[PATCH, RTL opt]: Ensure that equivalent_reg_at_start rejects registers with mismatched mode
Uros Bizjak
ubizjak@gmail.com
Sat May 13 21:44:00 GMT 2017
Hello!
-mtune=intel is able to copy SFmode value through general registers,
resulting in the following sequence:
(insn 288 1008 1009 29 (parallel [
(set (reg:DI 4 si [687])
(lshiftrt:DI (reg:DI 4 si [687])
(const_int 32 [0x20])))
(clobber (reg:CC 17 flags))
]) "ttt.c":41 546 {*lshrdi3_1}
(nil))
(insn 1009 288 289 29 (set (reg:DI 2 cx [419])
(reg:DI 4 si [687])) "ttt.c":41 81 {*movdi_internal}
(nil))
(insn 289 1009 291 29 (set (reg:SF 21 xmm0 [425])
(reg:SF 2 cx [419])) "ttt.c":41 127 {*movsf_internal}
(nil))
(insn 291 289 292 29 (set (reg:CCFPU 17 flags)
(compare:CCFPU (reg:SF 21 xmm0 [425])
(reg:SF 27 xmm6 [688]))) "ttt.c":41 51 {*cmpiusf}
(expr_list:REG_EQUAL (compare:CCFPU (reg:SF 21 xmm0 [425])
(const_double:SF 0.0 [0x0.0p+0]))
(nil)))
Looking at compare-elim.c, equivalent_reg_at_start, the function
traces the value in %xmm0 to %rsi. So, try_eliminate_compare tries to
check if the target supports the compare of
(lshiftrt:DI (reg:DI 4 si [687])
(const_int 32 [0x20])))
with
(reg:SF 27 xmm6 [688])
which won't fly, since compare operands must have the same modes.
Attached patch ensures that the mode of register copy, found by
equivalent_reg_at_start equals original mode.
2017-05-13 Uros Bizjak <ubizjak@gmail.com>
* compare-elim.c (equivalent_reg_at_start): Return NULL_RTX
when returned register mode doesn't match original mode.
Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}.
Committed to mainline SVN as obvious.
Uros.
-------------- next part --------------
Index: compare-elim.c
===================================================================
--- compare-elim.c (revision 248008)
+++ compare-elim.c (working copy)
@@ -526,6 +526,7 @@ maybe_select_cc_mode (struct comparison *cmp, rtx
static rtx
equivalent_reg_at_start (rtx reg, rtx_insn *end, rtx_insn *start)
{
+ machine_mode orig_mode = GET_MODE (reg);
rtx_insn *bb_head = BB_HEAD (BLOCK_FOR_INSN (end));
for (rtx_insn *insn = PREV_INSN (end);
@@ -572,6 +573,9 @@ equivalent_reg_at_start (rtx reg, rtx_insn *end, r
return NULL_RTX;
}
+ if (GET_MODE (reg) != orig_mode)
+ return NULL_RTX;
+
return reg;
}
More information about the Gcc-patches
mailing list