Skip to content

Commit eaccdba

Browse files
committed
combine: Fix ICE in try_combine on pr112494.c [PR112560]
The compiler, configured with --enable-checking=yes,rtl,extra ICEs with: internal compiler error: RTL check: expected elt 0 type 'e' or 'u', have 'E' (rtx unspec) in try_combine, at combine.cc:3237 This is 3236 /* Just replace the CC reg with a new mode. */ 3237 SUBST (XEXP (*cc_use_loc, 0), newpat_dest); 3238 undobuf.other_insn = cc_use_insn; in combine.cc, where *cc_use_loc is (unspec:DI [ (reg:CC 17 flags) ] UNSPEC_PUSHFL) combine assumes CC must be used inside of a comparison and uses XEXP (..., 0) without checking on the RTX type of the argument. Replace cc_use_loc with the entire new RTX only in case cc_use_loc satisfies COMPARISON_P predicate. Otherwise scan the entire cc_use_loc RTX for CC reg to be updated with a new mode. PR rtl-optimization/112560 gcc/ChangeLog: * combine.cc (try_combine): Replace cc_use_loc with the entire new RTX only in case cc_use_loc satisfies COMPARISON_P predicate. Otherwise scan the entire cc_use_loc RTX for CC reg to be updated with a new mode. * config/i386/i386.md (@pushf<mode>2): Allow all CC modes for operand 1.
1 parent df7625c commit eaccdba

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

gcc/combine.cc

+13-3
Original file line numberDiff line numberDiff line change
@@ -3222,8 +3222,7 @@ try_combine (rtx_insn *i3, rtx_insn *i2, rtx_insn *i1, rtx_insn *i0,
32223222
#endif
32233223
/* Cases for modifying the CC-using comparison. */
32243224
if (compare_code != orig_compare_code
3225-
/* ??? Do we need to verify the zero rtx? */
3226-
&& XEXP (*cc_use_loc, 1) == const0_rtx)
3225+
&& COMPARISON_P (*cc_use_loc))
32273226
{
32283227
/* Replace cc_use_loc with entire new RTX. */
32293228
SUBST (*cc_use_loc,
@@ -3233,8 +3232,19 @@ try_combine (rtx_insn *i3, rtx_insn *i2, rtx_insn *i1, rtx_insn *i0,
32333232
}
32343233
else if (compare_mode != orig_compare_mode)
32353234
{
3235+
subrtx_ptr_iterator::array_type array;
3236+
32363237
/* Just replace the CC reg with a new mode. */
3237-
SUBST (XEXP (*cc_use_loc, 0), newpat_dest);
3238+
FOR_EACH_SUBRTX_PTR (iter, array, cc_use_loc, NONCONST)
3239+
{
3240+
rtx *loc = *iter;
3241+
if (REG_P (*loc)
3242+
&& REGNO (*loc) == REGNO (newpat_dest))
3243+
{
3244+
SUBST (*loc, newpat_dest);
3245+
iter.skip_subrtxes ();
3246+
}
3247+
}
32383248
undobuf.other_insn = cc_use_insn;
32393249
}
32403250
}

gcc/config/i386/i386.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2219,9 +2219,9 @@
22192219

22202220
(define_insn "@pushfl<mode>2"
22212221
[(set (match_operand:W 0 "push_operand" "=<")
2222-
(unspec:W [(match_operand:CC 1 "flags_reg_operand")]
2222+
(unspec:W [(match_operand 1 "flags_reg_operand")]
22232223
UNSPEC_PUSHFL))]
2224-
""
2224+
"GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_CC"
22252225
"pushf{<imodesuffix>}"
22262226
[(set_attr "type" "push")
22272227
(set_attr "mode" "<MODE>")])

0 commit comments

Comments
 (0)