[llvm] r373394 - [BypassSlowDivision][CodeGenPrepare] avoid crashing on unused code (PR43514)

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 1 14:25:36 PDT 2019


Author: spatel
Date: Tue Oct  1 14:25:36 2019
New Revision: 373394

URL: http://llvm.org/viewvc/llvm-project?rev=373394&view=rev
Log:
[BypassSlowDivision][CodeGenPrepare] avoid crashing on unused code (PR43514)

https://bugs.llvm.org/show_bug.cgi?id=43514

Modified:
    llvm/trunk/lib/Transforms/Utils/BypassSlowDivision.cpp
    llvm/trunk/test/CodeGen/X86/bypass-slow-division-64.ll

Modified: llvm/trunk/lib/Transforms/Utils/BypassSlowDivision.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/BypassSlowDivision.cpp?rev=373394&r1=373393&r2=373394&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/BypassSlowDivision.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/BypassSlowDivision.cpp Tue Oct  1 14:25:36 2019
@@ -448,13 +448,17 @@ bool llvm::bypassSlowDivision(BasicBlock
   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);

Modified: llvm/trunk/test/CodeGen/X86/bypass-slow-division-64.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/bypass-slow-division-64.ll?rev=373394&r1=373393&r2=373394&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/bypass-slow-division-64.ll (original)
+++ llvm/trunk/test/CodeGen/X86/bypass-slow-division-64.ll Tue Oct  1 14:25:36 2019
@@ -75,3 +75,13 @@ define i64 @Test_get_quotient_and_remain
   %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
+}




More information about the llvm-commits mailing list