Unlike the other instructions, GEP really does need to look at the type of a
authorNick Lewycky <nicholas@mxc.ca>
Sat, 13 Jun 2009 19:09:52 +0000 (19:09 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Sat, 13 Jun 2009 19:09:52 +0000 (19:09 +0000)
pointer. This fixes kimwitu++. Pointed out by Frits van Bommel on review!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73299 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/IPO/MergeFunctions.cpp

index 1dd3279b9eb4a669be37b91f7f8a5ed3d7371365..5693cc0fc3b4737a57b0a75ff212669d6b085cc0 100644 (file)
@@ -284,6 +284,20 @@ static bool equals(const BasicBlock *BB1, const BasicBlock *BB2,
     if (!isEquivalentOperation(FI, GI))
       return false;
 
+    if (isa<GetElementPtrInst>(FI)) {
+      const GetElementPtrInst *GEPF = cast<GetElementPtrInst>(FI);
+      const GetElementPtrInst *GEPG = cast<GetElementPtrInst>(GI);
+      if (GEPF->hasAllZeroIndices() && GEPG->hasAllZeroIndices()) {
+        // It's effectively a bitcast.
+        ++FI, ++GI;
+        continue;
+      }
+
+      // TODO: we only really care about the elements before the index
+      if (FI->getOperand(0)->getType() != GI->getOperand(0)->getType())
+        return false;
+    }
+
     if (ValueMap[FI] == GI) {
       ++FI, ++GI;
       continue;