Skip to content

Commit 7b9168c

Browse files
authored
ValueTracking: Handle amdgcn_exp2 in computeKnownFPClass (#172495)
1 parent 82cdc30 commit 7b9168c

File tree

2 files changed

+31
-25
lines changed

2 files changed

+31
-25
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5374,8 +5374,14 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
53745374
}
53755375
case Intrinsic::exp:
53765376
case Intrinsic::exp2:
5377-
case Intrinsic::exp10: {
5377+
case Intrinsic::exp10:
5378+
case Intrinsic::amdgcn_exp2: {
53785379
Known.knownNot(fcNegative);
5380+
5381+
Type *EltTy = II->getType()->getScalarType();
5382+
if (IID == Intrinsic::amdgcn_exp2 && EltTy->isFloatTy())
5383+
Known.knownNot(fcSubnormal);
5384+
53795385
if ((InterestedClasses & fcNan) == fcNone)
53805386
break;
53815387

llvm/test/Transforms/Attributor/AMDGPU/nofpclass-amdgcn-exp.ll

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,110 +4,110 @@
44
declare float @llvm.amdgcn.exp2.f32(float)
55

66
define half @ret_exp_f16(half %arg0) {
7-
; CHECK-LABEL: define half @ret_exp_f16(
7+
; CHECK-LABEL: define nofpclass(ninf nzero nsub nnorm) half @ret_exp_f16(
88
; CHECK-SAME: half [[ARG0:%.*]]) #[[ATTR1:[0-9]+]] {
9-
; CHECK-NEXT: [[CALL:%.*]] = call half @llvm.amdgcn.exp2.f16(half [[ARG0]]) #[[ATTR2:[0-9]+]]
9+
; CHECK-NEXT: [[CALL:%.*]] = call nofpclass(ninf nzero nsub nnorm) half @llvm.amdgcn.exp2.f16(half [[ARG0]]) #[[ATTR2:[0-9]+]]
1010
; CHECK-NEXT: ret half [[CALL]]
1111
;
1212
%call = call half @llvm.amdgcn.exp2.f16(half %arg0)
1313
ret half %call
1414
}
1515

1616
define float @ret_exp_f32(float %arg0) {
17-
; CHECK-LABEL: define float @ret_exp_f32(
17+
; CHECK-LABEL: define nofpclass(ninf nzero sub nnorm) float @ret_exp_f32(
1818
; CHECK-SAME: float [[ARG0:%.*]]) #[[ATTR1]] {
19-
; CHECK-NEXT: [[CALL:%.*]] = call float @llvm.amdgcn.exp2.f32(float [[ARG0]]) #[[ATTR2]]
19+
; CHECK-NEXT: [[CALL:%.*]] = call nofpclass(ninf nzero sub nnorm) float @llvm.amdgcn.exp2.f32(float [[ARG0]]) #[[ATTR2]]
2020
; CHECK-NEXT: ret float [[CALL]]
2121
;
2222
%call = call float @llvm.amdgcn.exp2.f32(float %arg0)
2323
ret float %call
2424
}
2525

2626
define float @ret_exp_noinf(float nofpclass(inf) %arg0) {
27-
; CHECK-LABEL: define float @ret_exp_noinf(
27+
; CHECK-LABEL: define nofpclass(ninf nzero sub nnorm) float @ret_exp_noinf(
2828
; CHECK-SAME: float nofpclass(inf) [[ARG0:%.*]]) #[[ATTR1]] {
29-
; CHECK-NEXT: [[CALL:%.*]] = call float @llvm.amdgcn.exp2.f32(float nofpclass(inf) [[ARG0]]) #[[ATTR2]]
29+
; CHECK-NEXT: [[CALL:%.*]] = call nofpclass(ninf nzero sub nnorm) float @llvm.amdgcn.exp2.f32(float nofpclass(inf) [[ARG0]]) #[[ATTR2]]
3030
; CHECK-NEXT: ret float [[CALL]]
3131
;
3232
%call = call float @llvm.amdgcn.exp2.f32(float %arg0)
3333
ret float %call
3434
}
3535

3636
define float @ret_exp_nopinf(float nofpclass(pinf) %arg0) {
37-
; CHECK-LABEL: define float @ret_exp_nopinf(
37+
; CHECK-LABEL: define nofpclass(ninf nzero sub nnorm) float @ret_exp_nopinf(
3838
; CHECK-SAME: float nofpclass(pinf) [[ARG0:%.*]]) #[[ATTR1]] {
39-
; CHECK-NEXT: [[CALL:%.*]] = call float @llvm.amdgcn.exp2.f32(float nofpclass(pinf) [[ARG0]]) #[[ATTR2]]
39+
; CHECK-NEXT: [[CALL:%.*]] = call nofpclass(ninf nzero sub nnorm) float @llvm.amdgcn.exp2.f32(float nofpclass(pinf) [[ARG0]]) #[[ATTR2]]
4040
; CHECK-NEXT: ret float [[CALL]]
4141
;
4242
%call = call float @llvm.amdgcn.exp2.f32(float %arg0)
4343
ret float %call
4444
}
4545

4646
define float @ret_exp_noninf(float nofpclass(ninf) %arg0) {
47-
; CHECK-LABEL: define float @ret_exp_noninf(
47+
; CHECK-LABEL: define nofpclass(ninf nzero sub nnorm) float @ret_exp_noninf(
4848
; CHECK-SAME: float nofpclass(ninf) [[ARG0:%.*]]) #[[ATTR1]] {
49-
; CHECK-NEXT: [[CALL:%.*]] = call float @llvm.amdgcn.exp2.f32(float nofpclass(ninf) [[ARG0]]) #[[ATTR2]]
49+
; CHECK-NEXT: [[CALL:%.*]] = call nofpclass(ninf nzero sub nnorm) float @llvm.amdgcn.exp2.f32(float nofpclass(ninf) [[ARG0]]) #[[ATTR2]]
5050
; CHECK-NEXT: ret float [[CALL]]
5151
;
5252
%call = call float @llvm.amdgcn.exp2.f32(float %arg0)
5353
ret float %call
5454
}
5555

5656
define float @ret_exp_nonan(float nofpclass(nan) %arg0) {
57-
; CHECK-LABEL: define float @ret_exp_nonan(
57+
; CHECK-LABEL: define nofpclass(nan ninf nzero sub nnorm) float @ret_exp_nonan(
5858
; CHECK-SAME: float nofpclass(nan) [[ARG0:%.*]]) #[[ATTR1]] {
59-
; CHECK-NEXT: [[CALL:%.*]] = call float @llvm.amdgcn.exp2.f32(float nofpclass(nan) [[ARG0]]) #[[ATTR2]]
59+
; CHECK-NEXT: [[CALL:%.*]] = call nofpclass(nan ninf nzero sub nnorm) float @llvm.amdgcn.exp2.f32(float nofpclass(nan) [[ARG0]]) #[[ATTR2]]
6060
; CHECK-NEXT: ret float [[CALL]]
6161
;
6262
%call = call float @llvm.amdgcn.exp2.f32(float %arg0)
6363
ret float %call
6464
}
6565

6666
define float @ret_exp_nonan_noinf(float nofpclass(nan inf) %arg0) {
67-
; CHECK-LABEL: define float @ret_exp_nonan_noinf(
67+
; CHECK-LABEL: define nofpclass(nan ninf nzero sub nnorm) float @ret_exp_nonan_noinf(
6868
; CHECK-SAME: float nofpclass(nan inf) [[ARG0:%.*]]) #[[ATTR1]] {
69-
; CHECK-NEXT: [[CALL:%.*]] = call float @llvm.amdgcn.exp2.f32(float nofpclass(nan inf) [[ARG0]]) #[[ATTR2]]
69+
; CHECK-NEXT: [[CALL:%.*]] = call nofpclass(nan ninf nzero sub nnorm) float @llvm.amdgcn.exp2.f32(float nofpclass(nan inf) [[ARG0]]) #[[ATTR2]]
7070
; CHECK-NEXT: ret float [[CALL]]
7171
;
7272
%call = call float @llvm.amdgcn.exp2.f32(float %arg0)
7373
ret float %call
7474
}
7575

7676
define float @ret_exp_nonan_noinf_nozero(float nofpclass(nan inf zero) %arg0) {
77-
; CHECK-LABEL: define float @ret_exp_nonan_noinf_nozero(
77+
; CHECK-LABEL: define nofpclass(nan ninf nzero sub nnorm) float @ret_exp_nonan_noinf_nozero(
7878
; CHECK-SAME: float nofpclass(nan inf zero) [[ARG0:%.*]]) #[[ATTR1]] {
79-
; CHECK-NEXT: [[CALL:%.*]] = call float @llvm.amdgcn.exp2.f32(float nofpclass(nan inf zero) [[ARG0]]) #[[ATTR2]]
79+
; CHECK-NEXT: [[CALL:%.*]] = call nofpclass(nan ninf nzero sub nnorm) float @llvm.amdgcn.exp2.f32(float nofpclass(nan inf zero) [[ARG0]]) #[[ATTR2]]
8080
; CHECK-NEXT: ret float [[CALL]]
8181
;
8282
%call = call float @llvm.amdgcn.exp2.f32(float %arg0)
8383
ret float %call
8484
}
8585

8686
define float @ret_exp_noinf_nozero(float nofpclass(inf zero) %arg0) {
87-
; CHECK-LABEL: define float @ret_exp_noinf_nozero(
87+
; CHECK-LABEL: define nofpclass(ninf nzero sub nnorm) float @ret_exp_noinf_nozero(
8888
; CHECK-SAME: float nofpclass(inf zero) [[ARG0:%.*]]) #[[ATTR1]] {
89-
; CHECK-NEXT: [[CALL:%.*]] = call float @llvm.amdgcn.exp2.f32(float nofpclass(inf zero) [[ARG0]]) #[[ATTR2]]
89+
; CHECK-NEXT: [[CALL:%.*]] = call nofpclass(ninf nzero sub nnorm) float @llvm.amdgcn.exp2.f32(float nofpclass(inf zero) [[ARG0]]) #[[ATTR2]]
9090
; CHECK-NEXT: ret float [[CALL]]
9191
;
9292
%call = call float @llvm.amdgcn.exp2.f32(float %arg0)
9393
ret float %call
9494
}
9595

9696
define float @ret_exp_noinf_nonegzero(float nofpclass(inf nzero) %arg0) {
97-
; CHECK-LABEL: define float @ret_exp_noinf_nonegzero(
97+
; CHECK-LABEL: define nofpclass(ninf nzero sub nnorm) float @ret_exp_noinf_nonegzero(
9898
; CHECK-SAME: float nofpclass(inf nzero) [[ARG0:%.*]]) #[[ATTR1]] {
99-
; CHECK-NEXT: [[CALL:%.*]] = call float @llvm.amdgcn.exp2.f32(float nofpclass(inf nzero) [[ARG0]]) #[[ATTR2]]
99+
; CHECK-NEXT: [[CALL:%.*]] = call nofpclass(ninf nzero sub nnorm) float @llvm.amdgcn.exp2.f32(float nofpclass(inf nzero) [[ARG0]]) #[[ATTR2]]
100100
; CHECK-NEXT: ret float [[CALL]]
101101
;
102102
%call = call float @llvm.amdgcn.exp2.f32(float %arg0)
103103
ret float %call
104104
}
105105

106106
define float @ret_exp_positive_source(i32 %arg) {
107-
; CHECK-LABEL: define float @ret_exp_positive_source(
107+
; CHECK-LABEL: define nofpclass(nan ninf nzero sub nnorm) float @ret_exp_positive_source(
108108
; CHECK-SAME: i32 [[ARG:%.*]]) #[[ATTR1]] {
109109
; CHECK-NEXT: [[UITOFP:%.*]] = uitofp i32 [[ARG]] to float
110-
; CHECK-NEXT: [[CALL:%.*]] = call float @llvm.amdgcn.exp2.f32(float [[UITOFP]]) #[[ATTR2]]
110+
; CHECK-NEXT: [[CALL:%.*]] = call nofpclass(nan ninf nzero sub nnorm) float @llvm.amdgcn.exp2.f32(float [[UITOFP]]) #[[ATTR2]]
111111
; CHECK-NEXT: ret float [[CALL]]
112112
;
113113
%uitofp = uitofp i32 %arg to float
@@ -117,10 +117,10 @@ define float @ret_exp_positive_source(i32 %arg) {
117117

118118
; Could produce a nan because we don't know if the multiply is negative.
119119
define float @ret_exp_unknown_sign(float nofpclass(nan) %arg0, float nofpclass(nan) %arg1) {
120-
; CHECK-LABEL: define float @ret_exp_unknown_sign(
120+
; CHECK-LABEL: define nofpclass(nan ninf nzero sub nnorm) float @ret_exp_unknown_sign(
121121
; CHECK-SAME: float nofpclass(nan) [[ARG0:%.*]], float nofpclass(nan) [[ARG1:%.*]]) #[[ATTR1]] {
122122
; CHECK-NEXT: [[UNKNOWN_SIGN_NOT_NAN:%.*]] = fmul nnan float [[ARG0]], [[ARG1]]
123-
; CHECK-NEXT: [[CALL:%.*]] = call float @llvm.amdgcn.exp2.f32(float [[UNKNOWN_SIGN_NOT_NAN]]) #[[ATTR2]]
123+
; CHECK-NEXT: [[CALL:%.*]] = call nofpclass(nan ninf nzero sub nnorm) float @llvm.amdgcn.exp2.f32(float [[UNKNOWN_SIGN_NOT_NAN]]) #[[ATTR2]]
124124
; CHECK-NEXT: ret float [[CALL]]
125125
;
126126
%unknown.sign.not.nan = fmul nnan float %arg0, %arg1

0 commit comments

Comments
 (0)