[PATCH] middle-end/94614 - avoid multiword moves to nothing

Richard Biener rguenther@suse.de
Thu Apr 16 08:05:32 GMT 2020


This adjusts emit_move_multi_word to handle moves into paradoxical
subregs parts that are not there and resolve_clobber to handle
such subregs.

Bootstrap & regtest running on x86_64-unknown-linux-gnu.

The testcase involves writing to a register out of bounds so I'm not
sure this is the correct place to paper over this or whether RTL
expansion should have done things differently.

;; MEM[(v4si *)&res] = v_2(D);

(insn 12 9 10 (clobber (subreg:TI (reg/v:DI 113 [ res ]) 0)) 
"pr94574.c":13:18 -1
     (nil))

(insn 10 12 11 (set (subreg:SI (reg/v:DI 113 [ res ]) 0)
        (subreg:SI (reg/v:TI 115 [ v ]) 0)) "pr94574.c":13:18 -1
     (nil))

(insn 11 10 0 (set (subreg:SI (reg/v:DI 113 [ res ]) 4)
        (subreg:SI (reg/v:TI 115 [ v ]) 4)) "pr94574.c":13:18 -1
     (nil))

maybe we should simply force regs with out-of-bound accesses to
memory?  The above is the RTL generated after the first half of the
fix.  We still generate

(insn 12 7 10 2 (clobber (subreg:TI (reg/v:DI 113 [ res ]) 0)) 
"pr94574.c":13:18 -1  
     (nil))

which lower-subreg runs into - I did not track down where that
is generated, but I understand the subreg is pointless here?

Comments?  OK?

Richard.

2020-04-16  Richard Biener  <rguenther@suse.de>

	PR middle-end/94614
	* expr.c (emit_move_multi_word): Do not generate code when
	the destination part is undefined_operand_subword_p.
	* lower-subreg.c (resolve_clobber): Look through a paradoxica
	subreg.
---
 gcc/expr.c         | 5 +++++
 gcc/lower-subreg.c | 4 ++++
 2 files changed, 9 insertions(+)

diff --git a/gcc/expr.c b/gcc/expr.c
index b97c217e86d..dfbeae71518 100644
--- a/gcc/expr.c
+++ b/gcc/expr.c
@@ -3692,6 +3692,11 @@ emit_move_multi_word (machine_mode mode, rtx x, rtx y)
   need_clobber = false;
   for (i = 0; i < CEIL (mode_size, UNITS_PER_WORD); i++)
     {
+      /* Do not generate code for a move if it would go entirely
+	 to the non-existing bits of a paradoxical subreg.  */
+      if (undefined_operand_subword_p (x, i))
+	continue;
+
       rtx xpart = operand_subword (x, i, 1, mode);
       rtx ypart;
 
diff --git a/gcc/lower-subreg.c b/gcc/lower-subreg.c
index a170f0ff93b..a11e535b5bf 100644
--- a/gcc/lower-subreg.c
+++ b/gcc/lower-subreg.c
@@ -1150,6 +1150,10 @@ resolve_clobber (rtx pat, rtx_insn *insn)
   int ret;
 
   reg = XEXP (pat, 0);
+  /* For clobbers we can look through paradoxical subregs which
+     we do not handle in simplify_gen_subreg_concatn.  */
+  if (paradoxical_subreg_p (reg))
+    reg = SUBREG_REG (reg);
   if (!resolve_reg_p (reg) && !resolve_subreg_p (reg))
     return false;
 
-- 
2.16.4


More information about the Gcc-patches mailing list