[llvm] r231755 - Fix an infinite loop in InstCombine when an instruction with no users and side effects can be constant folded.

Owen Anderson resistor at mac.com
Mon Mar 9 22:13:48 PDT 2015


Author: resistor
Date: Tue Mar 10 00:13:47 2015
New Revision: 231755

URL: http://llvm.org/viewvc/llvm-project?rev=231755&view=rev
Log:
Fix an infinite loop in InstCombine when an instruction with no users and side effects can be constant folded.

ReplaceInstUsesWith needs to return nullptr when the input has no users,
because in that case it does not mutate the program.  Otherwise, we can
get stuck in an infinite loop of repeatedly attempting to constant fold
and instruction with no users.

Added:
    llvm/trunk/test/Transforms/InstCombine/constant-fold-hang.ll
Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h?rev=231755&r1=231754&r2=231755&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h Tue Mar 10 00:13:47 2015
@@ -372,6 +372,10 @@ public:
   /// I to the worklist, replace all uses of I with the new value, then return
   /// I, so that the inst combiner will know that I was modified.
   Instruction *ReplaceInstUsesWith(Instruction &I, Value *V) {
+    // If there are no uses to replace, then we return nullptr to indicate that
+    // no changes were made to the program.
+    if (I.use_empty()) return nullptr;
+
     Worklist.AddUsersToWorkList(I); // Add all modified instrs to worklist.
 
     // If we are replacing the instruction with itself, this must be in a

Added: llvm/trunk/test/Transforms/InstCombine/constant-fold-hang.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/constant-fold-hang.ll?rev=231755&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/constant-fold-hang.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/constant-fold-hang.ll Tue Mar 10 00:13:47 2015
@@ -0,0 +1,14 @@
+; RUN: opt -instcombine < %s
+
+; Function Attrs: nounwind readnone ssp
+define void @mulByZero(<4 x i16> %x) #0 {
+entry:
+  %a = tail call <4 x i32> @llvm.arm.neon.vmulls.v4i32(<4 x i16> %x, <4 x i16> zeroinitializer) #2
+  ret void
+}
+
+; Function Attrs: nounwind readnone
+declare <4 x i32> @llvm.arm.neon.vmulls.v4i32(<4 x i16>, <4 x i16>) #1
+
+attributes #0 = { nounwind readnone ssp }
+attributes #1 = { nounwind readnone }





More information about the llvm-commits mailing list