From 286f644bce84dca0e33899b3a80fa53a5b3f632a Mon Sep 17 00:00:00 2001 From: Jan Vesely Date: Fri, 5 Sep 2014 14:26:54 +0000 Subject: [PATCH] R600: Fix FROUND round halfway cases away from zero Signed-off-by: Jan Vesely Reviewed-by: Tom Stellard git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217250 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/R600/EvergreenInstructions.td | 2 +- lib/Target/R600/R600Instructions.td | 9 ++++++--- test/CodeGen/R600/llvm.round.ll | 14 ++++++++------ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/Target/R600/EvergreenInstructions.td b/lib/Target/R600/EvergreenInstructions.td index a83567a6aca..ea3f550dcb9 100644 --- a/lib/Target/R600/EvergreenInstructions.td +++ b/lib/Target/R600/EvergreenInstructions.td @@ -537,7 +537,7 @@ def : Pat<(fp_to_uint f32:$src0), (FLT_TO_UINT_eg (TRUNC $src0))>; // SHA-256 Patterns def : SHA256MaPattern ; -def : FROUNDPat ; +def : FROUNDPat ; def EG_ExportSwz : ExportSwzInst { let Word1{19-16} = 0; // BURST_COUNT diff --git a/lib/Target/R600/R600Instructions.td b/lib/Target/R600/R600Instructions.td index 671f923a91c..a883c839e62 100644 --- a/lib/Target/R600/R600Instructions.td +++ b/lib/Target/R600/R600Instructions.td @@ -1141,9 +1141,12 @@ class TGSI_LIT_Z_Common ; // FROUND pattern -class FROUNDPat : Pat < +class FROUNDPat : Pat < (AMDGPUround f32:$x), - (CNDGE (ADD (FNEG_R600 (f32 HALF)), (FRACT $x)), (CEIL $x), (FLOOR $x)) + (CNDGE $x, + (CNDGE (ADD (FNEG_R600 (f32 HALF)), (FRACT $x)), (CEIL $x), (FLOOR $x)), + (CNDGT (ADD (FNEG_R600 (f32 HALF)), (FRACT $x)), (CEIL $x), (FLOOR $x)) + ) >; @@ -1190,7 +1193,7 @@ let Predicates = [isR600] in { def : Pat<(fsqrt f32:$src), (MUL $src, (RECIPSQRT_CLAMPED_r600 $src))>; defm : RsqPat; - def : FROUNDPat ; + def : FROUNDPat ; def R600_ExportSwz : ExportSwzInst { let Word1{20-17} = 0; // BURST_COUNT diff --git a/test/CodeGen/R600/llvm.round.ll b/test/CodeGen/R600/llvm.round.ll index e06d45d4a37..5700427ee89 100644 --- a/test/CodeGen/R600/llvm.round.ll +++ b/test/CodeGen/R600/llvm.round.ll @@ -1,11 +1,13 @@ -; RUN: llc < %s -march=r600 -mcpu=redwood | FileCheck %s --check-prefix=R600 --check-prefix=FUNC +; RUN: llc -march=r600 -mcpu=redwood < %s | FileCheck %s --check-prefix=R600 --check-prefix=FUNC ; FUNC-LABEL: @f32 -; R600: FRACT -; R600-DAG: ADD -; R600-DAG: CEIL -; R600-DAG: FLOOR -; R600: CNDGE +; R600: FRACT {{.*}}, [[ARG:KC[0-9]\[[0-9]+\]\.[XYZW]]] +; R600-DAG: ADD {{.*}}, -0.5 +; R600-DAG: CEIL {{.*}} [[ARG]] +; R600-DAG: FLOOR {{.*}} [[ARG]] +; R600-DAG: CNDGE +; R600-DAG: CNDGT +; R600: CNDGE {{[^,]+}}, [[ARG]] define void @f32(float addrspace(1)* %out, float %in) { entry: %0 = call float @llvm.round.f32(float %in)