diff options
-rw-r--r-- | lib/Transforms/Utils/SimplifyCFG.cpp | 7 | ||||
-rw-r--r-- | test/Transforms/SimplifyCFG/switch_to_lookup_table.ll | 24 |
2 files changed, 29 insertions, 2 deletions
diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index a5e4d44b85..6da791bb1c 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -3351,8 +3351,11 @@ SwitchLookupTable::SwitchLookupTable(Module &M, 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; diff --git a/test/Transforms/SimplifyCFG/switch_to_lookup_table.ll b/test/Transforms/SimplifyCFG/switch_to_lookup_table.ll index 134ac4eeb1..aa48ec6481 100644 --- a/test/Transforms/SimplifyCFG/switch_to_lookup_table.ll +++ b/test/Transforms/SimplifyCFG/switch_to_lookup_table.ll @@ -269,3 +269,27 @@ if.end: ; 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 +} |