Skip to content

Commit 01be82c

Browse files
committed
[InstCombine] Handle scalable splats of constants in getMinimumFPType
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 4b9c243 commit 01be82c

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,11 +1685,12 @@ static Type *getMinimumFPType(Value *V, bool PreferBFloat) {
16851685
return T;
16861686

16871687
// 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();
1688+
// a splat.
1689+
if (auto *FPCE = dyn_cast<ConstantExpr>(V))
1690+
if (isa<ScalableVectorType>(V->getType()))
1691+
if (auto *Splat = dyn_cast<ConstantFP>(FPCE->getSplatValue()))
1692+
if (Type *T = shrinkFPConstant(Splat, PreferBFloat))
1693+
return T;
16931694

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

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ define <vscale x 2 x float> @shrink_splat_scalable_extend(<vscale x 2 x float> %
1717
define <vscale x 2 x float> @shrink_splat_scalable_extend_rhs_constexpr(<vscale x 2 x float> %a) {
1818
; CHECK-LABEL: define <vscale x 2 x float> @shrink_splat_scalable_extend_rhs_constexpr(
1919
; CHECK-SAME: <vscale x 2 x float> [[A:%.*]]) {
20-
; CHECK-NEXT: [[TMP1:%.*]] = fpext <vscale x 2 x float> [[A]] to <vscale x 2 x double>
21-
; CHECK-NEXT: [[TMP2:%.*]] = fadd <vscale x 2 x double> [[TMP1]], splat (double -1.000000e+00)
22-
; CHECK-NEXT: [[TMP3:%.*]] = fptrunc <vscale x 2 x double> [[TMP2]] to <vscale x 2 x float>
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]]
2322
; CHECK-NEXT: ret <vscale x 2 x float> [[TMP3]]
2423
;
2524
%2 = fpext <vscale x 2 x float> %a to <vscale x 2 x double>

0 commit comments

Comments
 (0)