-
Notifications
You must be signed in to change notification settings - Fork 15.7k
InstCombine: Reorder exp's known-nan source handling #174417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
InstCombine: Reorder exp's known-nan source handling #174417
Conversation
In SimplifyDemandedFPClass, reorder the known-nan source handling above The known-zero-or-nan handling. The more specific cases need to be handled first. Avoids spurious diff in an upcoming patch for fadd support; this would introduce a simplifiable fadd when we can just go directly to the end result.
|
@llvm/pr-subscribers-llvm-transforms Author: Matt Arsenault (arsenm) ChangesIn SimplifyDemandedFPClass, reorder the known-nan source Full diff: https://github.com/llvm/llvm-project/pull/174417.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
index 7bc1070613acd..fe910ee32b56a 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
@@ -2182,6 +2182,11 @@ Value *InstCombinerImpl::SimplifyDemandedUseFPClass(Value *V,
if (KnownSrc.isKnownAlways(fcZero))
return ConstantFP::get(VTy, 1.0);
+ // Only perform nan propagation.
+ // Note: Dropping canonicalize / quiet of signaling nan.
+ if (KnownSrc.isKnownAlways(fcNan))
+ return CI->getArgOperand(0);
+
// exp(0 | nan) => x == 0.0 ? 1.0 : x
if (KnownSrc.isKnownAlways(fcZero | fcNan)) {
IRBuilderBase::InsertPointGuard Guard(Builder);
@@ -2210,11 +2215,6 @@ Value *InstCombinerImpl::SimplifyDemandedUseFPClass(Value *V,
return ZeroOrInf;
}
- // Only perform nan propagation.
- // Note: Dropping canonicalize / quiet of signaling nan.
- if (KnownSrc.isKnownAlways(fcNan))
- return CI->getArgOperand(0);
-
Known = KnownFPClass::exp(KnownSrc);
break;
}
diff --git a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll
index 8a2ad8ba31d32..d0dff08d0e6d8 100644
--- a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll
+++ b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll
@@ -410,8 +410,7 @@ define nofpclass(nzero) float @source_is_known_ninf(float nofpclass(pinf nan nor
define nofpclass(nzero) float @source_is_known_nan(float nofpclass(inf norm sub zero) %must.be.nan) {
; CHECK-LABEL: define nofpclass(nzero) float @source_is_known_nan(
; CHECK-SAME: float nofpclass(inf zero sub norm) [[MUST_BE_NAN:%.*]]) {
-; CHECK-NEXT: [[TMP1:%.*]] = fadd float [[MUST_BE_NAN]], 1.000000e+00
-; CHECK-NEXT: ret float [[TMP1]]
+; CHECK-NEXT: ret float [[MUST_BE_NAN]]
;
%exp = call float @llvm.exp2.f32(float %must.be.nan)
ret float %exp
@@ -420,8 +419,7 @@ define nofpclass(nzero) float @source_is_known_nan(float nofpclass(inf norm sub
define nofpclass(nzero) float @source_is_known_nan_preserve_flags(float nofpclass(inf norm sub zero) %must.be.nan) {
; CHECK-LABEL: define nofpclass(nzero) float @source_is_known_nan_preserve_flags(
; CHECK-SAME: float nofpclass(inf zero sub norm) [[MUST_BE_NAN:%.*]]) {
-; CHECK-NEXT: [[TMP1:%.*]] = fadd nsz contract float [[MUST_BE_NAN]], 1.000000e+00
-; CHECK-NEXT: ret float [[TMP1]]
+; CHECK-NEXT: ret float [[MUST_BE_NAN]]
;
%exp = call contract nsz float @llvm.exp2.f32(float %must.be.nan)
ret float %exp
@@ -483,8 +481,7 @@ define nofpclass(pzero) <2 x float> @source_is_known_zero_or_nan_vec(<2 x float>
define nofpclass(nzero) float @source_is_known_snan(float nofpclass(inf norm sub zero qnan) %must.be.snan) {
; CHECK-LABEL: define nofpclass(nzero) float @source_is_known_snan(
; CHECK-SAME: float nofpclass(qnan inf zero sub norm) [[MUST_BE_SNAN:%.*]]) {
-; CHECK-NEXT: [[TMP1:%.*]] = fadd float [[MUST_BE_SNAN]], 1.000000e+00
-; CHECK-NEXT: ret float [[TMP1]]
+; CHECK-NEXT: ret float [[MUST_BE_SNAN]]
;
%exp = call float @llvm.exp2.f32(float %must.be.snan)
ret float %exp
@@ -493,8 +490,7 @@ define nofpclass(nzero) float @source_is_known_snan(float nofpclass(inf norm sub
define nofpclass(nzero) float @source_is_known_qnan(float nofpclass(inf norm sub zero snan) %must.be.qnan) {
; CHECK-LABEL: define nofpclass(nzero) float @source_is_known_qnan(
; CHECK-SAME: float nofpclass(snan inf zero sub norm) [[MUST_BE_QNAN:%.*]]) {
-; CHECK-NEXT: [[TMP1:%.*]] = fadd float [[MUST_BE_QNAN]], 1.000000e+00
-; CHECK-NEXT: ret float [[TMP1]]
+; CHECK-NEXT: ret float [[MUST_BE_QNAN]]
;
%exp = call float @llvm.exp2.f32(float %must.be.qnan)
ret float %exp
|
In SimplifyDemandedFPClass, reorder the known-nan source handling above The known-zero-or-nan handling. The more specific cases need to be handled first. Avoids spurious diff in an upcoming patch for fadd support; this would introduce a simplifiable fadd when we can just go directly to the end result.

In SimplifyDemandedFPClass, reorder the known-nan source
handling above The known-zero-or-nan handling. The more
specific cases need to be handled first. Avoids spurious
diff in an upcoming patch for fadd support; this would introduce
a simplifiable fadd when we can just go directly to the end
result.