/* snip */ > > diff --git a/gcc/testsuite/gcc.target/loongarch/add-const.c b/gcc/testsuite/gcc.target/loongarch/add-const.c > new file mode 100644 > index 00000000000..3a9f72fe83d > --- /dev/null > +++ b/gcc/testsuite/gcc.target/loongarch/add-const.c > @@ -0,0 +1,47 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O -mabi=lp64d" } */ > + > +/* None of these functions should load the const operand into a temp > + register. */ > + > +/* { dg-final { scan-assembler-not "add\\.[dw]" } } */ > + > +unsigned long f01 (unsigned long x) { return x + 1; } > +unsigned long f02 (unsigned long x) { return x - 1; } > +unsigned long f03 (unsigned long x) { return x + 2047; } > +unsigned long f04 (unsigned long x) { return x + 4094; } > +unsigned long f05 (unsigned long x) { return x - 2048; } > +unsigned long f06 (unsigned long x) { return x - 4096; } > +unsigned long f07 (unsigned long x) { return x + 0x7fff0000; } > +unsigned long f08 (unsigned long x) { return x - 0x80000000l; } > +unsigned long f09 (unsigned long x) { return x + 0x7fff0000l * 2; } > +unsigned long f10 (unsigned long x) { return x - 0x80000000l * 2; } > +unsigned long f11 (unsigned long x) { return x - 0x80000000l * 2; } These two test cases are duplicates. > +unsigned long f12 (unsigned long x) { return x + 0x7fff0000 + 0x1; } > +unsigned long f13 (unsigned long x) { return x + 0x7fff0000 - 0x1; } > +unsigned long f14 (unsigned long x) { return x + 0x7fff0000 + 0x7ff; } > +unsigned long f15 (unsigned long x) { return x + 0x7fff0000 - 0x800; } > +unsigned long f16 (unsigned long x) { return x - 0x80000000l - 1; } > +unsigned long f17 (unsigned long x) { return x - 0x80000000l + 1; } > +unsigned long f18 (unsigned long x) { return x - 0x80000000l - 0x800; } > +unsigned long f19 (unsigned long x) { return x - 0x80000000l + 0x7ff; } > + > +unsigned int g01 (unsigned int x) { return x + 1; } > +unsigned int g02 (unsigned int x) { return x - 1; } > +unsigned int g03 (unsigned int x) { return x + 2047; } > +unsigned int g04 (unsigned int x) { return x + 4094; } > +unsigned int g05 (unsigned int x) { return x - 2048; } > +unsigned int g06 (unsigned int x) { return x - 4096; } > +unsigned int g07 (unsigned int x) { return x + 0x7fff0000; } > +unsigned int g08 (unsigned int x) { return x - 0x80000000l; } > +unsigned int g09 (unsigned int x) { return x + 0x7fff0000l * 2; } > +unsigned int g10 (unsigned int x) { return x - 0x80000000l * 2; } > +unsigned int g11 (unsigned int x) { return x - 0x80000000l * 2; } Ditto. I found that adding this log test case gcc.target/loongarch/stack-check-cfa-1.c and gcc.target/loongarch/stack-check-cfa-2.c test failed. Although the test fails, the generated assembly code is better, and there is no problem with the logic of the assembly code. I haven't checked the reason for this yet. Otherwise LGTM, thanks!