Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1684,12 +1684,12 @@ static Type *getMinimumFPType(Value *V, bool PreferBFloat) {
if (Type *T = shrinkFPConstant(CFP, PreferBFloat))
return T;

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

// Try to shrink a vector of FP constants. This returns nullptr on scalable
// vectors
Expand Down
11 changes: 11 additions & 0 deletions llvm/test/Transforms/InstCombine/fpextend.ll
Original file line number Diff line number Diff line change
Expand Up @@ -448,3 +448,14 @@ define bfloat @bf16_frem(bfloat %x) {
%t3 = fptrunc float %t2 to bfloat
ret bfloat %t3
}

define <4 x float> @v4f32_fadd(<4 x float> %a) {
; CHECK-LABEL: @v4f32_fadd(
; CHECK-NEXT: [[TMP1:%.*]] = fadd <4 x float> [[A:%.*]], splat (float -1.000000e+00)
; CHECK-NEXT: ret <4 x float> [[TMP1]]
;
%2 = fpext <4 x float> %a to <4 x double>
%4 = fadd <4 x double> %2, splat (double -1.000000e+00)
%5 = fptrunc <4 x double> %4 to <4 x float>
ret <4 x float> %5
}
13 changes: 13 additions & 0 deletions llvm/test/Transforms/InstCombine/scalable-const-fp-splat.ll
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,16 @@ define <vscale x 2 x float> @shrink_splat_scalable_extend(<vscale x 2 x float> %
%5 = fptrunc <vscale x 2 x double> %4 to <vscale x 2 x float>
ret <vscale x 2 x float> %5
}

define <vscale x 2 x float> @shrink_splat_scalable_extend_rhs_constexpr(<vscale x 2 x float> %a) {
; CHECK-LABEL: define <vscale x 2 x float> @shrink_splat_scalable_extend_rhs_constexpr(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to have a fixed-width variant of this too, if there isn't one already?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to fpextend.ll in d26e672

; CHECK-SAME: <vscale x 2 x float> [[A:%.*]]) {
; CHECK-NEXT: [[TMP1:%.*]] = fptrunc <vscale x 2 x double> splat (double -1.000000e+00) to <vscale x 2 x float>
; CHECK-NEXT: [[TMP3:%.*]] = fadd <vscale x 2 x float> [[A]], [[TMP1]]
; CHECK-NEXT: ret <vscale x 2 x float> [[TMP3]]
;
%2 = fpext <vscale x 2 x float> %a to <vscale x 2 x double>
%4 = fadd <vscale x 2 x double> %2, splat (double -1.000000e+00)
%5 = fptrunc <vscale x 2 x double> %4 to <vscale x 2 x float>
ret <vscale x 2 x float> %5
}