[PATCH] D126939: [SLP] Avoid converting undef to poison when gathering.

Vasileios Porpodas via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 2 19:48:25 PDT 2022


vporpo created this revision.
vporpo added reviewers: ABataev, RKSimon, hvdijk, nikic, nlopes, MaskRay.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
vporpo requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The reduced test case is in phi-undef-input.ll

We expect SLP to generate code like this:

  entry:
    br i1 %cond, label %bb2, label %bb3
  bb2:
    br label %bb3
  bb3:
    %phi = phi <2 x i8> [ %arg0, %bb2 ], [ <i8 0, i8 undef> %entry ]
    %zext = zext <2 x i8> %phi to <2 x i32>

If we get to bb3 through the entry block, then %zext lane 1 should have its high-order bits 0.

But instead it generates a poison in phi's input coming from %entry:

  entry:
    br i1 %cond, label %bb2, label %bb3
  bb2:
    br label %bb3
  bb3:
    %phi = phi <2 x i8> [ %arg0, %bb2 ], [ <i8 0, i8 poison> %entry ]
    %zext = zext <2 x i8> %phi to <2 x i32>

This time if we get to bb3 through the entry block, then %zext lane 1 is poison, so no guarantees about the high-order bits.

Please also check: https://alive2.llvm.org/ce/z/aMa3qD


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126939

Files:
  llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
  llvm/test/Transforms/SLPVectorizer/X86/phi-undef-input.ll


Index: llvm/test/Transforms/SLPVectorizer/X86/phi-undef-input.ll
===================================================================
--- llvm/test/Transforms/SLPVectorizer/X86/phi-undef-input.ll
+++ llvm/test/Transforms/SLPVectorizer/X86/phi-undef-input.ll
@@ -14,7 +14,7 @@
 ; CHECK-NEXT:    [[TMP3:%.*]] = insertelement <4 x i8> [[TMP2]], i8 [[ARG3:%.*]], i32 3
 ; CHECK-NEXT:    br label [[BB3]]
 ; CHECK:       bb3:
-; CHECK-NEXT:    [[TMP4:%.*]] = phi <4 x i8> [ [[TMP3]], [[BB2]] ], [ <i8 0, i8 poison, i8 poison, i8 poison>, [[ENTRY:%.*]] ]
+; CHECK-NEXT:    [[TMP4:%.*]] = phi <4 x i8> [ [[TMP3]], [[BB2]] ], [ <i8 0, i8 undef, i8 undef, i8 undef>, [[ENTRY:%.*]] ]
 ; CHECK-NEXT:    [[TMP5:%.*]] = zext <4 x i8> [[TMP4]] to <4 x i32>
 ; CHECK-NEXT:    [[TMP6:%.*]] = call i32 @llvm.vector.reduce.or.v4i32(<4 x i32> [[TMP5]])
 ; CHECK-NEXT:    ret i32 [[TMP6]]
Index: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -7556,6 +7556,8 @@
       if (UniqueValues.empty()) {
         assert(all_of(VL, UndefValue::classof) && "Expected list of undefs.");
         NumValues = VF;
+      } else if (UniqueValues.size() == 1 && NumValues == 1) {
+        NumValues = VF;
       }
       ReuseShuffleIndicies.clear();
       UniqueValues.clear();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126939.433939.patch
Type: text/x-patch
Size: 1421 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220603/c542f116/attachment.bin>


More information about the llvm-commits mailing list