Skip to content

Commit 50a02e7

Browse files
committed
[VPlan] Pass intrinsic inst to TTI in VPWidenCallRecipe::computeCost.
Follow-up to 9ccf825, adjust computeCost to also pass IntrinsicInst to TTI if available, as there are multiple places in TTI which use the IntrinsicInst. Fixes #107016.
1 parent a586b5a commit 50a02e7

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -965,8 +965,10 @@ InstructionCost VPWidenCallRecipe::computeCost(ElementCount VF,
965965
ParamTys.push_back(
966966
ToVectorTy(Ctx.Types.inferScalarType(getOperand(I)), VF));
967967

968-
IntrinsicCostAttributes CostAttrs(VectorIntrinsicID, RetTy, Arguments,
969-
ParamTys, FMF);
968+
// TODO: Rework TTI interface to avoid reliance on underlying IntrinsicInst.
969+
IntrinsicCostAttributes CostAttrs(
970+
VectorIntrinsicID, RetTy, Arguments, ParamTys, FMF,
971+
dyn_cast_or_null<IntrinsicInst>(getUnderlyingValue()));
970972
return Ctx.TTI.getIntrinsicInstrCost(CostAttrs, CostKind);
971973
}
972974

llvm/test/Transforms/LoopVectorize/AArch64/call-costs.ll

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,65 @@ exit:
7474
ret void
7575
}
7676

77+
; Test case for https://github.com/llvm/llvm-project/issues/107016.
78+
define void @powi_call(ptr %P) {
79+
; CHECK-LABEL: define void @powi_call(
80+
; CHECK-SAME: ptr [[P:%.*]]) {
81+
; CHECK-NEXT: [[ENTRY:.*]]:
82+
; CHECK-NEXT: br i1 false, label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
83+
; CHECK: [[VECTOR_PH]]:
84+
; CHECK-NEXT: br label %[[VECTOR_BODY:.*]]
85+
; CHECK: [[VECTOR_BODY]]:
86+
; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
87+
; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[INDEX]], 0
88+
; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds double, ptr [[P]], i64 [[TMP0]]
89+
; CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds double, ptr [[TMP1]], i32 0
90+
; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <2 x double>, ptr [[TMP2]], align 8
91+
; CHECK-NEXT: [[TMP3:%.*]] = call <2 x double> @llvm.powi.v2f64.i32(<2 x double> [[WIDE_LOAD]], i32 3)
92+
; CHECK-NEXT: store <2 x double> [[TMP3]], ptr [[TMP2]], align 8
93+
; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
94+
; CHECK-NEXT: br i1 true, label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP4:![0-9]+]]
95+
; CHECK: [[MIDDLE_BLOCK]]:
96+
; CHECK-NEXT: br i1 true, label %[[EXIT:.*]], label %[[SCALAR_PH]]
97+
; CHECK: [[SCALAR_PH]]:
98+
; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ 2, %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ]
99+
; CHECK-NEXT: br label %[[LOOP:.*]]
100+
; CHECK: [[LOOP]]:
101+
; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]
102+
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds double, ptr [[P]], i64 [[IV]]
103+
; CHECK-NEXT: [[L:%.*]] = load double, ptr [[GEP]], align 8
104+
; CHECK-NEXT: [[POWI:%.*]] = tail call double @llvm.powi.f64.i32(double [[L]], i32 3)
105+
; CHECK-NEXT: store double [[POWI]], ptr [[GEP]], align 8
106+
; CHECK-NEXT: [[IV_NEXT]] = add i64 [[IV]], 1
107+
; CHECK-NEXT: [[EC:%.*]] = icmp eq i64 [[IV]], 1
108+
; CHECK-NEXT: br i1 [[EC]], label %[[EXIT]], label %[[LOOP]], !llvm.loop [[LOOP5:![0-9]+]]
109+
; CHECK: [[EXIT]]:
110+
; CHECK-NEXT: ret void
111+
;
112+
entry:
113+
br label %loop
114+
115+
loop:
116+
%iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
117+
%gep = getelementptr inbounds double, ptr %P, i64 %iv
118+
%l = load double, ptr %gep
119+
%powi = tail call double @llvm.powi.f64.i32(double %l, i32 3)
120+
store double %powi, ptr %gep, align 8
121+
%iv.next = add i64 %iv, 1
122+
%ec = icmp eq i64 %iv, 1
123+
br i1 %ec, label %exit, label %loop
124+
125+
exit:
126+
ret void
127+
}
128+
129+
declare double @llvm.powi.f64.i32(double, i32)
77130
declare i64 @llvm.fshl.i64(i64, i64, i64)
78131
;.
79132
; CHECK: [[LOOP0]] = distinct !{[[LOOP0]], [[META1:![0-9]+]], [[META2:![0-9]+]]}
80133
; CHECK: [[META1]] = !{!"llvm.loop.isvectorized", i32 1}
81134
; CHECK: [[META2]] = !{!"llvm.loop.unroll.runtime.disable"}
82135
; CHECK: [[LOOP3]] = distinct !{[[LOOP3]], [[META2]], [[META1]]}
136+
; CHECK: [[LOOP4]] = distinct !{[[LOOP4]], [[META1]], [[META2]]}
137+
; CHECK: [[LOOP5]] = distinct !{[[LOOP5]], [[META2]], [[META1]]}
83138
;.

0 commit comments

Comments
 (0)