[llvm] [GISel] Funnel shift combiner port from SelectionDAG ISel to GlobalISel (PR #135132)

Axel Sorenson via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 16 11:39:08 PDT 2025


================
@@ -105,3 +105,55 @@ define i16 @test_shl_i48_2(i48 %x, i48 %y) {
   %trunc = trunc i48 %shl to i16
   ret i16 %trunc
 }
+
+define i16 @test_fshl_i32(i32 %x, i32 %_, i32 %y) {
+; RV32-LABEL: test_fshl_i32:
+; RV32:       # %bb.0:
+; RV32-NEXT:    not a3, a2
+; RV32-NEXT:    sll a0, a0, a2
+; RV32-NEXT:    srli a1, a1, 1
+; RV32-NEXT:    srl a1, a1, a3
+; RV32-NEXT:    or a0, a0, a1
+; RV32-NEXT:    ret
+;
+; RV64-LABEL: test_fshl_i32:
+; RV64:       # %bb.0:
+; RV64-NEXT:    not a3, a2
+; RV64-NEXT:    sllw a0, a0, a2
+; RV64-NEXT:    srliw a1, a1, 1
+; RV64-NEXT:    srlw a1, a1, a3
+; RV64-NEXT:    or a0, a0, a1
+; RV64-NEXT:    ret
+  %fshl = call i32 @llvm.fshl.i32(i32 %x, i32 %_, i32 %y)
+  %shl = shl i32 %x, %y
+  %or = or i32 %fshl, %shl
+  %and = and i32 %or, %fshl
+  %trunc = trunc i32 %and to i16
----------------
axelcool1234 wrote:

If I recall correctly, I wrote the `%and` instruction because the transformation would make it `and` the same instruction to itself, making it redundant, thus the correct output would not have the `and` instruction outputted. If you want, I can copy these tests and remove that bit so it's _just_ the instructions that should be transformed.

The `trunc` instruction follows the same pattern as the other tests in the same file, and isn't really related. I can remove this too.

Should I go ahead and do these two things?

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


More information about the llvm-commits mailing list