Skip to content

Commit e0f3302

Browse files
authored
[ValueTracking] Support scalable vector splats in computeKnownFPClass (#170325)
Address comment #169904 (comment)
1 parent ea00593 commit e0f3302

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5877,6 +5877,12 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
58775877
break;
58785878
}
58795879
case Instruction::ShuffleVector: {
5880+
// Handle vector splat idiom
5881+
if (Value *Splat = getSplatValue(V)) {
5882+
computeKnownFPClass(Splat, Known, InterestedClasses, Q, Depth + 1);
5883+
break;
5884+
}
5885+
58805886
// For undef elements, we don't know anything about the common state of
58815887
// the shuffle result.
58825888
APInt DemandedLHS, DemandedRHS;

llvm/test/Transforms/Attributor/nofpclass.ll

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2667,15 +2667,10 @@ define [4 x float] @constant_aggregate_zero() {
26672667
}
26682668

26692669
define <vscale x 4 x float> @scalable_splat_pnorm() {
2670-
; CHECK-CV: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
2671-
; CHECK-CV-LABEL: define noundef <vscale x 4 x float> @scalable_splat_pnorm
2672-
; CHECK-CV-SAME: () #[[ATTR3]] {
2673-
; CHECK-CV-NEXT: ret <vscale x 4 x float> splat (float 1.000000e+00)
2674-
;
2675-
; CHECK-CI: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
2676-
; CHECK-CI-LABEL: define noundef nofpclass(nan inf zero sub nnorm) <vscale x 4 x float> @scalable_splat_pnorm
2677-
; CHECK-CI-SAME: () #[[ATTR3]] {
2678-
; CHECK-CI-NEXT: ret <vscale x 4 x float> splat (float 1.000000e+00)
2670+
; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
2671+
; CHECK-LABEL: define noundef nofpclass(nan inf zero sub nnorm) <vscale x 4 x float> @scalable_splat_pnorm
2672+
; CHECK-SAME: () #[[ATTR3]] {
2673+
; CHECK-NEXT: ret <vscale x 4 x float> splat (float 1.000000e+00)
26792674
;
26802675
ret <vscale x 4 x float> splat (float 1.0)
26812676
}
@@ -2689,6 +2684,19 @@ define <vscale x 4 x float> @scalable_splat_zero() {
26892684
ret <vscale x 4 x float> zeroinitializer
26902685
}
26912686

2687+
define <vscale x 4 x float> @scalable_splat_nnan(float nofpclass(nan) %x) {
2688+
; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
2689+
; CHECK-LABEL: define nofpclass(nan) <vscale x 4 x float> @scalable_splat_nnan
2690+
; CHECK-SAME: (float nofpclass(nan) [[X:%.*]]) #[[ATTR3]] {
2691+
; CHECK-NEXT: [[HEAD:%.*]] = insertelement <vscale x 4 x float> poison, float [[X]], i32 0
2692+
; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <vscale x 4 x float> [[HEAD]], <vscale x 4 x float> poison, <vscale x 4 x i32> zeroinitializer
2693+
; CHECK-NEXT: ret <vscale x 4 x float> [[SPLAT]]
2694+
;
2695+
%head = insertelement <vscale x 4 x float> poison, float %x, i32 0
2696+
%splat = shufflevector <vscale x 4 x float> %head, <vscale x 4 x float> poison, <vscale x 4 x i32> zeroinitializer
2697+
ret <vscale x 4 x float> %splat
2698+
}
2699+
26922700
; Verify we do not derive 'nofpclass(inf zero sub norm)' for the argument __x.
26932701
; See https://github.com/llvm/llvm-project/issues/78507
26942702

@@ -2989,5 +2997,7 @@ attributes #5 = { "denormal-fp-math"="ieee,positive-zero" }
29892997
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
29902998
; CGSCC-CI: {{.*}}
29912999
; CGSCC-CV: {{.*}}
3000+
; CHECK-CI: {{.*}}
3001+
; CHECK-CV: {{.*}}
29923002
; TUNIT-CI: {{.*}}
29933003
; TUNIT-CV: {{.*}}

0 commit comments

Comments
 (0)