Skip to content

Commit 927f270

Browse files
committed
address comments
1 parent fe462ed commit 927f270

File tree

2 files changed

+152
-3
lines changed

2 files changed

+152
-3
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5948,6 +5948,32 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
59485948
Known.KnownFPClasses = fcNan;
59495949
else if (!APFloat(Ty->getFltSemantics(), ~Bits.Zero).isNaN())
59505950
Known.knownNot(fcNan);
5951+
5952+
// Build KnownBits representing Inf and check if it must be equal or
5953+
// unequal to this value.
5954+
auto InfKB = KnownBits::makeConstant(
5955+
APFloat::getInf(Ty->getFltSemantics(), false).bitcastToAPInt());
5956+
InfKB = InfKB.intersectWith(KnownBits::makeConstant(
5957+
APFloat::getInf(Ty->getFltSemantics(), true).bitcastToAPInt()));
5958+
if (const auto InfResult = KnownBits::eq(Bits, InfKB)) {
5959+
assert(!InfResult.value());
5960+
Known.knownNot(fcInf);
5961+
} else if (Bits == InfKB) {
5962+
Known.KnownFPClasses = fcInf;
5963+
}
5964+
5965+
// Build KnownBits representing Zero and check if it must be equal or
5966+
// unequal to this value.
5967+
auto ZeroKB = KnownBits::makeConstant(
5968+
APFloat::getZero(Ty->getFltSemantics(), false).bitcastToAPInt());
5969+
ZeroKB = ZeroKB.intersectWith(KnownBits::makeConstant(
5970+
APFloat::getZero(Ty->getFltSemantics(), true).bitcastToAPInt()));
5971+
if (const auto ZeroResult = KnownBits::eq(Bits, ZeroKB)) {
5972+
assert(!ZeroResult.value());
5973+
Known.knownNot(fcZero);
5974+
} else if (Bits == ZeroKB) {
5975+
Known.KnownFPClasses = fcZero;
5976+
}
59515977
}
59525978

59535979
break;

llvm/test/Transforms/Attributor/nofpclass.ll

Lines changed: 126 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2685,6 +2685,20 @@ define <vscale x 4 x float> @scalable_splat_zero() {
26852685
; See https://github.com/llvm/llvm-project/issues/78507
26862686

26872687
define double @call_abs(double noundef %__x) {
2688+
; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
2689+
; TUNIT-LABEL: define noundef nofpclass(ninf nzero nsub nnorm) double @call_abs
2690+
; TUNIT-SAME: (double noundef [[__X:%.*]]) #[[ATTR3]] {
2691+
; TUNIT-NEXT: entry:
2692+
; TUNIT-NEXT: [[ABS:%.*]] = tail call noundef nofpclass(ninf nzero nsub nnorm) double @llvm.fabs.f64(double noundef [[__X]]) #[[ATTR22]]
2693+
; TUNIT-NEXT: ret double [[ABS]]
2694+
;
2695+
; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
2696+
; CGSCC-LABEL: define noundef nofpclass(ninf nzero nsub nnorm) double @call_abs
2697+
; CGSCC-SAME: (double noundef [[__X:%.*]]) #[[ATTR3]] {
2698+
; CGSCC-NEXT: entry:
2699+
; CGSCC-NEXT: [[ABS:%.*]] = tail call noundef nofpclass(ninf nzero nsub nnorm) double @llvm.fabs.f64(double noundef [[__X]]) #[[ATTR19]]
2700+
; CGSCC-NEXT: ret double [[ABS]]
2701+
;
26882702
entry:
26892703
%abs = tail call double @llvm.fabs.f64(double %__x)
26902704
ret double %abs
@@ -2705,7 +2719,7 @@ define float @bitcast_to_float_sign_0(i32 %arg) {
27052719

27062720
define float @bitcast_to_float_nnan(i32 %arg) {
27072721
; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
2708-
; CHECK-LABEL: define nofpclass(nan ninf nzero nsub nnorm) float @bitcast_to_float_nnan
2722+
; CHECK-LABEL: define nofpclass(nan inf nzero nsub nnorm) float @bitcast_to_float_nnan
27092723
; CHECK-SAME: (i32 [[ARG:%.*]]) #[[ATTR3]] {
27102724
; CHECK-NEXT: [[SHR:%.*]] = lshr i32 [[ARG]], 2
27112725
; CHECK-NEXT: [[CAST:%.*]] = bitcast i32 [[SHR]] to float
@@ -2742,6 +2756,47 @@ define float @bitcast_to_float_nan(i32 %arg) {
27422756
ret float %cast
27432757
}
27442758

2759+
define float @bitcast_to_float_zero(i32 %arg) {
2760+
; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
2761+
; CHECK-LABEL: define nofpclass(nan inf sub norm) float @bitcast_to_float_zero
2762+
; CHECK-SAME: (i32 [[ARG:%.*]]) #[[ATTR3]] {
2763+
; CHECK-NEXT: [[SHL:%.*]] = shl i32 [[ARG]], 31
2764+
; CHECK-NEXT: [[CAST:%.*]] = bitcast i32 [[SHL]] to float
2765+
; CHECK-NEXT: ret float [[CAST]]
2766+
;
2767+
%shl = shl i32 %arg, 31
2768+
%cast = bitcast i32 %shl to float
2769+
ret float %cast
2770+
}
2771+
2772+
define float @bitcast_to_float_nzero(i32 %arg) {
2773+
; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
2774+
; CHECK-LABEL: define nofpclass(zero) float @bitcast_to_float_nzero
2775+
; CHECK-SAME: (i32 [[ARG:%.*]]) #[[ATTR3]] {
2776+
; CHECK-NEXT: [[OR:%.*]] = or i32 [[ARG]], 134217728
2777+
; CHECK-NEXT: [[CAST:%.*]] = bitcast i32 [[OR]] to float
2778+
; CHECK-NEXT: ret float [[CAST]]
2779+
;
2780+
%or = or i32 %arg, 134217728
2781+
%cast = bitcast i32 %or to float
2782+
ret float %cast
2783+
}
2784+
2785+
define float @bitcast_to_float_inf(i32 %arg) {
2786+
; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
2787+
; CHECK-LABEL: define nofpclass(nan zero sub norm) float @bitcast_to_float_inf
2788+
; CHECK-SAME: (i32 [[ARG:%.*]]) #[[ATTR3]] {
2789+
; CHECK-NEXT: [[SHR:%.*]] = shl i32 [[ARG]], 31
2790+
; CHECK-NEXT: [[OR:%.*]] = or i32 [[SHR]], 2139095040
2791+
; CHECK-NEXT: [[CAST:%.*]] = bitcast i32 [[OR]] to float
2792+
; CHECK-NEXT: ret float [[CAST]]
2793+
;
2794+
%shr = shl i32 %arg, 31
2795+
%or = or i32 %shr, 2139095040
2796+
%cast = bitcast i32 %or to float
2797+
ret float %cast
2798+
}
2799+
27452800
define double @bitcast_to_double_sign_0(i64 %arg) {
27462801
; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
27472802
; CHECK-LABEL: define nofpclass(ninf nzero nsub nnorm) double @bitcast_to_double_sign_0
@@ -2757,7 +2812,7 @@ define double @bitcast_to_double_sign_0(i64 %arg) {
27572812

27582813
define double @bitcast_to_double_nnan(i64 %arg) {
27592814
; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
2760-
; CHECK-LABEL: define nofpclass(nan ninf nzero nsub nnorm) double @bitcast_to_double_nnan
2815+
; CHECK-LABEL: define nofpclass(nan inf nzero nsub nnorm) double @bitcast_to_double_nnan
27612816
; CHECK-SAME: (i64 [[ARG:%.*]]) #[[ATTR3]] {
27622817
; CHECK-NEXT: [[SHR:%.*]] = lshr i64 [[ARG]], 2
27632818
; CHECK-NEXT: [[CAST:%.*]] = bitcast i64 [[SHR]] to double
@@ -2795,6 +2850,48 @@ define double @bitcast_to_double_nan(i64 %arg) {
27952850
}
27962851

27972852

2853+
define double @bitcast_to_double_zero(i64 %arg) {
2854+
; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
2855+
; CHECK-LABEL: define nofpclass(nan inf sub norm) double @bitcast_to_double_zero
2856+
; CHECK-SAME: (i64 [[ARG:%.*]]) #[[ATTR3]] {
2857+
; CHECK-NEXT: [[SHL:%.*]] = shl i64 [[ARG]], 63
2858+
; CHECK-NEXT: [[CAST:%.*]] = bitcast i64 [[SHL]] to double
2859+
; CHECK-NEXT: ret double [[CAST]]
2860+
;
2861+
%shl = shl i64 %arg, 63
2862+
%cast = bitcast i64 %shl to double
2863+
ret double %cast
2864+
}
2865+
2866+
define double @bitcast_to_double_nzero(i64 %arg) {
2867+
; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
2868+
; CHECK-LABEL: define nofpclass(zero) double @bitcast_to_double_nzero
2869+
; CHECK-SAME: (i64 [[ARG:%.*]]) #[[ATTR3]] {
2870+
; CHECK-NEXT: [[OR:%.*]] = or i64 [[ARG]], 1152921504606846976
2871+
; CHECK-NEXT: [[CAST:%.*]] = bitcast i64 [[OR]] to double
2872+
; CHECK-NEXT: ret double [[CAST]]
2873+
;
2874+
%or = or i64 %arg, 1152921504606846976
2875+
%cast = bitcast i64 %or to double
2876+
ret double %cast
2877+
}
2878+
2879+
define double @bitcast_to_double_inf(i64 %arg) {
2880+
; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
2881+
; CHECK-LABEL: define nofpclass(nan zero sub norm) double @bitcast_to_double_inf
2882+
; CHECK-SAME: (i64 [[ARG:%.*]]) #[[ATTR3]] {
2883+
; CHECK-NEXT: [[SHR:%.*]] = shl i64 [[ARG]], 63
2884+
; CHECK-NEXT: [[OR:%.*]] = or i64 [[SHR]], 9218868437227405312
2885+
; CHECK-NEXT: [[CAST:%.*]] = bitcast i64 [[OR]] to double
2886+
; CHECK-NEXT: ret double [[CAST]]
2887+
;
2888+
%shr = shl i64 %arg, 63
2889+
%or = or i64 %shr, 9218868437227405312
2890+
%cast = bitcast i64 %or to double
2891+
ret double %cast
2892+
}
2893+
2894+
27982895
define <2 x float> @bitcast_to_float_vect_sign_0(<2 x i32> %arg) {
27992896
; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
28002897
; CHECK-LABEL: define nofpclass(ninf nzero nsub nnorm) <2 x float> @bitcast_to_float_vect_sign_0
@@ -2810,7 +2907,7 @@ define <2 x float> @bitcast_to_float_vect_sign_0(<2 x i32> %arg) {
28102907

28112908
define <2 x float> @bitcast_to_float_vect_nnan(<2 x i32> %arg) {
28122909
; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
2813-
; CHECK-LABEL: define nofpclass(nan ninf nzero nsub nnorm) <2 x float> @bitcast_to_float_vect_nnan
2910+
; CHECK-LABEL: define nofpclass(nan inf nzero nsub nnorm) <2 x float> @bitcast_to_float_vect_nnan
28142911
; CHECK-SAME: (<2 x i32> [[ARG:%.*]]) #[[ATTR3]] {
28152912
; CHECK-NEXT: [[SHR:%.*]] = lshr <2 x i32> [[ARG]], <i32 4, i32 4>
28162913
; CHECK-NEXT: [[CAST:%.*]] = bitcast <2 x i32> [[SHR]] to <2 x float>
@@ -2847,6 +2944,32 @@ define <2 x float> @bitcast_to_float_vect_nan(<2 x i32> %arg) {
28472944
ret <2 x float> %cast
28482945
}
28492946

2947+
define <2 x float> @bitcast_to_float_vect_conservative_1(<2 x i32> %arg) {
2948+
; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
2949+
; CHECK-LABEL: define <2 x float> @bitcast_to_float_vect_conservative_1
2950+
; CHECK-SAME: (<2 x i32> [[ARG:%.*]]) #[[ATTR3]] {
2951+
; CHECK-NEXT: [[OR:%.*]] = or <2 x i32> [[ARG]], <i32 -2147483648, i32 0>
2952+
; CHECK-NEXT: [[CAST:%.*]] = bitcast <2 x i32> [[OR]] to <2 x float>
2953+
; CHECK-NEXT: ret <2 x float> [[CAST]]
2954+
;
2955+
%or = or <2 x i32> %arg, <i32 -2147483648, i32 0>
2956+
%cast = bitcast <2 x i32> %or to <2 x float>
2957+
ret <2 x float> %cast
2958+
}
2959+
2960+
define <2 x float> @bitcast_to_float_vect_conservative_2(<2 x i32> %arg) {
2961+
; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
2962+
; CHECK-LABEL: define <2 x float> @bitcast_to_float_vect_conservative_2
2963+
; CHECK-SAME: (<2 x i32> [[ARG:%.*]]) #[[ATTR3]] {
2964+
; CHECK-NEXT: [[OR:%.*]] = or <2 x i32> [[ARG]], <i32 0, i32 2139095041>
2965+
; CHECK-NEXT: [[CAST:%.*]] = bitcast <2 x i32> [[OR]] to <2 x float>
2966+
; CHECK-NEXT: ret <2 x float> [[CAST]]
2967+
;
2968+
%or = or <2 x i32> %arg, <i32 0, i32 2139095041>
2969+
%cast = bitcast <2 x i32> %or to <2 x float>
2970+
ret <2 x float> %cast
2971+
}
2972+
28502973
declare i64 @_Z13get_global_idj(i32 noundef)
28512974

28522975
attributes #0 = { "denormal-fp-math"="preserve-sign,preserve-sign" }

0 commit comments

Comments
 (0)