]> granicus.if.org Git - llvm/commitdiff
[BasicAA] Don't call isKnownNonEqual if we might be have gone through a PHINode.
authorCraig Topper <craig.topper@intel.com>
Thu, 15 Jun 2017 17:16:56 +0000 (17:16 +0000)
committerCraig Topper <craig.topper@intel.com>
Thu, 15 Jun 2017 17:16:56 +0000 (17:16 +0000)
This is a fix for the test case in PR32314.

Basic Alias Analysis can ask if two nodes are known non-equal after looking through a phi node to find a GEP. isAddOfNonZero saw an add of a constant from the same phi and said that its output couldn't be equal. But Basic Alias Analysis was really asking about the value from the previous loop iteration.

This patch at least makes that case not happen anymore, I'm not sure if there were still other ways this can fail. As was discussed in the bug, it looks like fixing BasicAA would be difficult so this patch seemed like a possible workaround

Differential Revision: https://reviews.llvm.org/D33136

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

lib/Analysis/BasicAliasAnalysis.cpp

index f743cb234c455f0a5d05603510b31fccc409c6aa..dbb1b01b94ac28883efb5802db446f1a2683a465 100644 (file)
@@ -1011,10 +1011,24 @@ static AliasResult aliasSameBasePointerGEPs(const GEPOperator *GEP1,
     // equal each other so we can exit early.
     if (C1 && C2)
       return NoAlias;
-    if (isKnownNonEqual(GEP1->getOperand(GEP1->getNumOperands() - 1),
-                        GEP2->getOperand(GEP2->getNumOperands() - 1),
-                        DL))
-      return NoAlias;
+    {
+      Value *GEP1LastIdx = GEP1->getOperand(GEP1->getNumOperands() - 1);
+      Value *GEP2LastIdx = GEP2->getOperand(GEP2->getNumOperands() - 1);
+      if (isa<PHINode>(GEP1LastIdx) || isa<PHINode>(GEP2LastIdx)) {
+        // If one of the indices is a PHI node, be safe and only use
+        // computeKnownBits so we don't make any assumptions about the
+        // relationships between the two indices. This is important if we're
+        // asking about values from different loop iterations. See PR32314.
+        // TODO: We may be able to change the check so we only do this when
+        // we definitely looked through a PHINode.
+        KnownBits Known1 = computeKnownBits(GEP1LastIdx, DL);
+        KnownBits Known2 = computeKnownBits(GEP2LastIdx, DL);
+        if (Known1.Zero.intersects(Known2.One) ||
+            Known1.One.intersects(Known2.Zero))
+          return NoAlias;
+      } else if (isKnownNonEqual(GEP1LastIdx, GEP2LastIdx, DL))
+        return NoAlias;
+    }
     return MayAlias;
   } else if (!LastIndexedStruct || !C1 || !C2) {
     return MayAlias;