[llvm] [LSR] Reuse identical casts and instructions across fixups (PR #201839)
Timur Golubovich via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 5 07:03:30 PDT 2026
================
@@ -43,22 +43,14 @@ define void @sitofp_v8i8_to_v8f32(ptr %src, ptr %dst) {
; CHECK: // %bb.0: // %entry
; CHECK-NEXT: adrp x8, .LCPI0_0
; CHECK-NEXT: adrp x9, .LCPI0_1
-; CHECK-NEXT: ldr q0, [x8, :lo12:.LCPI0_0]
-; CHECK-NEXT: ldr q1, [x9, :lo12:.LCPI0_1]
-; CHECK-NEXT: mov x8, xzr
-; CHECK-NEXT: .LBB0_1: // %loop
-; CHECK-NEXT: // =>This Inner Loop Header: Depth=1
-; CHECK-NEXT: ldr d2, [x0, x8, lsl #3]
-; CHECK-NEXT: add x9, x1, x8, lsl #5
-; CHECK-NEXT: add x8, x8, #1
-; CHECK-NEXT: cmp x8, #1000
-; CHECK-NEXT: tbl v3.16b, { v2.16b }, v0.16b
-; CHECK-NEXT: tbl v2.16b, { v2.16b }, v1.16b
-; CHECK-NEXT: scvtf v3.4s, v3.4s, #24
-; CHECK-NEXT: scvtf v2.4s, v2.4s, #24
-; CHECK-NEXT: stp q2, q3, [x9]
-; CHECK-NEXT: b.eq .LBB0_1
-; CHECK-NEXT: // %bb.2: // %exit
+; CHECK-NEXT: ldr d0, [x0]
+; CHECK-NEXT: ldr q1, [x8, :lo12:.LCPI0_0]
+; CHECK-NEXT: ldr q2, [x9, :lo12:.LCPI0_1]
+; CHECK-NEXT: tbl v1.16b, { v0.16b }, v1.16b
+; CHECK-NEXT: tbl v0.16b, { v0.16b }, v2.16b
+; CHECK-NEXT: scvtf v1.4s, v1.4s, #24
+; CHECK-NEXT: scvtf v0.4s, v0.4s, #24
+; CHECK-NEXT: stp q0, q1, [x1]
----------------
timurgol007 wrote:
I think this transformation is correct. The loop condition appears to be inverted:
`br i1 %ec, label %loop, label %exit`
Since `%iv.next` is 1 on the first iteration, `%ec` is false and execution immediately branches to exit. As a result, the backedge is never taken and the loop effectively runs only once.
Given that, it's expected that LSR can eliminate the dead backedge and simplify the branch. It looks like the test itself may have the successors swapped and was probably intended to use:
`br i1 %ec, label %exit, label %loop`
The autogenerated CHECK lines are consistent with the current single-iteration behavior, so the test still passes, but it doesn't seem to be exercising a real loop.
https://github.com/llvm/llvm-project/pull/201839
More information about the llvm-commits
mailing list