[llvm] f897d08 - [LoopCacheAnalysis]: Fix assertion failure during cost computation
Rachel Craik via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 15 11:57:02 PST 2019
Author: Rachel Craik
Date: 2019-11-15T14:56:26-05:00
New Revision: f897d087d09dbbccec3417f812109ed534b94248
URL: https://github.com/llvm/llvm-project/commit/f897d087d09dbbccec3417f812109ed534b94248
DIFF: https://github.com/llvm/llvm-project/commit/f897d087d09dbbccec3417f812109ed534b94248.diff
LOG: [LoopCacheAnalysis]: Fix assertion failure during cost computation
Ensure the stride and trip count have the same type before multiplying them during reference cost calculation
Reviewed By: jdoefert
Differential Revision: https://reviews.llvm.org/D70192
Added:
llvm/test/Analysis/LoopCacheAnalysis/PowerPC/compute-cost.ll
Modified:
llvm/lib/Analysis/LoopCacheAnalysis.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/LoopCacheAnalysis.cpp b/llvm/lib/Analysis/LoopCacheAnalysis.cpp
index 098bc6f6818f..25325ec1be02 100644
--- a/llvm/lib/Analysis/LoopCacheAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopCacheAnalysis.cpp
@@ -284,6 +284,9 @@ CacheCostTy IndexedReference::computeRefCost(const Loop &L,
const SCEV *ElemSize = Sizes.back();
const SCEV *Stride = SE.getMulExpr(Coeff, ElemSize);
const SCEV *CacheLineSize = SE.getConstant(Stride->getType(), CLS);
+ Type *WiderType = SE.getWiderType(Stride->getType(), TripCount->getType());
+ Stride = SE.getNoopOrSignExtend(Stride, WiderType);
+ TripCount = SE.getNoopOrAnyExtend(TripCount, WiderType);
const SCEV *Numerator = SE.getMulExpr(Stride, TripCount);
RefCost = SE.getUDivExpr(Numerator, CacheLineSize);
LLVM_DEBUG(dbgs().indent(4)
diff --git a/llvm/test/Analysis/LoopCacheAnalysis/PowerPC/compute-cost.ll b/llvm/test/Analysis/LoopCacheAnalysis/PowerPC/compute-cost.ll
new file mode 100644
index 000000000000..8afde3697a46
--- /dev/null
+++ b/llvm/test/Analysis/LoopCacheAnalysis/PowerPC/compute-cost.ll
@@ -0,0 +1,35 @@
+; RUN: opt < %s -passes='print<loop-cache-cost>' -disable-output 2>&1 | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-n32:64"
+target triple = "powerpc64le-unknown-linux-gnu"
+
+; Check IndexedReference::computeRefCost can handle type
diff erences between
+; Stride and TripCount
+
+; CHECK: Loop 'for.cond' has cost = 64
+
+%struct._Handleitem = type { %struct._Handleitem* }
+
+define void @handle_to_ptr(%struct._Handleitem** %blocks) {
+; Preheader:
+entry:
+ br label %for.cond
+
+; Loop:
+for.cond: ; preds = %for.body, %entry
+ %i.0 = phi i32 [ 1, %entry ], [ %inc, %for.body ]
+ %cmp = icmp ult i32 %i.0, 1024
+ br i1 %cmp, label %for.body, label %for.end
+
+for.body: ; preds = %for.cond
+ %idxprom = zext i32 %i.0 to i64
+ %arrayidx = getelementptr inbounds %struct._Handleitem*, %struct._Handleitem** %blocks, i64 %idxprom
+ store %struct._Handleitem* null, %struct._Handleitem** %arrayidx, align 8
+ %inc = add nuw nsw i32 %i.0, 1
+ br label %for.cond
+
+; Exit blocks
+for.end: ; preds = %for.cond
+ ret void
+
+}
More information about the llvm-commits
mailing list