This patch checks allows immediate then/else operands for cmovs.
We rely on,emit_conditional_move returning NULL if something unsupported
was generated.

Also, minor refactoring is performed.

--

gcc/ChangeLog:

2018-11-14  Robin Dapp  <rd...@linux.ibm.com>

        * ifcvt.c (have_const_cmov): New function.
        (noce_convert_multiple_sets): Allow constants if supported.
        (bb_ok_for_noce_convert_multiple_sets): Likewise.
        (check_cond_move_block): Refactor.
---
 gcc/ifcvt.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c
index 55205cac153..99716e5f63c 100644
--- a/gcc/ifcvt.c
+++ b/gcc/ifcvt.c
@@ -3214,7 +3214,9 @@ noce_convert_multiple_sets (struct noce_if_info *if_info)
         we'll end up trying to emit r4:HI = cond ? (r1:SI) : (r3:HI).
         Wrap the two cmove operands into subregs if appropriate to prevent
         that.  */
-      if (GET_MODE (new_val) != GET_MODE (temp))
+
+      if (!CONST_INT_P (new_val)
+         && GET_MODE (new_val) != GET_MODE (temp))
        {
          machine_mode src_mode = GET_MODE (new_val);
          machine_mode dst_mode = GET_MODE (temp);
@@ -3225,7 +3227,8 @@ noce_convert_multiple_sets (struct noce_if_info *if_info)
            }
          new_val = lowpart_subreg (dst_mode, new_val, src_mode);
        }
-      if (GET_MODE (old_val) != GET_MODE (temp))
+      if (!CONST_INT_P (old_val)
+         && GET_MODE (old_val) != GET_MODE (temp))
        {
          machine_mode src_mode = GET_MODE (old_val);
          machine_mode dst_mode = GET_MODE (temp);
@@ -3362,9 +3365,9 @@ bb_ok_for_noce_convert_multiple_sets (basic_block 
test_bb, unsigned *cost)
       if (!REG_P (dest))
        return false;
 
-      if (!(REG_P (src)
-          || (GET_CODE (src) == SUBREG && REG_P (SUBREG_REG (src))
-              && subreg_lowpart_p (src))))
+      if (!((REG_P (src) || (CONST_INT_P (src)))
+           || (GET_CODE (src) == SUBREG && REG_P (SUBREG_REG (src))
+             && subreg_lowpart_p (src))))
        return false;
 
       /* Destination must be appropriate for a conditional write.  */
@@ -3724,7 +3727,7 @@ check_cond_move_block (basic_block bb,
     {
       rtx set, dest, src;
 
-      if (!NONDEBUG_INSN_P (insn) || JUMP_P (insn))
+      if (!active_insn_p (insn))
        continue;
       set = single_set (insn);
       if (!set)
@@ -3740,10 +3743,8 @@ check_cond_move_block (basic_block bb,
       if (!CONSTANT_P (src) && !register_operand (src, VOIDmode))
        return FALSE;
 
-      if (side_effects_p (src) || side_effects_p (dest))
-       return FALSE;
-
-      if (may_trap_p (src) || may_trap_p (dest))
+      /* Check for side effects and trapping.  */
+      if (!noce_operand_ok (src) || !noce_operand_ok (dest))
        return FALSE;
 
       /* Don't try to handle this if the source register was
-- 
2.17.0

Reply via email to