The existing "case AND" in this function is not sufficient for optabs.c:avoid_expensive_constant usage, where the AND is passed in outer_code. We'd like to cost AND of rs6000_is_valid_and_mask or rs6000_is_valid_2insn_and variety there, so that those masks aren't seen as expensive (ie. better to load to a reg then AND).
* config/rs6000/rs6000.c (rs6000_rtx_costs): Combine CONST_INT AND handling with IOR/XOR. Move costing for AND with rs6000_is_valid_and_mask or rs6000_is_valid_2insn_and to CONST_INT. diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index 97180bb3819..e870ba0039a 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -21264,16 +21264,13 @@ rs6000_rtx_costs (rtx x, machine_mode mode, int outer_code, || outer_code == MINUS) && (satisfies_constraint_I (x) || satisfies_constraint_L (x))) - || (outer_code == AND - && (satisfies_constraint_K (x) - || (mode == SImode - ? satisfies_constraint_L (x) - : satisfies_constraint_J (x)))) - || ((outer_code == IOR || outer_code == XOR) + || ((outer_code == AND || outer_code == IOR || outer_code == XOR) && (satisfies_constraint_K (x) || (mode == SImode ? satisfies_constraint_L (x) : satisfies_constraint_J (x)))) + || (outer_code == AND + && rs6000_is_valid_and_mask (x, mode)) || outer_code == ASHIFT || outer_code == ASHIFTRT || outer_code == LSHIFTRT @@ -21310,7 +21307,9 @@ rs6000_rtx_costs (rtx x, machine_mode mode, int outer_code, || outer_code == IOR || outer_code == XOR) && (INTVAL (x) - & ~ (unsigned HOST_WIDE_INT) 0xffffffff) == 0)) + & ~ (unsigned HOST_WIDE_INT) 0xffffffff) == 0) + || (outer_code == AND + && rs6000_is_valid_2insn_and (x, mode))) { *total = COSTS_N_INSNS (1); return true; @@ -21448,26 +21447,6 @@ rs6000_rtx_costs (rtx x, machine_mode mode, int outer_code, *total += COSTS_N_INSNS (1); return true; } - - /* rotate-and-mask (no rotate), andi., andis.: 1 insn. */ - HOST_WIDE_INT val = INTVAL (XEXP (x, 1)); - if (rs6000_is_valid_and_mask (XEXP (x, 1), mode) - || (val & 0xffff) == val - || (val & 0xffff0000) == val - || ((val & 0xffff) == 0 && mode == SImode)) - { - *total = rtx_cost (left, mode, AND, 0, speed); - *total += COSTS_N_INSNS (1); - return true; - } - - /* 2 insns. */ - if (rs6000_is_valid_2insn_and (XEXP (x, 1), mode)) - { - *total = rtx_cost (left, mode, AND, 0, speed); - *total += COSTS_N_INSNS (2); - return true; - } } *total = COSTS_N_INSNS (1);