OSDN Git Service

[Scalarizer] When gathering scattered scalar, don't replace it with itself
authorRoman Lebedev <lebedev.ri@gmail.com>
Tue, 7 Jul 2020 13:53:19 +0000 (16:53 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Tue, 7 Jul 2020 14:03:53 +0000 (17:03 +0300)
The (previously-crashing) test-case would cause us to seemingly-harmlessly
replace some use with something else, but we can't replace it with itself,
so we would crash.

llvm/lib/Transforms/Scalar/Scalarizer.cpp
llvm/test/Transforms/Scalarizer/crash-bug.ll

index e8fea50..3d650c6 100644 (file)
@@ -944,6 +944,8 @@ bool ScalarizerVisitor::finish() {
       } else {
         assert(CV.size() == 1 && Op->getType() == CV[0]->getType());
         Res = CV[0];
+        if (Op == Res)
+          continue;
       }
       Res->takeName(Op);
       Op->replaceAllUsesWith(Res);
index d581707..9775636 100644 (file)
@@ -22,3 +22,32 @@ bb3:
   ret void
 }
 
+; See https://reviews.llvm.org/D83101#2135945
+define void @f1_crash(<2 x i16> %base, i1 %c, <2 x i16>* %ptr) {
+; CHECK-LABEL: @f1_crash(
+; CHECK: vector.ph:
+; CHECK:   %base.i0 = extractelement <2 x i16> %base, i32 0
+; CHECK:   %base.i1 = extractelement <2 x i16> %base, i32 1
+; CHECK:   br label %vector.body115
+; CHECK: vector.body115:                                   ; preds = %vector.body115, %vector.ph
+; CHECK:   %vector.recur.i0 = phi i16 [ %base.i0, %vector.ph ], [ %wide.load125.i0, %vector.body115 ]
+; CHECK:   %vector.recur.i1 = phi i16 [ %base.i1, %vector.ph ], [ %wide.load125.i1, %vector.body115 ]
+; CHECK:   %wide.load125 = load <2 x i16>, <2 x i16>* %ptr, align 1
+; CHECK:   %wide.load125.i0 = extractelement <2 x i16> %wide.load125, i32 0
+; CHECK:   %wide.load125.i1 = extractelement <2 x i16> %wide.load125, i32 1
+; CHECK:   br i1 %c, label %middle.block113, label %vector.body115
+; CHECK: middle.block113:                                  ; preds = %vector.body115
+; CHECK:   ret void
+; CHECK: }
+
+vector.ph:
+  br label %vector.body115
+
+vector.body115:
+  %vector.recur = phi <2 x i16> [ %base, %vector.ph ], [ %wide.load125, %vector.body115 ]
+  %wide.load125 = load <2 x i16>, <2 x i16>* %ptr, align 1
+  br i1 %c, label %middle.block113, label %vector.body115
+
+middle.block113:
+  ret void
+}