Skip to content

Commit 1d2aa9a

Browse files
committed
[LRA]: Exclude some hard regs for multi-reg inout reload pseudos used in asm in different mode
See gcc.c-torture/execute/20030222-1.c. Consider the code for 32-bit (e.g. BE) target: int i, v; long x; x = v; asm ("" : "=r" (i) : "0" (x)); We generate the following RTL with reload insns: 1. subreg:si(x:di, 0) = 0; 2. subreg:si(x:di, 4) = v:si; 3. t:di = x:di, dead x; 4. asm ("" : "=r" (subreg:si(t:di,4)) : "0" (t:di)) 5. i:si = subreg:si(t:di,4); If we assign hard reg of x to t, dead code elimination will remove insn #2 and we will use unitialized hard reg. So exclude the hard reg of x for t. We could ignore this problem for non-empty asm using all x value but it is hard to check that the asm are expanded into insn realy using x and setting r. The old reload pass used the same approach. gcc/ChangeLog * lra-constraints.cc (match_reload): Exclude some hard regs for multi-reg inout reload pseudos used in asm in different mode.
1 parent cae48a9 commit 1d2aa9a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

gcc/lra-constraints.cc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,34 @@ match_reload (signed char out, signed char *ins, signed char *outs,
10221022
are ordered. */
10231023
if (partial_subreg_p (outmode, inmode))
10241024
{
1025+
bool asm_p = asm_noperands (PATTERN (curr_insn)) >= 0;
1026+
int hr;
1027+
HARD_REG_SET temp_hard_reg_set;
1028+
1029+
if (asm_p && (hr = get_hard_regno (out_rtx)) >= 0
1030+
&& hard_regno_nregs (hr, inmode) > 1)
1031+
{
1032+
/* See gcc.c-torture/execute/20030222-1.c.
1033+
Consider the code for 32-bit (e.g. BE) target:
1034+
int i, v; long x; x = v; asm ("" : "=r" (i) : "0" (x));
1035+
We generate the following RTL with reload insns:
1036+
1. subreg:si(x:di, 0) = 0;
1037+
2. subreg:si(x:di, 4) = v:si;
1038+
3. t:di = x:di, dead x;
1039+
4. asm ("" : "=r" (subreg:si(t:di,4)) : "0" (t:di))
1040+
5. i:si = subreg:si(t:di,4);
1041+
If we assign hard reg of x to t, dead code elimination
1042+
will remove insn #2 and we will use unitialized hard reg.
1043+
So exclude the hard reg of x for t. We could ignore this
1044+
problem for non-empty asm using all x value but it is hard to
1045+
check that the asm are expanded into insn realy using x
1046+
and setting r. */
1047+
CLEAR_HARD_REG_SET (temp_hard_reg_set);
1048+
if (exclude_start_hard_regs != NULL)
1049+
temp_hard_reg_set = *exclude_start_hard_regs;
1050+
SET_HARD_REG_BIT (temp_hard_reg_set, hr);
1051+
exclude_start_hard_regs = &temp_hard_reg_set;
1052+
}
10251053
reg = new_in_reg
10261054
= lra_create_new_reg_with_unique_value (inmode, in_rtx, goal_class,
10271055
exclude_start_hard_regs,

0 commit comments

Comments
 (0)