[PATCH] D73777: [SCEV][IndVars] Always provide insertion point to the SCEVExpander::isHighCostExpansion()
Roman Lebedev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 5 06:36:04 PST 2020
lebedev.ri updated this revision to Diff 242597.
lebedev.ri added a comment.
Rebased.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D73777/new/
https://reviews.llvm.org/D73777
Files:
llvm/include/llvm/Analysis/ScalarEvolutionExpander.h
llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
llvm/test/Transforms/IndVarSimplify/elim-extend.ll
Index: llvm/test/Transforms/IndVarSimplify/elim-extend.ll
===================================================================
--- llvm/test/Transforms/IndVarSimplify/elim-extend.ll
+++ llvm/test/Transforms/IndVarSimplify/elim-extend.ll
@@ -140,8 +140,8 @@
; CHECK-NEXT: store i8 0, i8* [[ADR2]]
; CHECK-NEXT: [[ADR3:%.*]] = getelementptr i8, i8* [[ADDRESS]], i64 [[INDVARS_IV_NEXT]]
; CHECK-NEXT: store i8 0, i8* [[ADR3]]
-; CHECK-NEXT: [[INNERCMP:%.*]] = icmp sgt i64 [[TMP0]], [[INDVARS_IV_NEXT]]
-; CHECK-NEXT: br i1 [[INNERCMP]], label [[INNERLOOP]], label [[INNEREXIT:%.*]]
+; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i64 [[INDVARS_IV_NEXT]], [[TMP0]]
+; CHECK-NEXT: br i1 [[EXITCOND]], label [[INNERLOOP]], label [[INNEREXIT:%.*]]
; CHECK: innerexit:
; CHECK-NEXT: [[TMP4:%.*]] = trunc i64 [[TMP0]] to i32
; CHECK-NEXT: br label [[OUTERMERGE]]
@@ -153,8 +153,8 @@
; CHECK-NEXT: [[ADR5:%.*]] = getelementptr i8, i8* [[ADDRESS]], i64 [[OFS5]]
; CHECK-NEXT: store i8 0, i8* [[ADR5]]
; CHECK-NEXT: [[INDVARS_IV_NEXT2]] = add nuw nsw i64 [[INDVARS_IV1]], 1
-; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i64 [[INDVARS_IV_NEXT2]], [[WIDE_TRIP_COUNT]]
-; CHECK-NEXT: br i1 [[EXITCOND]], label [[OUTERLOOP]], label [[RETURN:%.*]]
+; CHECK-NEXT: [[EXITCOND4:%.*]] = icmp ne i64 [[INDVARS_IV_NEXT2]], [[WIDE_TRIP_COUNT]]
+; CHECK-NEXT: br i1 [[EXITCOND4]], label [[OUTERLOOP]], label [[RETURN:%.*]]
; CHECK: return:
; CHECK-NEXT: ret void
;
Index: llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -2719,6 +2719,9 @@
// If we have a trip count expression, rewrite the loop's exit condition
// using it.
if (!DisableLFTR) {
+ BasicBlock *PreHeader = L->getLoopPreheader();
+ BranchInst *PreHeaderBR = cast<BranchInst>(PreHeader->getTerminator());
+
SmallVector<BasicBlock*, 16> ExitingBlocks;
L->getExitingBlocks(ExitingBlocks);
for (BasicBlock *ExitingBB : ExitingBlocks) {
@@ -2753,7 +2756,7 @@
// Avoid high cost expansions. Note: This heuristic is questionable in
// that our definition of "high cost" is not exactly principled.
if (Rewriter.isHighCostExpansion(ExitCount, L, SCEVCheapExpansionBudget,
- TTI))
+ TTI, PreHeaderBR))
continue;
// Check preconditions for proper SCEVExpander operation. SCEV does not
Index: llvm/include/llvm/Analysis/ScalarEvolutionExpander.h
===================================================================
--- llvm/include/llvm/Analysis/ScalarEvolutionExpander.h
+++ llvm/include/llvm/Analysis/ScalarEvolutionExpander.h
@@ -176,12 +176,12 @@
/// Return true for expressions that can't be evaluated at runtime
/// within given \b Budget.
///
- /// At is an optional parameter which specifies point in code where user is
- /// going to expand this expression. Sometimes this knowledge can lead to a
- /// more accurate cost estimation.
+ /// At is a parameter which specifies point in code where user is going to
+ /// expand this expression. Sometimes this knowledge can lead to
+ /// a less pessimistic cost estimation.
bool isHighCostExpansion(const SCEV *Expr, Loop *L, unsigned Budget,
const TargetTransformInfo *TTI,
- const Instruction *At = nullptr) {
+ const Instruction *At) {
assert(TTI && "This function requires TTI to be provided.");
if (!TTI) // In assert-less builds, avoid crashing
return true; // by always claiming to be high-cost.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73777.242597.patch
Type: text/x-patch
Size: 3816 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200205/71dfb9a4/attachment.bin>
More information about the llvm-commits
mailing list