[llvm] r232510 - [SwitchLowering] Remove incoming values in the reverse order
Michael Liao
michael.liao at intel.com
Tue Mar 17 11:03:10 PDT 2015
Author: hliao
Date: Tue Mar 17 13:03:10 2015
New Revision: 232510
URL: http://llvm.org/viewvc/llvm-project?rev=232510&view=rev
Log:
[SwitchLowering] Remove incoming values in the reverse order
- To prevent invalidating *successive* indices.
Modified:
llvm/trunk/lib/Transforms/Utils/LowerSwitch.cpp
llvm/trunk/test/Transforms/Util/lowerswitch.ll
Modified: llvm/trunk/lib/Transforms/Utils/LowerSwitch.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LowerSwitch.cpp?rev=232510&r1=232509&r2=232510&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/LowerSwitch.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/LowerSwitch.cpp Tue Mar 17 13:03:10 2015
@@ -175,11 +175,16 @@ static void fixPhis(BasicBlock *SuccBB,
// Remove additional occurences coming from condensed cases and keep the
// number of incoming values equal to the number of branches to SuccBB.
+ SmallVector<unsigned, 8> Indices;
for (++Idx; LocalNumMergedCases > 0 && Idx < E; ++Idx)
if (PN->getIncomingBlock(Idx) == OrigBB) {
- PN->removeIncomingValue(Idx);
+ Indices.push_back(Idx);
LocalNumMergedCases--;
}
+ // Remove incoming values in the reverse order to prevent invalidating
+ // *successive* index.
+ for (auto III = Indices.rbegin(), IIE = Indices.rend(); III != IIE; ++III)
+ PN->removeIncomingValue(*III);
}
}
Modified: llvm/trunk/test/Transforms/Util/lowerswitch.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Util/lowerswitch.ll?rev=232510&r1=232509&r2=232510&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/Util/lowerswitch.ll (original)
+++ llvm/trunk/test/Transforms/Util/lowerswitch.ll Tue Mar 17 13:03:10 2015
@@ -52,3 +52,137 @@ bb3:
exit:
ret void
}
+
+; Test that we don't crash.
+define void @test2(i32 %mode) {
+; CHECK-LABEL: @test2
+ br i1 undef, label %1, label %._crit_edge
+
+; <label>:1 ; preds = %0
+ switch i32 %mode, label %33 [
+ i32 2, label %2
+ i32 3, label %3
+ i32 4, label %4
+ i32 5, label %5
+ i32 6, label %6
+ i32 7, label %7
+ i32 8, label %8
+ i32 9, label %9
+ i32 10, label %10
+ i32 11, label %14
+ i32 12, label %18
+ i32 13, label %22
+ i32 14, label %26
+ i32 15, label %27
+ i32 16, label %34
+ i32 17, label %34
+ i32 18, label %34
+ i32 19, label %34
+ i32 22, label %34
+ i32 20, label %31
+ i32 21, label %32
+ ]
+
+; <label>:2 ; preds = %1
+ br label %34
+
+; <label>:3 ; preds = %1
+ br label %34
+
+; <label>:4 ; preds = %1
+ br label %34
+
+; <label>:5 ; preds = %1
+ br label %34
+
+; <label>:6 ; preds = %1
+ br label %34
+
+; <label>:7 ; preds = %1
+ br label %34
+
+; <label>:8 ; preds = %1
+ br label %34
+
+; <label>:9 ; preds = %1
+ br label %34
+
+; <label>:10 ; preds = %1
+ br i1 undef, label %11, label %12
+
+; <label>:11 ; preds = %10
+ br label %13
+
+; <label>:12 ; preds = %10
+ br label %13
+
+; <label>:13 ; preds = %12, %11
+ br label %34
+
+; <label>:14 ; preds = %1
+ br i1 undef, label %15, label %16
+
+; <label>:15 ; preds = %14
+ br label %17
+
+; <label>:16 ; preds = %14
+ br label %17
+
+; <label>:17 ; preds = %16, %15
+ br label %34
+
+; <label>:18 ; preds = %1
+ br i1 undef, label %19, label %20
+
+; <label>:19 ; preds = %18
+ br label %21
+
+; <label>:20 ; preds = %18
+ br label %21
+
+; <label>:21 ; preds = %20, %19
+ br label %34
+
+; <label>:22 ; preds = %1
+ br i1 undef, label %23, label %24
+
+; <label>:23 ; preds = %22
+ br label %25
+
+; <label>:24 ; preds = %22
+ br label %25
+
+; <label>:25 ; preds = %24, %23
+ br label %34
+
+; <label>:26 ; preds = %1
+ br label %34
+
+; <label>:27 ; preds = %1
+ br i1 undef, label %28, label %29
+
+; <label>:28 ; preds = %27
+ br label %30
+
+; <label>:29 ; preds = %27
+ br label %30
+
+; <label>:30 ; preds = %29, %28
+ br label %34
+
+; <label>:31 ; preds = %1
+ br label %34
+
+; <label>:32 ; preds = %1
+ br label %34
+
+; <label>:33 ; preds = %1
+ br label %34
+
+; <label>:34 ; preds = %33, %32, %31, %30, %26, %25, %21, %17, %13, %9, %8, %7, %6, %5, %4, %3, %2, %1, %1, %1, %1, %1
+ %o.0 = phi float [ undef, %33 ], [ undef, %32 ], [ undef, %31 ], [ undef, %30 ], [ undef, %26 ], [ undef, %25 ], [ undef, %21 ], [ undef, %17 ], [ undef, %13 ], [ undef, %9 ], [ undef, %8 ], [ undef, %7 ], [ undef, %6 ], [ undef, %5 ], [ undef, %4 ], [ undef, %3 ], [ undef, %2 ], [ undef, %1 ], [ undef, %1 ], [ undef, %1 ], [ undef, %1 ], [ undef, %1 ]
+ br label %._crit_edge
+
+._crit_edge: ; preds = %34, %0
+ ret void
+}
More information about the llvm-commits
mailing list