https://gcc.gnu.org/g:535e0759e5b7153470d4d2bf91c8d1a04747948f
commit r17-6380-g535e0759e5b7153470d4d2bf91c8d1a04747948f Author: liuhongt <[email protected]> Date: Mon Nov 16 21:51:26 2026 -0800 x86_cse: Drop REG_EQUAL/REG_EQUIV notes on constant integer loads [PR128690] When replace_vector_const converts a CONST_VECTOR load no larger than an integer register into a constant integer load, it rewrites the destination with gen_lowpart. For (set (subreg:V2QI (reg:HI 126) 0) (plus:V2QI ...)) with a REG_EQUAL (const_vector:V2QI [5 5]) note, the result is (set (reg:HI 126) (const_int 1285)) with the V2QImode REG_EQUAL note left in place. Since the destination is now a bare REG, IRA records the note as an equivalence of the HImode pseudo. The CONST_VECTOR isn't a legitimate HImode constant, so IRA calls force_const_mem (HImode, const_vector:V2QI), which creates a constant pool entry whose mode doesn't match its constant. When LRA spills the pseudo and uses that equivalence, optimize_constant_pool hits the mode check in native_encode_rtx. The SET_SRC is now the constant itself, so the note is redundant. Remove REG_EQUAL and REG_EQUIV notes when the source is replaced with a CONST_INT. IRA still records the equivalence from the CONST_INT source. gcc/ChangeLog: PR target/128690 * config/i386/i386-features.cc (replace_vector_const): Remove REG_EQUAL and REG_EQUIV notes when replacing the source with a CONST_INT. gcc/testsuite/ChangeLog: PR target/128690 * gcc.target/i386/pr128690.c: New test. Diff: --- gcc/config/i386/i386-features.cc | 3 ++ gcc/testsuite/gcc.target/i386/pr128690.c | 50 ++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/gcc/config/i386/i386-features.cc b/gcc/config/i386/i386-features.cc index ee5ad0768573..4f31ea684b14 100644 --- a/gcc/config/i386/i386-features.cc +++ b/gcc/config/i386/i386-features.cc @@ -3956,6 +3956,9 @@ replace_vector_const (machine_mode vector_mode, rtx vector_const, { dest = gen_lowpart (scalar_mode, dest); SET_DEST (set) = dest; + /* SET_SRC is now the constant itself, so any REG_EQUAL or + REG_EQUIV note is redundant (PR target/128690). */ + remove_reg_equal_equiv_notes (insn, true); } /* Drop possible dead definitions. */ PATTERN (insn) = set; diff --git a/gcc/testsuite/gcc.target/i386/pr128690.c b/gcc/testsuite/gcc.target/i386/pr128690.c new file mode 100644 index 000000000000..499d463495ae --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr128690.c @@ -0,0 +1,50 @@ +/* PR target/128690 */ +/* { dg-do compile } */ +/* { dg-options "-O3 -msse2 -fno-vect-cost-model" } */ + +extern void g (int); +extern int h (); +char a, b; +int d, e; + +void +f () +{ + for (int c = 0; c < 8; ++c) + a = 1; +} + +void +i (int j) +{ + char k[8], l[8]; + k[0] = k[1] = k[2] = k[3] = k[4] = k[5] = k[6] = k[7] = 6; + int *m = 0; + char *n = 0; + if (!d) + { + *m = 0; + n = &b; + goto p; + } + do + { + if (e) + goto r; + p: + *n = 0; + for (int s = 0; s < 8; ++s) + l[s] = k[s]; + } + while (b); + l[6] = k[6] - 1; + l[7] = k[7] - 1; + if (j - h ()) + r: + f (); + k[6] = l[6]; + k[7] = 7 + l[7]; + g (k[6]); + g (k[7]); + g (l[7]); +}
