Skip to content

Commit fe56afc

Browse files
committed
AMDGPU: Fix fcanonicalize constant folding not correctly handling -0.0
1 parent 18fda86 commit fe56afc

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10284,8 +10284,10 @@ bool SITargetLowering::isCanonicalized(Register Reg, MachineFunction &MF,
1028410284
SDValue SITargetLowering::getCanonicalConstantFP(
1028510285
SelectionDAG &DAG, const SDLoc &SL, EVT VT, const APFloat &C) const {
1028610286
// Flush denormals to 0 if not enabled.
10287-
if (C.isDenormal() && !denormalsEnabledForType(DAG, VT))
10288-
return DAG.getConstantFP(0.0, SL, VT);
10287+
if (C.isDenormal() && !denormalsEnabledForType(DAG, VT)) {
10288+
return DAG.getConstantFP(APFloat::getZero(C.getSemantics(),
10289+
C.isNegative()), SL, VT);
10290+
}
1028910291

1029010292
if (C.isNaN()) {
1029110293
APFloat CanonicalQNaN = APFloat::getQNaN(C.getSemantics());

llvm/test/CodeGen/AMDGPU/fcanonicalize.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ define amdgpu_kernel void @test_denormals_fold_canonicalize_denormal0_f32(float
148148
}
149149

150150
; GCN-LABEL: {{^}}test_no_denormals_fold_canonicalize_denormal1_f32:
151-
; GCN: v_mov_b32_e32 [[REG:v[0-9]+]], 0{{$}}
151+
; GCN: v_bfrev_b32_e32 [[REG:v[0-9]+]], 1{{$}}
152152
; GCN: {{flat|global}}_store_dword v{{.+}}, [[REG]]
153153
define amdgpu_kernel void @test_no_denormals_fold_canonicalize_denormal1_f32(float addrspace(1)* %out) #1 {
154154
%canonicalized = call float @llvm.canonicalize.f32(float bitcast (i32 2155872255 to float))
@@ -353,7 +353,7 @@ define amdgpu_kernel void @test_denormals_fold_canonicalize_denormal0_f64(double
353353

354354
; GCN-LABEL: {{^}}test_no_denormals_fold_canonicalize_denormal1_f64:
355355
; GCN: v_mov_b32_e32 v[[LO:[0-9]+]], 0{{$}}
356-
; GCN: v_mov_b32_e32 v[[HI:[0-9]+]], v[[LO]]{{$}}
356+
; GCN: v_bfrev_b32_e32 v[[HI:[0-9]+]], 1{{$}}
357357
; GCN: {{flat|global}}_store_dwordx2 v{{.+}}, v[[[LO]]:[[HI]]]
358358
define amdgpu_kernel void @test_no_denormals_fold_canonicalize_denormal1_f64(double addrspace(1)* %out) #2 {
359359
%canonicalized = call double @llvm.canonicalize.f64(double bitcast (i64 9227875636482146303 to double))

0 commit comments

Comments
 (0)