[llvm] [RISCV] Improve instruction selection for most significant bit extraction (PR #151687)

Piotr Fusik via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 1 04:00:32 PDT 2025


================
@@ -1691,6 +1691,20 @@ multiclass SelectCC_GPR_riirr<DAGOperand valty, DAGOperand imm> {
                 valty:$truev, valty:$falsev), []>;
 }
 
+let Predicates = [IsRV32] in {
+def : Pat<(i32 (seteq (i32 (and GPR:$rs1, 0xffffffff80000000)), 0)),
+          (XORI (i32 (SRLI GPR:$rs1, 31)), 1)>;
+def : Pat<(i32 (setlt (i32 GPR:$rs1), 0)), (SRLI GPR:$rs1, 31)>; // compressible
+}
+let Predicates = [IsRV64] in {
+def : Pat<(i64 (seteq (i64 (and GPR:$rs1, 0x8000000000000000)), 0)),
----------------
pfusik wrote:

How to fix this warning?

    [80/82 -j1] Building CXX object lib/Target/RISCV/CMakeFiles/LLVMRISCVCodeGen.dir/GISel/RISCVInstructionSelector.cpp.o
    In file included from /home/p.fusik/upstream/llvm-project/llvm/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp:180:
    /home/p.fusik/upstream/llvm-project/build/lib/Target/RISCV/RISCVGenGlobalISel.inc:806998: warning: integer constant is so large that it is unsigned
    806998 |      /* 2243228 */   GIM_CheckConstantInt, /*MI*/1, /*Op*/2, GIMT_Encode8(-9223372036854775808),


https://github.com/llvm/llvm-project/pull/151687


More information about the llvm-commits mailing list