Skip to content

Commit ebfee32

Browse files
authored
[SDAG] Constant fold frexp in signed way (#161015)
Fixes #160981 The exponential part of a floating-point number is signed. This patch prevents treating it as unsigned.
1 parent 078e99e commit ebfee32

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11161,8 +11161,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList,
1116111161
APFloat FrexpMant =
1116211162
frexp(C->getValueAPF(), FrexpExp, APFloat::rmNearestTiesToEven);
1116311163
SDValue Result0 = getConstantFP(FrexpMant, DL, VTList.VTs[0]);
11164-
SDValue Result1 =
11165-
getConstant(FrexpMant.isFinite() ? FrexpExp : 0, DL, VTList.VTs[1]);
11164+
SDValue Result1 = getSignedConstant(FrexpMant.isFinite() ? FrexpExp : 0,
11165+
DL, VTList.VTs[1]);
1116611166
return getNode(ISD::MERGE_VALUES, DL, VTList, {Result0, Result1}, Flags);
1116711167
}
1116811168

llvm/test/CodeGen/X86/llvm.frexp.ll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,22 @@ define i32 @test_frexp_f64_i32_only_use_exp(double %a) nounwind {
582582
ret i32 %result.0
583583
}
584584

585+
define { float, i32 } @pr160981() {
586+
; X64-LABEL: pr160981:
587+
; X64: # %bb.0:
588+
; X64-NEXT: movss {{.*#+}} xmm0 = [9.9999988E-1,0.0E+0,0.0E+0,0.0E+0]
589+
; X64-NEXT: movl $-126, %eax
590+
; X64-NEXT: retq
591+
;
592+
; WIN32-LABEL: pr160981:
593+
; WIN32: # %bb.0:
594+
; WIN32-NEXT: flds __real@3f7ffffe
595+
; WIN32-NEXT: movl $-126, %eax
596+
; WIN32-NEXT: retl
597+
%ret = call { float, i32 } @llvm.frexp.f32.i32(float bitcast (i32 8388607 to float))
598+
ret { float, i32 } %ret
599+
}
600+
585601
; FIXME: Widen vector result
586602
; define { <2 x double>, <2 x i32> } @test_frexp_v2f64_v2i32(<2 x double> %a) nounwind {
587603
; %result = call { <2 x double>, <2 x i32> } @llvm.frexp.v2f64.v2i32(<2 x double> %a)

0 commit comments

Comments
 (0)