From 3f162e8e6da14726c7666f5c935c503fcb784a41 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sun, 29 Aug 2021 20:29:04 +0200 Subject: [PATCH] [SCEVExpander] Assert single pointer op in add (NFC) There can only be one pointer operand in an add expression, and we have sorted operands to guarantee that it is the first. As such, the pointer check for other operands is dead code. --- llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp index ca1545b..e0205c1 100644 --- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp +++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp @@ -765,7 +765,11 @@ Value *SCEVExpander::visitAddExpr(const SCEVAddExpr *S) { // This is the first operand. Just expand it. Sum = expand(Op); ++I; - } else if (PointerType *PTy = dyn_cast(Sum->getType())) { + continue; + } + + assert(!Op->getType()->isPointerTy() && "Only first op can be pointer"); + if (PointerType *PTy = dyn_cast(Sum->getType())) { // The running sum expression is a pointer. Try to form a getelementptr // at this level with that as the base. SmallVector NewOps; @@ -779,16 +783,6 @@ Value *SCEVExpander::visitAddExpr(const SCEVAddExpr *S) { NewOps.push_back(X); } Sum = expandAddToGEP(NewOps.begin(), NewOps.end(), PTy, Ty, Sum); - } else if (PointerType *PTy = dyn_cast(Op->getType())) { - // The running sum is an integer, and there's a pointer at this level. - // Try to form a getelementptr. If the running sum is instructions, - // use a SCEVUnknown to avoid re-analyzing them. - SmallVector NewOps; - NewOps.push_back(isa(Sum) ? SE.getUnknown(Sum) : - SE.getSCEV(Sum)); - for (++I; I != E && I->first == CurLoop; ++I) - NewOps.push_back(I->second); - Sum = expandAddToGEP(NewOps.begin(), NewOps.end(), PTy, Ty, expand(Op)); } else if (Op->isNonConstantNegative()) { // Instead of doing a negate and add, just do a subtract. Value *W = expandCodeForImpl(SE.getNegativeSCEV(Op), Ty, false); -- 2.7.4