Skip to content

Commit 9738fd6

Browse files
committed
[BypassSlowDivision][CodeGenPrepare] avoid crashing on unused code (PR43514)
https://bugs.llvm.org/show_bug.cgi?id=43514 llvm-svn: 373394
1 parent 081e9df commit 9738fd6

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

llvm/lib/Transforms/Utils/BypassSlowDivision.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,13 +448,17 @@ bool llvm::bypassSlowDivision(BasicBlock *BB,
448448
DivCacheTy PerBBDivCache;
449449

450450
bool MadeChange = false;
451-
Instruction* Next = &*BB->begin();
451+
Instruction *Next = &*BB->begin();
452452
while (Next != nullptr) {
453453
// We may add instructions immediately after I, but we want to skip over
454454
// them.
455-
Instruction* I = Next;
455+
Instruction *I = Next;
456456
Next = Next->getNextNode();
457457

458+
// Ignore dead code to save time and avoid bugs.
459+
if (I->hasNUses(0))
460+
continue;
461+
458462
FastDivInsertionTask Task(I, BypassWidths);
459463
if (Value *Replacement = Task.getReplacement(PerBBDivCache)) {
460464
I->replaceAllUsesWith(Replacement);

llvm/test/CodeGen/X86/bypass-slow-division-64.ll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,13 @@ define i64 @Test_get_quotient_and_remainder(i64 %a, i64 %b) nounwind {
7575
%result = add i64 %resultdiv, %resultrem
7676
ret i64 %result
7777
}
78+
79+
define void @PR43514(i32 %x, i32 %y) {
80+
; CHECK-LABEL: PR43514:
81+
; CHECK: # %bb.0:
82+
; CHECK-NEXT: retq
83+
%z1 = zext i32 %x to i64
84+
%z2 = zext i32 %y to i64
85+
%s = srem i64 %z1, %z2
86+
ret void
87+
}

0 commit comments

Comments
 (0)