[StackSafety] Simplify SCEVRewriteVisitor
authorVitaly Buka <vitalybuka@google.com>
Wed, 27 May 2020 00:04:09 +0000 (17:04 -0700)
committerVitaly Buka <vitalybuka@google.com>
Wed, 27 May 2020 01:09:43 +0000 (18:09 -0700)
Probably NFC.

llvm/lib/Analysis/StackSafetyAnalysis.cpp
llvm/test/Analysis/StackSafetyAnalysis/local.ll

index 4b2fc30..10b9f14 100644 (file)
@@ -42,16 +42,6 @@ public:
   AllocaOffsetRewriter(ScalarEvolution &SE, const Value *AllocaPtr)
       : SCEVRewriteVisitor(SE), AllocaPtr(AllocaPtr) {}
 
-  const SCEV *visit(const SCEV *Expr) {
-    // Only re-write the expression if the alloca is used in an addition
-    // expression (it can be used in other types of expressions if it's cast to
-    // an int and passed as an argument.)
-    if (!isa<SCEVAddRecExpr>(Expr) && !isa<SCEVAddExpr>(Expr) &&
-        !isa<SCEVUnknown>(Expr))
-      return Expr;
-    return SCEVRewriteVisitor<AllocaOffsetRewriter>::visit(Expr);
-  }
-
   const SCEV *visitUnknown(const SCEVUnknown *Expr) {
     // FIXME: look through one or several levels of definitions?
     // This can be inttoptr(AllocaPtr) and SCEV would not unwrap
@@ -237,7 +227,8 @@ ConstantRange StackSafetyLocalAnalysis::offsetFrom(Value *Addr, Value *Base) {
   AllocaOffsetRewriter Rewriter(SE, Base);
   const SCEV *Expr = Rewriter.visit(SE.getSCEV(Addr));
   ConstantRange Offset = SE.getUnsignedRange(Expr).zextOrTrunc(PointerSize);
-  assert(!Offset.isEmptySet());
+  if (Offset.isEmptySet())
+    return UnknownRange;
   return Offset;
 }
 
index 0ba1694..b7c9eb1 100644 (file)
@@ -177,6 +177,7 @@ define void @NonConstantOffset(i1 zeroext %z) {
 ; CHECK-NEXT: args uses:
 ; CHECK-NEXT: z[]: full-set{{$}}
 ; CHECK-NEXT: allocas uses:
+; FIXME: SCEV can't look through selects.
 ; CHECK-NEXT: x[4]: [0,4){{$}}
 ; CHECK-NOT: ]:
 entry: