llvm-project/llvm/test/Transforms/InstCombine/scalable-const-fp-splat.ll
Luke Lau 79435de8a5
[ConstantFold] Support scalable constant splats in ConstantFoldCastInstruction (#133207)
Previously only fixed vector splats were handled. This adds supports for
scalable vectors too by allowing ConstantExpr splats.

We need to add the extra V->getType()->isVectorTy() check because a
ConstantExpr might be a scalar to vector bitcast.

By allowing ConstantExprs this also allow fixed vector ConstantExprs to
be folded, which causes the diffs in
llvm/test/Analysis/ValueTracking/known-bits-from-operator-constexpr.ll
and llvm/test/Transforms/InstSimplify/ConstProp/cast-vector.ll. I can
remove them from this PR if reviewers would prefer.

Fixes #132922
2025-04-03 16:24:56 +01:00

28 lines
1.4 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
; RUN: opt -passes=instcombine -S -o - < %s | FileCheck %s
define <vscale x 2 x float> @shrink_splat_scalable_extend(<vscale x 2 x float> %a) {
; CHECK-LABEL: define <vscale x 2 x float> @shrink_splat_scalable_extend(
; CHECK-SAME: <vscale x 2 x float> [[A:%.*]]) {
; CHECK-NEXT: [[TMP1:%.*]] = fadd <vscale x 2 x float> [[A]], splat (float -1.000000e+00)
; CHECK-NEXT: ret <vscale x 2 x float> [[TMP1]]
;
%2 = fpext <vscale x 2 x float> %a to <vscale x 2 x double>
%3 = fpext <vscale x 2 x float> splat (float -1.000000e+00) to <vscale x 2 x double>
%4 = fadd <vscale x 2 x double> %2, %3
%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(
; CHECK-SAME: <vscale x 2 x float> [[A:%.*]]) {
; CHECK-NEXT: [[TMP3:%.*]] = fadd <vscale x 2 x float> [[A]], splat (float -1.000000e+00)
; 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
}