[llvm-commits] Review Request for modification to Instruction::IsIdenticalToWhenDefined
Joel Jones
joel_k_jones at apple.com
Wed May 9 16:44:24 PDT 2012
Fix a problem with incomplete equality testing of PHINodes in Instruction::IsIdenticalToWhenDefined.
This manifested itself when inlining two calls to the same function. The inlined function had a switch statement that returned one of a set of global variables. Without this modification, the two phi instructions that chose values from the branches of the switch instruction inlined from the callee were considered equivalent and jump-threading replaced a load for the first switch value with a phi selecting from the second switch, thereby producing incorrect code.
This patch has been tested with "make check-all", "lnt runteste nt", and llvm self-hosted, and on the original program that had this problem, wireshark.
<rdar://problem/11025519>
Attached is a test case which will reside in test/Transforms/JumpThreading
Index: lib/VMCore/Instruction.cpp
===================================================================
--- lib/VMCore/Instruction.cpp (revision 156460)
+++ lib/VMCore/Instruction.cpp (working copy)
@@ -226,7 +226,15 @@
RMWI->isVolatile() == cast<AtomicRMWInst>(I)->isVolatile() &&
RMWI->getOrdering() == cast<AtomicRMWInst>(I)->getOrdering() &&
RMWI->getSynchScope() == cast<AtomicRMWInst>(I)->getSynchScope();
-
+ if (const PHINode *thisPHI = dyn_cast<PHINode>(this)) {
+ // The check above ensures that the dyn_cast and getIncomingBlock calls
+ // below won't fail, as the type of otherPHI must be PHINode and the
+ // number of incoming blocks must be the same.
+ const PHINode *otherPHI = dyn_cast<PHINode>(I);
+ for (unsigned i = 0, e = thisPHI->getNumOperands(); i != e; ++i)
+ if (thisPHI->getIncomingBlock(i) != otherPHI->getIncomingBlock(i))
+ return false;
+ }
return true;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: phi-eq.ll
Type: application/octet-stream
Size: 33678 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120509/0f75781b/attachment.obj>
More information about the llvm-commits
mailing list