]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[RISC-V][PR target/117690] Add missing shift in constant synthesis
authorJeff Law <jlaw@ventanamicro.com>
Thu, 21 Nov 2024 23:21:07 +0000 (16:21 -0700)
committerJeff Law <jlaw@ventanamicro.com>
Thu, 21 Nov 2024 23:21:07 +0000 (16:21 -0700)
As hinted out in the BZ, we were missing a left shift in the constant synthesis
in the case where the upper 32 bits can be synthesized using a shNadd of the
low 32 bits.

This adjusts the synthesis to add the missing left shift and adjusts the cost
to account for the additional instruction.

Regression tested on riscv64-elf in my tester.  Waiting for the pre-commit
tester before moving forward.

PR target/117690
gcc/
* config/riscv/riscv.cc (riscv_build_integer): Add missing left
shift when using shNadd to derive upper 32 bits from lower 32 bits.

gcc/testsuite
* gcc.target/riscv/pr117690.c: New test.
* gcc.target/riscv/synthesis-13.c: Adjust expected output.

gcc/config/riscv/riscv.cc
gcc/testsuite/gcc.target/riscv/pr117690.c [new file with mode: 0644]
gcc/testsuite/gcc.target/riscv/synthesis-13.c

index b423344d4d6bf3b6f1cb6f24cd8f9a040e2becbe..93702f71ec9f70ff614d0e0769a7730dd77e0f56 100644 (file)
@@ -1328,16 +1328,20 @@ riscv_build_integer (struct riscv_integer_op *codes, HOST_WIDE_INT value,
            value = 9;
 
          if (value)
-           alt_cost = 2 + riscv_build_integer_1 (alt_codes,
+           alt_cost = 3 + riscv_build_integer_1 (alt_codes,
                                                  sext_hwi (loval, 32), mode);
 
          /* For constants where the upper half is a shNadd of the lower half
             we can do a similar transformation.  */
          if (value && alt_cost < cost)
            {
-             alt_codes[alt_cost - 3].save_temporary = true;
-             alt_codes[alt_cost - 2].code = FMA;
-             alt_codes[alt_cost - 2].value = value;
+             alt_codes[alt_cost - 4].save_temporary = true;
+             alt_codes[alt_cost - 3].code = FMA;
+             alt_codes[alt_cost - 3].value = value;
+             alt_codes[alt_cost - 3].use_uw = false;
+             alt_codes[alt_cost - 3].save_temporary = false;
+             alt_codes[alt_cost - 2].code = ASHIFT;
+             alt_codes[alt_cost - 2].value = 32;
              alt_codes[alt_cost - 2].use_uw = false;
              alt_codes[alt_cost - 2].save_temporary = false;
              alt_codes[alt_cost - 1].code = CONCAT;
diff --git a/gcc/testsuite/gcc.target/riscv/pr117690.c b/gcc/testsuite/gcc.target/riscv/pr117690.c
new file mode 100644 (file)
index 0000000..9c06ab4
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do run { target { riscv64*-*-* } } } */
+/* { dg-options "-march=rv64gc_zba_zbb -mabi=lp64d" } */
+
+#define myconst 0x4fffaffb0fffefffUL;
+volatile unsigned long a = myconst;
+unsigned long foo()
+{
+  return myconst;
+}
+
+int main()
+{
+  if (foo() != a)
+    __builtin_abort();
+  __builtin_exit (0);
+}
index 957410acda148ef46ad082d08280cddd4cafb4ac..80412f29f89d27a07999233a36972e1b21f269fd 100644 (file)
@@ -12,7 +12,7 @@
    total number of instructions.
 
    This isn't expected to change much and any change is worthy of a look.  */
-/* { dg-final { scan-assembler-times "\\t(add|addi|bseti|li|pack|ret|sh1add|sh2add|sh3add|slli|srli|xori|or)" 45 } } */
+/* { dg-final { scan-assembler-times "\\t(add|addi|bseti|li|pack|ret|sh1add|sh2add|sh3add|slli|srli|xori|or)" 54 } } */
 
 
 unsigned long foo_0x7907d89a2857f2de(void) { return 0x7907d89a2857f2deUL; }