From: Richard Earnshaw Date: Tue, 14 Apr 2026 13:45:38 +0000 (+0100) Subject: arm: apply stronger checks on conditional-compare patterns [PR123102] X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=HEAD;p=thirdparty%2Fgcc.git arm: apply stronger checks on conditional-compare patterns [PR123102] If a conditional compare operation is generated during expand, then combine may try to substitute into it in order to generate better code; but if it does so, we need to validate that the optimized sequence is still a valid conditional compare. We were skipping those checks and that can lead to wrong code being generated. gcc/ChangeLog: PR target/123102 * config/arm/arm.md (*cmp_ite0): Apply stricter checks on the comparison mode. (*cmp_ite1, *cmp_and, *cmp_ior): Likewise. --- diff --git a/gcc/config/arm/arm.md b/gcc/config/arm/arm.md index d9ce482838b..2a72dde3647 100644 --- a/gcc/config/arm/arm.md +++ b/gcc/config/arm/arm.md @@ -10133,6 +10133,7 @@ (set_attr "type" "multiple")] ) +;; (pred4 && pred5) != 0 (define_insn "*cmp_ite0" [(set (match_operand 6 "dominant_cc_register" "") (compare @@ -10149,7 +10150,11 @@ "lPy,rI,L,lPy,lPy,rI,rI,L,L")]) (const_int 0)) (const_int 0)))] - "TARGET_32BIT" + "TARGET_32BIT + && GET_MODE (operands[6]) != CCmode + && (GET_MODE (operands[6]) + == arm_select_dominance_cc_mode (operands[4], operands[5], + DOM_CC_X_AND_Y))" "* { static const char * const cmp1[NUM_OF_COND_CMP][2] = @@ -10216,6 +10221,7 @@ (const_int 10))])] ) +;; (!pred4 || pred5) != 0 (define_insn "*cmp_ite1" [(set (match_operand 6 "dominant_cc_register" "") (compare @@ -10232,7 +10238,11 @@ "lPy,rI,L,lPy,lPy,rI,rI,L,L")]) (const_int 1)) (const_int 0)))] - "TARGET_32BIT" + "TARGET_32BIT + && GET_MODE (operands[6]) != CCmode + && (GET_MODE (operands[6]) + == arm_select_dominance_cc_mode (operands[4], operands[5], + DOM_CC_NX_OR_Y))" "* { static const char * const cmp1[NUM_OF_COND_CMP][2] = @@ -10315,7 +10325,11 @@ (match_operand:SI 3 "arm_add_operand" "lPy,rI,L,lPy,lPy,r,rI,rI,L,L")])) (const_int 0)))] - "TARGET_32BIT" + "TARGET_32BIT + && GET_MODE (operands[6]) != CCmode + && (GET_MODE (operands[6]) + == arm_select_dominance_cc_mode (operands[4], operands[5], + DOM_CC_X_AND_Y))" "* { static const char *const cmp1[NUM_OF_COND_CMP][2] = @@ -10400,7 +10414,11 @@ (match_operand:SI 3 "arm_add_operand" "lPy,rI,L,lPy,lPy,r,rI,rI,L,L")])) (const_int 0)))] - "TARGET_32BIT" + "TARGET_32BIT + && GET_MODE (operands[6]) != CCmode + && (GET_MODE (operands[6]) + == arm_select_dominance_cc_mode (operands[4], operands[5], + DOM_CC_X_OR_Y))" "* { static const char *const cmp1[NUM_OF_COND_CMP][2] =