<div dir="ltr"><div>Thanks for the test case. Reduced further, and this seems to be an existing bug - this crashes with "opt -analyze -cost-model costcrash.ll -S" independently of the cost model change that I made:</div><div><br></div><div>target triple = "x86_64"<br>declare float @llvm.vector.reduce.fadd.v4f32(float, <4 x float>)<br>define void @c() {<br> %r = call fast float @llvm.vector.reduce.fadd.v4f32(float 0.0, <4 x float> undef)<br> ret void<br>}<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Oct 25, 2020 at 2:48 AM Martin Storsjö via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
Author: Martin Storsjö<br>
Date: 2020-10-25T08:47:54+02:00<br>
New Revision: 1c8371692dfe8245bc6690ff1262dcced4649d21<br>
<br>
URL: <a href="https://github.com/llvm/llvm-project/commit/1c8371692dfe8245bc6690ff1262dcced4649d21" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/1c8371692dfe8245bc6690ff1262dcced4649d21</a><br>
DIFF: <a href="https://github.com/llvm/llvm-project/commit/1c8371692dfe8245bc6690ff1262dcced4649d21.diff" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/1c8371692dfe8245bc6690ff1262dcced4649d21.diff</a><br>
<br>
LOG: Revert "[CostModel] remove cost-kind predicate for vector reduction costs"<br>
<br>
This reverts commit 22d10b8ab44f703b72b8316a9b3b8adc623ca73f.<br>
<br>
This broke compilation e.g. like this:<br>
$ cat synth.c<br>
*a;<br>
float *b;<br>
c() {<br>
for (;;) {<br>
float d = -*b * *a++;<br>
d -= *--b * *a++;<br>
d -= *--b * *a;<br>
d -= *--b * *a;<br>
e(d);<br>
}<br>
}<br>
$ clang -target x86_64-linux-gnu -c -O2 -ffast-math synth.c<br>
clang: ../include/llvm/Support/Casting.h:104: static bool llvm::isa_impl<br>
_cl<To, const From*>::doit(const From*) [with To = llvm::PointerType; Fr<br>
om = llvm::Type]: Assertion `Val && "isa<> used on a null pointer"' fail<br>
ed.<br>
<br>
Added: <br>
<br>
<br>
Modified: <br>
llvm/include/llvm/CodeGen/BasicTTIImpl.h<br>
llvm/test/Analysis/CostModel/ARM/intrinsic-cost-kinds.ll<br>
llvm/test/Analysis/CostModel/ARM/reduce-add.ll<br>
llvm/test/Analysis/CostModel/X86/intrinsic-cost-kinds.ll<br>
<br>
Removed: <br>
<br>
<br>
<br>
################################################################################<br>
diff --git a/llvm/include/llvm/CodeGen/BasicTTIImpl.h b/llvm/include/llvm/CodeGen/BasicTTIImpl.h<br>
index 87b70411ef38..c615d48a1021 100644<br>
--- a/llvm/include/llvm/CodeGen/BasicTTIImpl.h<br>
+++ b/llvm/include/llvm/CodeGen/BasicTTIImpl.h<br>
@@ -1202,6 +1202,9 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {<br>
case Intrinsic::vector_reduce_fmin:<br>
case Intrinsic::vector_reduce_umax:<br>
case Intrinsic::vector_reduce_umin: {<br>
+ // FIXME: all cost kinds should default to the same thing?<br>
+ if (CostKind != TTI::TCK_RecipThroughput)<br>
+ return BaseT::getIntrinsicInstrCost(ICA, CostKind);<br>
IntrinsicCostAttributes Attrs(IID, RetTy, Args[0]->getType(), FMF, 1, I);<br>
return getTypeBasedIntrinsicInstrCost(Attrs, CostKind);<br>
}<br>
<br>
diff --git a/llvm/test/Analysis/CostModel/ARM/intrinsic-cost-kinds.ll b/llvm/test/Analysis/CostModel/ARM/intrinsic-cost-kinds.ll<br>
index ea9b6a07f4e4..bffaa98c82aa 100644<br>
--- a/llvm/test/Analysis/CostModel/ARM/intrinsic-cost-kinds.ll<br>
+++ b/llvm/test/Analysis/CostModel/ARM/intrinsic-cost-kinds.ll<br>
@@ -213,11 +213,11 @@ define void @reduce_fmax(<16 x float> %va) {<br>
; LATE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void<br>
;<br>
; SIZE-LABEL: 'reduce_fmax'<br>
-; SIZE-NEXT: Cost Model: Found an estimated cost of 620 for instruction: %v = call float @llvm.vector.reduce.fmax.v16f32(<16 x float> %va)<br>
+; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v = call float @llvm.vector.reduce.fmax.v16f32(<16 x float> %va)<br>
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void<br>
;<br>
; SIZE_LATE-LABEL: 'reduce_fmax'<br>
-; SIZE_LATE-NEXT: Cost Model: Found an estimated cost of 620 for instruction: %v = call float @llvm.vector.reduce.fmax.v16f32(<16 x float> %va)<br>
+; SIZE_LATE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v = call float @llvm.vector.reduce.fmax.v16f32(<16 x float> %va)<br>
; SIZE_LATE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void<br>
;<br>
%v = call float @llvm.vector.reduce.fmax.v16f32(<16 x float> %va)<br>
<br>
diff --git a/llvm/test/Analysis/CostModel/ARM/reduce-add.ll b/llvm/test/Analysis/CostModel/ARM/reduce-add.ll<br>
index b3cc0adf7460..2564c1e456c1 100644<br>
--- a/llvm/test/Analysis/CostModel/ARM/reduce-add.ll<br>
+++ b/llvm/test/Analysis/CostModel/ARM/reduce-add.ll<br>
@@ -22,19 +22,19 @@ define i32 @reduce_i64(i32 %arg) {<br>
; NEON-RECIP-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret i32 undef<br>
;<br>
; V8M-SIZE-LABEL: 'reduce_i64'<br>
-; V8M-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %V1 = call i64 @llvm.vector.reduce.add.v1i64(<1 x i64> undef)<br>
-; V8M-SIZE-NEXT: Cost Model: Found an estimated cost of 7 for instruction: %V2 = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> undef)<br>
-; V8M-SIZE-NEXT: Cost Model: Found an estimated cost of 16 for instruction: %V4 = call i64 @llvm.vector.reduce.add.v4i64(<4 x i64> undef)<br>
-; V8M-SIZE-NEXT: Cost Model: Found an estimated cost of 33 for instruction: %V8 = call i64 @llvm.vector.reduce.add.v8i64(<8 x i64> undef)<br>
-; V8M-SIZE-NEXT: Cost Model: Found an estimated cost of 66 for instruction: %V16 = call i64 @llvm.vector.reduce.add.v16i64(<16 x i64> undef)<br>
+; V8M-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V1 = call i64 @llvm.vector.reduce.add.v1i64(<1 x i64> undef)<br>
+; V8M-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V2 = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> undef)<br>
+; V8M-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V4 = call i64 @llvm.vector.reduce.add.v4i64(<4 x i64> undef)<br>
+; V8M-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V8 = call i64 @llvm.vector.reduce.add.v8i64(<8 x i64> undef)<br>
+; V8M-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V16 = call i64 @llvm.vector.reduce.add.v16i64(<16 x i64> undef)<br>
; V8M-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret i32 undef<br>
;<br>
; NEON-SIZE-LABEL: 'reduce_i64'<br>
-; NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %V1 = call i64 @llvm.vector.reduce.add.v1i64(<1 x i64> undef)<br>
-; NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 16 for instruction: %V2 = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> undef)<br>
-; NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 29 for instruction: %V4 = call i64 @llvm.vector.reduce.add.v4i64(<4 x i64> undef)<br>
-; NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 54 for instruction: %V8 = call i64 @llvm.vector.reduce.add.v8i64(<8 x i64> undef)<br>
-; NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 103 for instruction: %V16 = call i64 @llvm.vector.reduce.add.v16i64(<16 x i64> undef)<br>
+; NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V1 = call i64 @llvm.vector.reduce.add.v1i64(<1 x i64> undef)<br>
+; NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V2 = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> undef)<br>
+; NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V4 = call i64 @llvm.vector.reduce.add.v4i64(<4 x i64> undef)<br>
+; NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V8 = call i64 @llvm.vector.reduce.add.v8i64(<8 x i64> undef)<br>
+; NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V16 = call i64 @llvm.vector.reduce.add.v16i64(<16 x i64> undef)<br>
; NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret i32 undef<br>
;<br>
%V1 = call i64 @llvm.vector.reduce.add.v1i64(<1 x i64> undef)<br>
@@ -67,23 +67,23 @@ define i32 @reduce_i32(i32 %arg) {<br>
; NEON-RECIP-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret i32 undef<br>
;<br>
; V8M-SIZE-LABEL: 'reduce_i32'<br>
-; V8M-SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %V2 = call i8 @llvm.vector.reduce.add.v2i8(<2 x i8> undef)<br>
-; V8M-SIZE-NEXT: Cost Model: Found an estimated cost of 9 for instruction: %V4 = call i8 @llvm.vector.reduce.add.v4i8(<4 x i8> undef)<br>
-; V8M-SIZE-NEXT: Cost Model: Found an estimated cost of 18 for instruction: %V8 = call i8 @llvm.vector.reduce.add.v8i8(<8 x i8> undef)<br>
-; V8M-SIZE-NEXT: Cost Model: Found an estimated cost of 35 for instruction: %V16 = call i8 @llvm.vector.reduce.add.v16i8(<16 x i8> undef)<br>
-; V8M-SIZE-NEXT: Cost Model: Found an estimated cost of 68 for instruction: %V32 = call i8 @llvm.vector.reduce.add.v32i8(<32 x i8> undef)<br>
-; V8M-SIZE-NEXT: Cost Model: Found an estimated cost of 133 for instruction: %V64 = call i8 @llvm.vector.reduce.add.v64i8(<64 x i8> undef)<br>
-; V8M-SIZE-NEXT: Cost Model: Found an estimated cost of 262 for instruction: %V128 = call i8 @llvm.vector.reduce.add.v128i8(<128 x i8> undef)<br>
+; V8M-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V2 = call i8 @llvm.vector.reduce.add.v2i8(<2 x i8> undef)<br>
+; V8M-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V4 = call i8 @llvm.vector.reduce.add.v4i8(<4 x i8> undef)<br>
+; V8M-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V8 = call i8 @llvm.vector.reduce.add.v8i8(<8 x i8> undef)<br>
+; V8M-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V16 = call i8 @llvm.vector.reduce.add.v16i8(<16 x i8> undef)<br>
+; V8M-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V32 = call i8 @llvm.vector.reduce.add.v32i8(<32 x i8> undef)<br>
+; V8M-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V64 = call i8 @llvm.vector.reduce.add.v64i8(<64 x i8> undef)<br>
+; V8M-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V128 = call i8 @llvm.vector.reduce.add.v128i8(<128 x i8> undef)<br>
; V8M-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret i32 undef<br>
;<br>
; NEON-SIZE-LABEL: 'reduce_i32'<br>
-; NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 16 for instruction: %V2 = call i8 @llvm.vector.reduce.add.v2i8(<2 x i8> undef)<br>
-; NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 53 for instruction: %V4 = call i8 @llvm.vector.reduce.add.v4i8(<4 x i8> undef)<br>
-; NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 150 for instruction: %V8 = call i8 @llvm.vector.reduce.add.v8i8(<8 x i8> undef)<br>
-; NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 391 for instruction: %V16 = call i8 @llvm.vector.reduce.add.v16i8(<16 x i8> undef)<br>
-; NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 488 for instruction: %V32 = call i8 @llvm.vector.reduce.add.v32i8(<32 x i8> undef)<br>
-; NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 681 for instruction: %V64 = call i8 @llvm.vector.reduce.add.v64i8(<64 x i8> undef)<br>
-; NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 1066 for instruction: %V128 = call i8 @llvm.vector.reduce.add.v128i8(<128 x i8> undef)<br>
+; NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V2 = call i8 @llvm.vector.reduce.add.v2i8(<2 x i8> undef)<br>
+; NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V4 = call i8 @llvm.vector.reduce.add.v4i8(<4 x i8> undef)<br>
+; NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V8 = call i8 @llvm.vector.reduce.add.v8i8(<8 x i8> undef)<br>
+; NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V16 = call i8 @llvm.vector.reduce.add.v16i8(<16 x i8> undef)<br>
+; NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V32 = call i8 @llvm.vector.reduce.add.v32i8(<32 x i8> undef)<br>
+; NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V64 = call i8 @llvm.vector.reduce.add.v64i8(<64 x i8> undef)<br>
+; NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V128 = call i8 @llvm.vector.reduce.add.v128i8(<128 x i8> undef)<br>
; NEON-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret i32 undef<br>
;<br>
%V2 = call i8 @llvm.vector.reduce.add.v2i8(<2 x i8> undef)<br>
<br>
diff --git a/llvm/test/Analysis/CostModel/X86/intrinsic-cost-kinds.ll b/llvm/test/Analysis/CostModel/X86/intrinsic-cost-kinds.ll<br>
index 1bedeb7c22d1..d3bf703513eb 100644<br>
--- a/llvm/test/Analysis/CostModel/X86/intrinsic-cost-kinds.ll<br>
+++ b/llvm/test/Analysis/CostModel/X86/intrinsic-cost-kinds.ll<br>
@@ -213,11 +213,11 @@ define void @reduce_fmax(<16 x float> %va) {<br>
; LATE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void<br>
;<br>
; SIZE-LABEL: 'reduce_fmax'<br>
-; SIZE-NEXT: Cost Model: Found an estimated cost of 7 for instruction: %v = call float @llvm.vector.reduce.fmax.v16f32(<16 x float> %va)<br>
+; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v = call float @llvm.vector.reduce.fmax.v16f32(<16 x float> %va)<br>
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void<br>
;<br>
; SIZE_LATE-LABEL: 'reduce_fmax'<br>
-; SIZE_LATE-NEXT: Cost Model: Found an estimated cost of 7 for instruction: %v = call float @llvm.vector.reduce.fmax.v16f32(<16 x float> %va)<br>
+; SIZE_LATE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v = call float @llvm.vector.reduce.fmax.v16f32(<16 x float> %va)<br>
; SIZE_LATE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void<br>
;<br>
%v = call float @llvm.vector.reduce.fmax.v16f32(<16 x float> %va)<br>
<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>