From: Oliver Stannard Date: Mon, 27 Oct 2014 09:23:02 +0000 (+0000) Subject: [ARM] Select VMAXNM and VMINNM regardless of operand order X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=79efe41a0ce09242e5ed9f5dc27bd7eae73da083;p=platform%2Fupstream%2Fllvm.git [ARM] Select VMAXNM and VMINNM regardless of operand order Currently, the ARM backend will select the VMAXNM and VMINNM for these C expressions: (a < b) ? a : b (a > b) ? a : b but not these expressions: (a > b) ? b : a (a < b) ? b : a This patch allows all of these expressions to be matched. llvm-svn: 220671 --- diff --git a/llvm/lib/Target/ARM/ARMISelLowering.cpp b/llvm/lib/Target/ARM/ARMISelLowering.cpp index 680b497..df3b016 100644 --- a/llvm/lib/Target/ARM/ARMISelLowering.cpp +++ b/llvm/lib/Target/ARM/ARMISelLowering.cpp @@ -3632,12 +3632,18 @@ SDValue ARMTargetLowering::LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const { // select c, a, b // We only do this in unsafe-fp-math, because signed zeros and NaNs are // handled differently than the original code sequence. - if (getTargetMachine().Options.UnsafeFPMath && LHS == TrueVal && - RHS == FalseVal) { - if (CC == ISD::SETOGT || CC == ISD::SETUGT) - return DAG.getNode(ARMISD::VMAXNM, dl, VT, TrueVal, FalseVal); - if (CC == ISD::SETOLT || CC == ISD::SETULT) - return DAG.getNode(ARMISD::VMINNM, dl, VT, TrueVal, FalseVal); + if (getTargetMachine().Options.UnsafeFPMath) { + if (LHS == TrueVal && RHS == FalseVal) { + if (CC == ISD::SETOGT || CC == ISD::SETUGT) + return DAG.getNode(ARMISD::VMAXNM, dl, VT, TrueVal, FalseVal); + if (CC == ISD::SETOLT || CC == ISD::SETULT) + return DAG.getNode(ARMISD::VMINNM, dl, VT, TrueVal, FalseVal); + } else if (LHS == FalseVal && RHS == TrueVal) { + if (CC == ISD::SETOLT || CC == ISD::SETULT) + return DAG.getNode(ARMISD::VMAXNM, dl, VT, TrueVal, FalseVal); + if (CC == ISD::SETOGT || CC == ISD::SETUGT) + return DAG.getNode(ARMISD::VMINNM, dl, VT, TrueVal, FalseVal); + } } bool swpCmpOps = false; diff --git a/llvm/test/CodeGen/ARM/vminmaxnm.ll b/llvm/test/CodeGen/ARM/vminmaxnm.ll index f6ce64c..39289a0 100644 --- a/llvm/test/CodeGen/ARM/vminmaxnm.ll +++ b/llvm/test/CodeGen/ARM/vminmaxnm.ll @@ -2,7 +2,7 @@ ; RUN: llc < %s -mtriple armv8 -mattr=+neon,+fp-armv8 -enable-unsafe-fp-math | FileCheck %s --check-prefix=CHECK-FAST define <4 x float> @vmaxnmq(<4 x float>* %A, <4 x float>* %B) nounwind { -; CHECK: vmaxnmq +; CHECK-LABEL: vmaxnmq: ; CHECK: vmaxnm.f32 q{{[0-9]+}}, q{{[0-9]+}}, q{{[0-9]+}} %tmp1 = load <4 x float>* %A %tmp2 = load <4 x float>* %B @@ -11,7 +11,7 @@ define <4 x float> @vmaxnmq(<4 x float>* %A, <4 x float>* %B) nounwind { } define <2 x float> @vmaxnmd(<2 x float>* %A, <2 x float>* %B) nounwind { -; CHECK: vmaxnmd +; CHECK-LABEL: vmaxnmd: ; CHECK: vmaxnm.f32 d{{[0-9]+}}, d{{[0-9]+}}, d{{[0-9]+}} %tmp1 = load <2 x float>* %A %tmp2 = load <2 x float>* %B @@ -20,7 +20,7 @@ define <2 x float> @vmaxnmd(<2 x float>* %A, <2 x float>* %B) nounwind { } define <4 x float> @vminnmq(<4 x float>* %A, <4 x float>* %B) nounwind { -; CHECK: vminnmq +; CHECK-LABEL: vminnmq: ; CHECK: vminnm.f32 q{{[0-9]+}}, q{{[0-9]+}}, q{{[0-9]+}} %tmp1 = load <4 x float>* %A %tmp2 = load <4 x float>* %B @@ -29,7 +29,7 @@ define <4 x float> @vminnmq(<4 x float>* %A, <4 x float>* %B) nounwind { } define <2 x float> @vminnmd(<2 x float>* %A, <2 x float>* %B) nounwind { -; CHECK: vminnmd +; CHECK-LABEL: vminnmd: ; CHECK: vminnm.f32 d{{[0-9]+}}, d{{[0-9]+}}, d{{[0-9]+}} %tmp1 = load <2 x float>* %A %tmp2 = load <2 x float>* %B @@ -38,49 +38,93 @@ define <2 x float> @vminnmd(<2 x float>* %A, <2 x float>* %B) nounwind { } define float @fp-armv8_vminnm_o(float %a, float %b) { -; CHECK-FAST: fp-armv8_vminnm_o +; CHECK-FAST-LABEL: "fp-armv8_vminnm_o": ; CHECK-FAST-NOT: vcmp ; CHECK-FAST: vminnm.f32 -; CHECK: fp-armv8_vminnm_o +; CHECK-LABEL: "fp-armv8_vminnm_o": ; CHECK-NOT: vminnm.f32 %cmp = fcmp olt float %a, %b %cond = select i1 %cmp, float %a, float %b ret float %cond } +define float @fp-armv8_vminnm_o_rev(float %a, float %b) { +; CHECK-FAST-LABEL: "fp-armv8_vminnm_o_rev": +; CHECK-FAST-NOT: vcmp +; CHECK-FAST: vminnm.f32 +; CHECK-LABEL: "fp-armv8_vminnm_o_rev": +; CHECK-NOT: vminnm.f32 + %cmp = fcmp ogt float %a, %b + %cond = select i1 %cmp, float %b, float %a + ret float %cond +} + define float @fp-armv8_vminnm_u(float %a, float %b) { -; CHECK-FAST: fp-armv8_vminnm_u +; CHECK-FAST-LABEL: "fp-armv8_vminnm_u": ; CHECK-FAST-NOT: vcmp ; CHECK-FAST: vminnm.f32 -; CHECK: fp-armv8_vminnm_u +; CHECK-LABEL: "fp-armv8_vminnm_u": ; CHECK-NOT: vminnm.f32 %cmp = fcmp ult float %a, %b %cond = select i1 %cmp, float %a, float %b ret float %cond } +define float @fp-armv8_vminnm_u_rev(float %a, float %b) { +; CHECK-FAST-LABEL: "fp-armv8_vminnm_u_rev": +; CHECK-FAST-NOT: vcmp +; CHECK-FAST: vminnm.f32 +; CHECK-LABEL: "fp-armv8_vminnm_u_rev": +; CHECK-NOT: vminnm.f32 + %cmp = fcmp ugt float %a, %b + %cond = select i1 %cmp, float %b, float %a + ret float %cond +} + define float @fp-armv8_vmaxnm_o(float %a, float %b) { -; CHECK-FAST: fp-armv8_vmaxnm_o +; CHECK-FAST-LABEL: "fp-armv8_vmaxnm_o": ; CHECK-FAST-NOT: vcmp ; CHECK-FAST: vmaxnm.f32 -; CHECK: fp-armv8_vmaxnm_o +; CHECK-LABEL: "fp-armv8_vmaxnm_o": ; CHECK-NOT: vmaxnm.f32 %cmp = fcmp ogt float %a, %b %cond = select i1 %cmp, float %a, float %b ret float %cond } +define float @fp-armv8_vmaxnm_o_rev(float %a, float %b) { +; CHECK-FAST-LABEL: "fp-armv8_vmaxnm_o_rev": +; CHECK-FAST-NOT: vcmp +; CHECK-FAST: vmaxnm.f32 +; CHECK-LABEL: "fp-armv8_vmaxnm_o_rev": +; CHECK-NOT: vmaxnm.f32 + %cmp = fcmp olt float %a, %b + %cond = select i1 %cmp, float %b, float %a + ret float %cond +} + define float @fp-armv8_vmaxnm_u(float %a, float %b) { -; CHECK-FAST: fp-armv8_vmaxnm_u +; CHECK-FAST-LABEL: "fp-armv8_vmaxnm_u": ; CHECK-FAST-NOT: vcmp ; CHECK-FAST: vmaxnm.f32 -; CHECK: fp-armv8_vmaxnm_u +; CHECK-LABEL: "fp-armv8_vmaxnm_u": ; CHECK-NOT: vmaxnm.f32 %cmp = fcmp ugt float %a, %b %cond = select i1 %cmp, float %a, float %b ret float %cond } +define float @fp-armv8_vmaxnm_u_rev(float %a, float %b) { +; CHECK-FAST-LABEL: "fp-armv8_vmaxnm_u_rev": +; CHECK-FAST-NOT: vcmp +; CHECK-FAST: vmaxnm.f32 +; CHECK-LABEL: "fp-armv8_vmaxnm_u_rev": +; CHECK-NOT: vmaxnm.f32 + %cmp = fcmp ult float %a, %b + %cond = select i1 %cmp, float %b, float %a + ret float %cond +} + declare <4 x float> @llvm.arm.neon.vminnm.v4f32(<4 x float>, <4 x float>) nounwind readnone declare <2 x float> @llvm.arm.neon.vminnm.v2f32(<2 x float>, <2 x float>) nounwind readnone