diff options
| -rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 7 | ||||
| -rw-r--r-- | llvm/test/Transforms/SimplifyCFG/rangereduce.ll | 28 |
2 files changed, 31 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index f4d7f5e38b9..8e821d9b9fa 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -5132,11 +5132,12 @@ static bool ReduceSwitchRange(SwitchInst *SI, IRBuilder<> &Builder, Builder.CreateShl(Sub, Ty->getBitWidth() - Shift)); SI->replaceUsesOfWith(SI->getCondition(), Rot); - for (auto &C : SI->cases()) { + for (SwitchInst::CaseIt C = SI->case_begin(), E = SI->case_end(); C != E; + ++C) { auto *Orig = C.getCaseValue(); auto Sub = Orig->getValue() - APInt(Ty->getBitWidth(), Base); - SI->replaceUsesOfWith(Orig, - ConstantInt::get(Ty, Sub.lshr(ShiftC->getValue()))); + C.setValue( + cast<ConstantInt>(ConstantInt::get(Ty, Sub.lshr(ShiftC->getValue())))); } return true; } diff --git a/llvm/test/Transforms/SimplifyCFG/rangereduce.ll b/llvm/test/Transforms/SimplifyCFG/rangereduce.ll index d1a745ecfd9..1b6434a4129 100644 --- a/llvm/test/Transforms/SimplifyCFG/rangereduce.ll +++ b/llvm/test/Transforms/SimplifyCFG/rangereduce.ll @@ -192,4 +192,30 @@ two: ret i32 1143 three: ret i32 99783 -}
\ No newline at end of file +} + +; CHECK-LABEL: @test9 +; CHECK: switch +; CHECK: i32 6 +; CHECK: i32 7 +; CHECK: i32 0 +; CHECK: i32 2 +define i32 @test9(i32 %a) { + switch i32 %a, label %def [ + i32 18, label %one + i32 20, label %two + i32 6, label %three + i32 10, label %three + ] + +def: + ret i32 8867 + +one: + ret i32 11984 +two: + ret i32 1143 +three: + ret i32 99783 +} + |

