]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
RISC-V: Fix scalar code-gen of unsigned SAT_MUL
authorPan Li <pan2.li@intel.com>
Thu, 31 Jul 2025 04:32:24 +0000 (12:32 +0800)
committerPan Li <pan2.li@intel.com>
Tue, 5 Aug 2025 01:37:10 +0000 (09:37 +0800)
The previous code-gen of scalar unsigned SAT_MUL, aka usmul.
Leverage the mulhs by mistake, it should be mulhu for the
hight bit result of mul.  Thus, this patch would like to make
it correct.

gcc/ChangeLog:

* config/riscv/riscv.cc (riscv_expand_xmode_usmul): Take
umulhu for high bits mul result.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/sat/sat_u_mul-1-u32-from-u64.c: Add mulhu
asm check.
* gcc.target/riscv/sat/sat_u_mul-1-u64-from-u128.c: Ditto.

Signed-off-by: Pan Li <pan2.li@intel.com>
gcc/config/riscv/riscv.cc
gcc/testsuite/gcc.target/riscv/sat/sat_u_mul-1-u32-from-u64.c
gcc/testsuite/gcc.target/riscv/sat/sat_u_mul-1-u64-from-u128.c

index 0a9fcef370295c9586d282a4a884dfc57d3e13ff..e0d8904c1bf887ce0cafdeea91689d306b20b5fb 100644 (file)
@@ -13867,9 +13867,9 @@ riscv_expand_xmode_usmul (rtx dest, rtx x, rtx y)
   riscv_emit_binary (MULT, mul, x, y);
 
   if (TARGET_64BIT)
-    emit_insn (gen_usmuldi3_highpart (mulhu, x, y));
+    emit_insn (gen_umuldi3_highpart (mulhu, x, y));
   else
-    emit_insn (gen_usmulsi3_highpart (mulhu, x, y));
+    emit_insn (gen_umulsi3_highpart (mulhu, x, y));
 
   riscv_emit_binary (NE, overflow_p, mulhu, CONST0_RTX (Xmode));
   riscv_emit_unary (NEG, overflow_p, overflow_p);
index 8d5449bf3493a0432823145981461aaa9022a2e3..fa3758a2f547035c3bc3e59bf1d531eed3710706 100644 (file)
@@ -9,3 +9,5 @@
 DEF_SAT_U_MUL_FMT_1_WRAP(NT, WT)
 
 /* { dg-final { scan-tree-dump-times ".SAT_MUL" 1 "optimized" } } */
+/* { dg-final { scan-assembler-not "\.L\[0-9\]+" } } */
+/* { dg-final { scan-assembler-times "mulhu" 1 } } */
index d8a01d1a06facf9ec50022aa7a9c27891b55648c..b1bf4fae968be697d5d6b1e12c5c542a15b71914 100644 (file)
@@ -10,3 +10,4 @@ DEF_SAT_U_MUL_FMT_1_WRAP(NT, WT)
 
 /* { dg-final { scan-tree-dump-times ".SAT_MUL" 1 "optimized" } } */
 /* { dg-final { scan-assembler-not "\.L\[0-9\]+" } } */
+/* { dg-final { scan-assembler-times "mulhu" 1 } } */