[PATCH] D109477: [ScalarEvolution] Add an additional bailout to avoid NOT of pointer.

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 8 17:53:54 PDT 2021


efriedma created this revision.
efriedma added reviewers: reames, mkazantsev, nikic.
Herald added subscribers: javed.absar, hiraditya.
efriedma requested review of this revision.
Herald added a project: LLVM.

It's possible in some cases for the LHS to be a pointer where the RHS is not.  This isn't directly possible for an icmp, but the analysis mixes up operands of different icmp expressions in some cases.

I haven't managed to reduce a testcase I can commit; the testcase in the bug depends on sanitizer passes, and the obvious reduction methods didn't work for me.

Also add an assertion to getNotSCEV() to make tracking down this sort of issue a bit easier in the future.

Fixes https://bugs.llvm.org/show_bug.cgi?id=51787 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D109477

Files:
  llvm/lib/Analysis/ScalarEvolution.cpp


Index: llvm/lib/Analysis/ScalarEvolution.cpp
===================================================================
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -4127,6 +4127,8 @@
 
 /// Return a SCEV corresponding to ~V = -1-V
 const SCEV *ScalarEvolution::getNotSCEV(const SCEV *V) {
+  assert(!V->getType()->isPointerTy() && "Can't negate pointer");
+
   if (const SCEVConstant *VC = dyn_cast<SCEVConstant>(V))
     return getConstant(
                 cast<ConstantInt>(ConstantExpr::getNot(VC->getValue())));
@@ -10673,7 +10675,8 @@
       return isImpliedCondOperands(Pred, LHS, RHS, FoundRHS, FoundLHS, Context);
 
     // Don't try to getNotSCEV pointers.
-    if (LHS->getType()->isPointerTy() || FoundLHS->getType()->isPointerTy())
+    if (LHS->getType()->isPointerTy() || RHS->getType()->isPointerTy() ||
+        FoundLHS->getType()->isPointerTy() || FoundRHS->getType()->isPointerTy())
       return false;
 
     // There's no clear preference between forms 3. and 4., try both.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109477.371483.patch
Type: text/x-patch
Size: 1033 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210909/3f747cfd/attachment.bin>


More information about the llvm-commits mailing list