-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[SDAG] Constant fold frexp in signed way #161015
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
Conversation
@llvm/pr-subscribers-llvm-selectiondag Author: Hongyu Chen (XChy) ChangesFixes #160981 Full diff: https://github.com/llvm/llvm-project/pull/161015.diff 2 Files Affected:
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 7aa293af963e6..8fc7eabf90ea8 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -11161,8 +11161,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList,
APFloat FrexpMant =
frexp(C->getValueAPF(), FrexpExp, APFloat::rmNearestTiesToEven);
SDValue Result0 = getConstantFP(FrexpMant, DL, VTList.VTs[0]);
- SDValue Result1 =
- getConstant(FrexpMant.isFinite() ? FrexpExp : 0, DL, VTList.VTs[1]);
+ SDValue Result1 = getSignedConstant(FrexpMant.isFinite() ? FrexpExp : 0,
+ DL, VTList.VTs[1]);
return getNode(ISD::MERGE_VALUES, DL, VTList, {Result0, Result1}, Flags);
}
diff --git a/llvm/test/CodeGen/X86/llvm.frexp.ll b/llvm/test/CodeGen/X86/llvm.frexp.ll
index 83840dd85c533..e3a1b1b83b2e3 100644
--- a/llvm/test/CodeGen/X86/llvm.frexp.ll
+++ b/llvm/test/CodeGen/X86/llvm.frexp.ll
@@ -582,6 +582,22 @@ define i32 @test_frexp_f64_i32_only_use_exp(double %a) nounwind {
ret i32 %result.0
}
+define { float, i32 } @pr160981() {
+; X64-LABEL: pr160981:
+; X64: # %bb.0:
+; X64-NEXT: movss {{.*#+}} xmm0 = [9.9999988E-1,0.0E+0,0.0E+0,0.0E+0]
+; X64-NEXT: movl $-126, %eax
+; X64-NEXT: retq
+;
+; WIN32-LABEL: pr160981:
+; WIN32: # %bb.0:
+; WIN32-NEXT: flds __real@3f7ffffe
+; WIN32-NEXT: movl $-126, %eax
+; WIN32-NEXT: retl
+ %ret = call { float, i32 } @llvm.frexp.f32.i32(float bitcast (i32 8388607 to float))
+ ret { float, i32 } %ret
+}
+
; FIXME: Widen vector result
; define { <2 x double>, <2 x i32> } @test_frexp_v2f64_v2i32(<2 x double> %a) nounwind {
; %result = call { <2 x double>, <2 x i32> } @llvm.frexp.v2f64.v2i32(<2 x double> %a)
|
@llvm/pr-subscribers-backend-x86 Author: Hongyu Chen (XChy) ChangesFixes #160981 Full diff: https://github.com/llvm/llvm-project/pull/161015.diff 2 Files Affected:
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 7aa293af963e6..8fc7eabf90ea8 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -11161,8 +11161,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList,
APFloat FrexpMant =
frexp(C->getValueAPF(), FrexpExp, APFloat::rmNearestTiesToEven);
SDValue Result0 = getConstantFP(FrexpMant, DL, VTList.VTs[0]);
- SDValue Result1 =
- getConstant(FrexpMant.isFinite() ? FrexpExp : 0, DL, VTList.VTs[1]);
+ SDValue Result1 = getSignedConstant(FrexpMant.isFinite() ? FrexpExp : 0,
+ DL, VTList.VTs[1]);
return getNode(ISD::MERGE_VALUES, DL, VTList, {Result0, Result1}, Flags);
}
diff --git a/llvm/test/CodeGen/X86/llvm.frexp.ll b/llvm/test/CodeGen/X86/llvm.frexp.ll
index 83840dd85c533..e3a1b1b83b2e3 100644
--- a/llvm/test/CodeGen/X86/llvm.frexp.ll
+++ b/llvm/test/CodeGen/X86/llvm.frexp.ll
@@ -582,6 +582,22 @@ define i32 @test_frexp_f64_i32_only_use_exp(double %a) nounwind {
ret i32 %result.0
}
+define { float, i32 } @pr160981() {
+; X64-LABEL: pr160981:
+; X64: # %bb.0:
+; X64-NEXT: movss {{.*#+}} xmm0 = [9.9999988E-1,0.0E+0,0.0E+0,0.0E+0]
+; X64-NEXT: movl $-126, %eax
+; X64-NEXT: retq
+;
+; WIN32-LABEL: pr160981:
+; WIN32: # %bb.0:
+; WIN32-NEXT: flds __real@3f7ffffe
+; WIN32-NEXT: movl $-126, %eax
+; WIN32-NEXT: retl
+ %ret = call { float, i32 } @llvm.frexp.f32.i32(float bitcast (i32 8388607 to float))
+ ret { float, i32 } %ret
+}
+
; FIXME: Widen vector result
; define { <2 x double>, <2 x i32> } @test_frexp_v2f64_v2i32(<2 x double> %a) nounwind {
; %result = call { <2 x double>, <2 x i32> } @llvm.frexp.v2f64.v2i32(<2 x double> %a)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - cheers
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/174/builds/25168 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/143/builds/11224 Here is the relevant piece of the build log for the reference
|
Fixes llvm#160981 The exponential part of a floating-point number is signed. This patch prevents treating it as unsigned.
Fixes #160981
The exponential part of a floating-point number is signed. This patch prevents treating it as unsigned.