[llvm-commits] [llvm] r164934 - in /llvm/trunk: lib/Transforms/Utils/SimplifyCFG.cpp test/Transforms/SimplifyCFG/switch_to_lookup_table.ll
Benjamin Kramer
benny.kra at googlemail.com
Mon Oct 1 04:31:49 PDT 2012
Author: d0k
Date: Mon Oct 1 06:31:48 2012
New Revision: 164934
URL: http://llvm.org/viewvc/llvm-project?rev=164934&view=rev
Log:
SimplifyCFG: Don't crash when forming a switch bitmap with an undef default value.
Fixes PR13985.
Modified:
llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/trunk/test/Transforms/SimplifyCFG/switch_to_lookup_table.ll
Modified: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=164934&r1=164933&r2=164934&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Mon Oct 1 06:31:48 2012
@@ -3351,8 +3351,11 @@
APInt TableInt(TableSize * IT->getBitWidth(), 0);
for (uint64_t I = TableSize; I > 0; --I) {
TableInt <<= IT->getBitWidth();
- ConstantInt *Val = cast<ConstantInt>(TableContents[I - 1]);
- TableInt |= Val->getValue().zext(TableInt.getBitWidth());
+ // Insert values into the bitmap. Undef values are set to zero.
+ if (!isa<UndefValue>(TableContents[I - 1])) {
+ ConstantInt *Val = cast<ConstantInt>(TableContents[I - 1]);
+ TableInt |= Val->getValue().zext(TableInt.getBitWidth());
+ }
}
BitMap = ConstantInt::get(M.getContext(), TableInt);
BitMapElementTy = IT;
Modified: llvm/trunk/test/Transforms/SimplifyCFG/switch_to_lookup_table.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/switch_to_lookup_table.ll?rev=164934&r1=164933&r2=164934&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/switch_to_lookup_table.ll (original)
+++ llvm/trunk/test/Transforms/SimplifyCFG/switch_to_lookup_table.ll Mon Oct 1 06:31:48 2012
@@ -269,3 +269,27 @@
; CHECK: switch
; CHECK: phi
}
+
+; PR13985
+define i1 @undef(i32 %tmp) uwtable ssp {
+bb:
+ switch i32 %tmp, label %bb3 [
+ i32 0, label %bb1
+ i32 1, label %bb1
+ i32 7, label %bb2
+ i32 8, label %bb2
+ ]
+
+bb1: ; preds = %bb, %bb
+ br label %bb3
+
+bb2: ; preds = %bb, %bb
+ br label %bb3
+
+bb3: ; preds = %bb2, %bb1, %bb
+ %tmp4 = phi i1 [ undef, %bb ], [ false, %bb2 ], [ true, %bb1 ]
+ ret i1 %tmp4
+; CHECK: define i1 @undef
+; CHECK: %switch.cast = trunc i32 %switch.tableidx to i9
+; CHECK: %switch.downshift = lshr i9 3, %switch.shiftamt
+}
More information about the llvm-commits
mailing list