[PATCH] D114555: [ScalarEvolution] Add bailout to avoid zext of pointer.

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 24 11:22:39 PST 2021


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

The RHS of an isImpliedCond call can be a pointer even if the LHS is not. This is similar to bfa2a81e <https://reviews.llvm.org/rGbfa2a81e926f07c1d24d561c84388160cbbed905>.

Not going to include a testcase; an IR testcase would be extremely complicated and fragile.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114555

Files:
  llvm/lib/Analysis/ScalarEvolution.cpp


Index: llvm/lib/Analysis/ScalarEvolution.cpp
===================================================================
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -10767,7 +10767,8 @@
     // For unsigned and equality predicates, try to prove that both found
     // operands fit into narrow unsigned range. If so, try to prove facts in
     // narrow types.
-    if (!CmpInst::isSigned(FoundPred) && !FoundLHS->getType()->isPointerTy()) {
+    if (!CmpInst::isSigned(FoundPred) && !FoundLHS->getType()->isPointerTy() &&
+        !FoundRHS->getType()->isPointerTy()) {
       auto *NarrowType = LHS->getType();
       auto *WideType = FoundLHS->getType();
       auto BitWidth = getTypeSizeInBits(NarrowType);
@@ -10785,7 +10786,7 @@
       }
     }
 
-    if (LHS->getType()->isPointerTy())
+    if (LHS->getType()->isPointerTy() || RHS->getType()->isPointerTy())
       return false;
     if (CmpInst::isSigned(Pred)) {
       LHS = getSignExtendExpr(LHS, FoundLHS->getType());
@@ -10796,7 +10797,7 @@
     }
   } else if (getTypeSizeInBits(LHS->getType()) >
       getTypeSizeInBits(FoundLHS->getType())) {
-    if (FoundLHS->getType()->isPointerTy())
+    if (FoundLHS->getType()->isPointerTy() || FoundRHS->getType()->isPointerTy())
       return false;
     if (CmpInst::isSigned(FoundPred)) {
       FoundLHS = getSignExtendExpr(FoundLHS, LHS->getType());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114555.389575.patch
Type: text/x-patch
Size: 1400 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211124/48293119/attachment.bin>


More information about the llvm-commits mailing list