diff options
author | Sanjay Patel <spatel@rotateright.com> | 2019-10-01 21:25:36 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2019-10-01 21:25:36 +0000 |
commit | 9738fd63877136eb1ffffb74ad78ea77861c88fe (patch) | |
tree | 6a4aa2c545360d0375297a76981aa1162510fe5b | |
parent | 081e9df1e1874078a46d3421ce7a3fca55b23259 (diff) | |
download | bcm5719-llvm-9738fd63877136eb1ffffb74ad78ea77861c88fe.tar.gz bcm5719-llvm-9738fd63877136eb1ffffb74ad78ea77861c88fe.zip |
[BypassSlowDivision][CodeGenPrepare] avoid crashing on unused code (PR43514)
https://bugs.llvm.org/show_bug.cgi?id=43514
llvm-svn: 373394
-rw-r--r-- | llvm/lib/Transforms/Utils/BypassSlowDivision.cpp | 8 | ||||
-rw-r--r-- | llvm/test/CodeGen/X86/bypass-slow-division-64.ll | 10 |
2 files changed, 16 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/BypassSlowDivision.cpp b/llvm/lib/Transforms/Utils/BypassSlowDivision.cpp index df299f673f6..9a6761040bd 100644 --- a/llvm/lib/Transforms/Utils/BypassSlowDivision.cpp +++ b/llvm/lib/Transforms/Utils/BypassSlowDivision.cpp @@ -448,13 +448,17 @@ bool llvm::bypassSlowDivision(BasicBlock *BB, DivCacheTy PerBBDivCache; bool MadeChange = false; - Instruction* Next = &*BB->begin(); + Instruction *Next = &*BB->begin(); while (Next != nullptr) { // We may add instructions immediately after I, but we want to skip over // them. - Instruction* I = Next; + Instruction *I = Next; Next = Next->getNextNode(); + // Ignore dead code to save time and avoid bugs. + if (I->hasNUses(0)) + continue; + FastDivInsertionTask Task(I, BypassWidths); if (Value *Replacement = Task.getReplacement(PerBBDivCache)) { I->replaceAllUsesWith(Replacement); diff --git a/llvm/test/CodeGen/X86/bypass-slow-division-64.ll b/llvm/test/CodeGen/X86/bypass-slow-division-64.ll index 11fc0df2443..14a71050e94 100644 --- a/llvm/test/CodeGen/X86/bypass-slow-division-64.ll +++ b/llvm/test/CodeGen/X86/bypass-slow-division-64.ll @@ -75,3 +75,13 @@ define i64 @Test_get_quotient_and_remainder(i64 %a, i64 %b) nounwind { %result = add i64 %resultdiv, %resultrem ret i64 %result } + +define void @PR43514(i32 %x, i32 %y) { +; CHECK-LABEL: PR43514: +; CHECK: # %bb.0: +; CHECK-NEXT: retq + %z1 = zext i32 %x to i64 + %z2 = zext i32 %y to i64 + %s = srem i64 %z1, %z2 + ret void +} |