summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2015-03-10 05:13:47 +0000
committerOwen Anderson <resistor@mac.com>2015-03-10 05:13:47 +0000
commit51b75b8c346dd0e062b9e81c22b75e36c4b15c1a (patch)
treedbdc95f4a2681572cbe79dcf3d7cd1ade941902d /llvm/lib/Transforms/InstCombine/InstCombineInternal.h
parenteb26ddf559cf9ce2e198f7d9ea1241f2bbb6cf32 (diff)
downloadbcm5719-llvm-51b75b8c346dd0e062b9e81c22b75e36c4b15c1a.tar.gz
bcm5719-llvm-51b75b8c346dd0e062b9e81c22b75e36c4b15c1a.zip
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. llvm-svn: 231755
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineInternal.h')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineInternal.h4
1 files changed, 4 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
index 8c784ab1e68..fb2321df2e0 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
+++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
@@ -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
OpenPOWER on IntegriCloud