Skip to content

Commit 27a4371

Browse files
authored
[InstCombine] Handle scalable splats of constants in getMinimumFPType (#132960)
We previously handled ConstantExpr scalable splats in 5d92979, but only fpexts. ConstantExpr fpexts have since been removed, and simultaneously we didn't handle splats of constants that weren't extended. This updates it to remove the fpext check and instead see if we can shrink the result of getSplatValue. Note that the test case doesn't get completely folded away due to #132922
1 parent 8fdfe3f commit 27a4371

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,12 +1684,12 @@ static Type *getMinimumFPType(Value *V, bool PreferBFloat) {
16841684
if (Type *T = shrinkFPConstant(CFP, PreferBFloat))
16851685
return T;
16861686

1687-
// We can only correctly find a minimum type for a scalable vector when it is
1688-
// a splat. For splats of constant values the fpext is wrapped up as a
1689-
// ConstantExpr.
1690-
if (auto *FPCExt = dyn_cast<ConstantExpr>(V))
1691-
if (FPCExt->getOpcode() == Instruction::FPExt)
1692-
return FPCExt->getOperand(0)->getType();
1687+
// Try to shrink scalable and fixed splat vectors.
1688+
if (auto *FPC = dyn_cast<Constant>(V))
1689+
if (isa<VectorType>(V->getType()))
1690+
if (auto *Splat = dyn_cast_or_null<ConstantFP>(FPC->getSplatValue()))
1691+
if (Type *T = shrinkFPConstant(Splat, PreferBFloat))
1692+
return T;
16931693

16941694
// Try to shrink a vector of FP constants. This returns nullptr on scalable
16951695
// vectors

llvm/test/Transforms/InstCombine/fpextend.ll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,3 +448,14 @@ define bfloat @bf16_frem(bfloat %x) {
448448
%t3 = fptrunc float %t2 to bfloat
449449
ret bfloat %t3
450450
}
451+
452+
define <4 x float> @v4f32_fadd(<4 x float> %a) {
453+
; CHECK-LABEL: @v4f32_fadd(
454+
; CHECK-NEXT: [[TMP1:%.*]] = fadd <4 x float> [[A:%.*]], splat (float -1.000000e+00)
455+
; CHECK-NEXT: ret <4 x float> [[TMP1]]
456+
;
457+
%2 = fpext <4 x float> %a to <4 x double>
458+
%4 = fadd <4 x double> %2, splat (double -1.000000e+00)
459+
%5 = fptrunc <4 x double> %4 to <4 x float>
460+
ret <4 x float> %5
461+
}

llvm/test/Transforms/InstCombine/scalable-const-fp-splat.ll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,16 @@ define <vscale x 2 x float> @shrink_splat_scalable_extend(<vscale x 2 x float> %
1313
%5 = fptrunc <vscale x 2 x double> %4 to <vscale x 2 x float>
1414
ret <vscale x 2 x float> %5
1515
}
16+
17+
define <vscale x 2 x float> @shrink_splat_scalable_extend_rhs_constexpr(<vscale x 2 x float> %a) {
18+
; CHECK-LABEL: define <vscale x 2 x float> @shrink_splat_scalable_extend_rhs_constexpr(
19+
; CHECK-SAME: <vscale x 2 x float> [[A:%.*]]) {
20+
; CHECK-NEXT: [[TMP1:%.*]] = fptrunc <vscale x 2 x double> splat (double -1.000000e+00) to <vscale x 2 x float>
21+
; CHECK-NEXT: [[TMP3:%.*]] = fadd <vscale x 2 x float> [[A]], [[TMP1]]
22+
; CHECK-NEXT: ret <vscale x 2 x float> [[TMP3]]
23+
;
24+
%2 = fpext <vscale x 2 x float> %a to <vscale x 2 x double>
25+
%4 = fadd <vscale x 2 x double> %2, splat (double -1.000000e+00)
26+
%5 = fptrunc <vscale x 2 x double> %4 to <vscale x 2 x float>
27+
ret <vscale x 2 x float> %5
28+
}

0 commit comments

Comments
 (0)