[llvm] [SLP] Fix incorrect operand order in interchangeable instruction. (PR #139225)

Han-Kuan Chen via llvm-commits llvm-commits at lists.llvm.org
Fri May 9 01:51:46 PDT 2025


================
@@ -4,19 +4,40 @@
 define void @test() {
 ; CHECK-LABEL: @test(
 ; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i8, ptr undef, i64 4
-; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr inbounds [4 x [4 x i32]], ptr undef, i64 0, i64 1, i64 0
-; CHECK-NEXT:    [[TMP3:%.*]] = load <4 x i8>, ptr [[TMP1]], align 1
-; CHECK-NEXT:    [[TMP4:%.*]] = zext <4 x i8> [[TMP3]] to <4 x i16>
-; CHECK-NEXT:    [[TMP5:%.*]] = sub <4 x i16> zeroinitializer, [[TMP4]]
-; CHECK-NEXT:    [[TMP6:%.*]] = shl <4 x i16> [[TMP5]], zeroinitializer
-; CHECK-NEXT:    [[TMP7:%.*]] = add <4 x i16> [[TMP6]], zeroinitializer
-; CHECK-NEXT:    [[TMP8:%.*]] = shufflevector <4 x i16> [[TMP7]], <4 x i16> poison, <4 x i32> <i32 1, i32 0, i32 3, i32 2>
-; CHECK-NEXT:    [[TMP9:%.*]] = add <4 x i16> [[TMP8]], [[TMP7]]
-; CHECK-NEXT:    [[TMP10:%.*]] = sub <4 x i16> [[TMP8]], [[TMP7]]
-; CHECK-NEXT:    [[TMP11:%.*]] = shufflevector <4 x i16> [[TMP9]], <4 x i16> [[TMP10]], <4 x i32> <i32 0, i32 5, i32 2, i32 7>
-; CHECK-NEXT:    [[TMP13:%.*]] = sub <4 x i16> zeroinitializer, [[TMP11]]
----------------
HanKuanChen wrote:

I think the old result is incorrect. SLP tries to vectorize the following instructions.
```
%29 = add nsw i32 0, %25
%31 = sub nsw i32 0, %27
%33 = add nsw i32 0, %26
%35 = sub nsw i32 0, %28
```
but the vectorized result is `sub <4 x i16> zeroinitializer, [[TMP11]]`.
`%29 = add nsw i32 0, %25` should be `%29 = sub nsw i32 %25, 0` instead of `%29 = sub nsw i32 0, %25`.

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


More information about the llvm-commits mailing list