]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
RISC-V: Correct the mode that is causing the program to fail for XTheadCondMov
authorJin Ma <jinma@linux.alibaba.com>
Mon, 20 Jan 2025 16:29:30 +0000 (09:29 -0700)
committerJeff Law <jlaw@ventanamicro.com>
Mon, 20 Jan 2025 16:30:01 +0000 (09:30 -0700)
For XTheadCondMov, the bit width of rs2 should always be XLEN-sized, otherwise
the program logic will be wrong.

Reference form
https://github.com/XUANTIE-RV/thead-extension-spec/releases/download/2.3.0/xthead-2023-11-10-2.3.0.pdf

Synopsis
Move if equal zero.

Mnemonic
th.mveqz rd, rs1, rs2

Description
This instruction moves the content of register rs1 into rd if the content of rs2 is 0x0.
Otherwise, the value of rd does not change.

Operation
if (reg[rs2] == 0x0)
  reg[rd] := reg[rs1]

gcc/ChangeLog:

* config/riscv/thead.md (*th_cond_mov<GPR:mode><GPR2:mode>):
Change GPR2 to X.
(*th_cond_mov<GPR:mode>): Likewise.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/xtheadcondmov-bug.c: New test.

gcc/config/riscv/thead.md
gcc/testsuite/gcc.target/riscv/xtheadcondmov-bug.c [new file with mode: 0644]

index 54b9737b4308dea1f316000009cc829cf3521f68..d816f3b86ddecfe22a287923bb3ae5852946bf28 100644 (file)
 
 ;; XTheadCondMov
 
-(define_insn "*th_cond_mov<GPR:mode><GPR2:mode>"
+(define_insn "*th_cond_mov<GPR:mode>"
   [(set (match_operand:GPR 0 "register_operand" "=r,r")
        (if_then_else:GPR
         (match_operator 4 "equality_operator"
-               [(match_operand:GPR2 1 "register_operand" "r,r")
+               [(match_operand:X 1 "register_operand" "r,r")
                 (const_int 0)])
         (match_operand:GPR 2 "reg_or_0_operand" "rJ,0")
         (match_operand:GPR 3 "reg_or_0_operand" "0,rJ")))]
diff --git a/gcc/testsuite/gcc.target/riscv/xtheadcondmov-bug.c b/gcc/testsuite/gcc.target/riscv/xtheadcondmov-bug.c
new file mode 100644 (file)
index 0000000..01cec62
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-do compile  { target { rv64 } } } */
+/* { dg-options "-march=rv64gc_xtheadcondmov -mabi=lp64d -O2" } */
+
+long long int
+foo (long long int x, long long int y)
+{
+  if (((int) x | (int) y) != 0)
+    return 6;
+  return x + y;
+}
+
+/* { dg-final { scan-assembler-times {\msext\.w\M} 1 } } */