[llvm] r306938 - [Cloner] Re-map simplfied cloned instructions.
Davide Italiano via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 30 20:29:33 PDT 2017
Author: davide
Date: Fri Jun 30 20:29:33 2017
New Revision: 306938
URL: http://llvm.org/viewvc/llvm-project?rev=306938&view=rev
Log:
[Cloner] Re-map simplfied cloned instructions.
This commit pretty much rolls back the logic added in r306495
as in the testcase provided we simplify an `icmp` looking through
a PHI that hasn't been mapped yet.
I think instsimplify shouldn't do threading over select/phis or
just looking through phis in general, but this is what we have
now. Also, add a test to prevent this from happening in case somebody
wants to modify this code again.
Briefly discussed with Kyle Butt (thanks Kyle!).
Added:
llvm/trunk/test/Transforms/Inline/pr33637.ll
Modified:
llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp
Modified: llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp?rev=306938&r1=306937&r2=306938&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp Fri Jun 30 20:29:33 2017
@@ -325,11 +325,10 @@ void PruningFunctionCloner::CloneBlock(c
// the basic block.
if (Value *V =
SimplifyInstruction(NewInst, BB->getModule()->getDataLayout())) {
- assert((!isa<Instruction>(V) ||
- cast<Instruction>(V)->getParent() == nullptr ||
- cast<Instruction>(V)->getFunction() != OldFunc ||
- OldFunc == NewFunc) &&
- "Simplified Instruction should not be in the old function.");
+ // On the off-chance that this simplifies to an instruction in the old
+ // function, map it back into the new function.
+ if (Value *MappedV = VMap.lookup(V))
+ V = MappedV;
if (!NewInst->mayHaveSideEffects()) {
VMap[&*II] = V;
Added: llvm/trunk/test/Transforms/Inline/pr33637.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Inline/pr33637.ll?rev=306938&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/Inline/pr33637.ll (added)
+++ llvm/trunk/test/Transforms/Inline/pr33637.ll Fri Jun 30 20:29:33 2017
@@ -0,0 +1,25 @@
+; RUN: opt -inline < %s
+
+define void @patatino() {
+for.cond:
+ br label %for.body
+
+for.body:
+ %tobool = icmp eq i32 5, 0
+ %sel = select i1 %tobool, i32 0, i32 2
+ br i1 undef, label %cleanup1.thread, label %cleanup1
+
+cleanup1.thread:
+ ret void
+
+cleanup1:
+ %cleanup.dest2 = phi i32 [ %sel, %for.body ]
+ %switch = icmp ult i32 %cleanup.dest2, 1
+ ret void
+}
+
+define void @main() {
+entry:
+ call void @patatino()
+ ret void
+}
More information about the llvm-commits
mailing list