[llvm] r208469 - ARM64: fix SELECT_CC lowering in absence of NaNs.
Tim Northover
tnorthover at apple.com
Sat May 10 00:37:52 PDT 2014
Author: tnorthover
Date: Sat May 10 02:37:50 2014
New Revision: 208469
URL: http://llvm.org/viewvc/llvm-project?rev=208469&view=rev
Log:
ARM64: fix SELECT_CC lowering in absence of NaNs.
We were swapping the true & false results while testing for FMAX/FMIN,
but not putting them back to the original state if the later checks
failed.
Should fix PR19700.
Modified:
llvm/trunk/lib/Target/ARM64/ARM64ISelLowering.cpp
llvm/trunk/test/CodeGen/ARM64/fmax.ll
Modified: llvm/trunk/lib/Target/ARM64/ARM64ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM64/ARM64ISelLowering.cpp?rev=208469&r1=208468&r2=208469&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM64/ARM64ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/ARM64/ARM64ISelLowering.cpp Sat May 10 02:37:50 2014
@@ -3121,17 +3121,18 @@ SDValue ARM64TargetLowering::LowerSELECT
// Try to match this select into a max/min operation, which have dedicated
// opcode in the instruction set.
- // NOTE: This is not correct in the presence of NaNs, so we only enable this
+ // FIXME: This is not correct in the presence of NaNs, so we only enable this
// in no-NaNs mode.
if (getTargetMachine().Options.NoNaNsFPMath) {
- if (selectCCOpsAreFMaxCompatible(LHS, FVal) &&
- selectCCOpsAreFMaxCompatible(RHS, TVal)) {
+ SDValue MinMaxLHS = TVal, MinMaxRHS = FVal;
+ if (selectCCOpsAreFMaxCompatible(LHS, MinMaxRHS) &&
+ selectCCOpsAreFMaxCompatible(RHS, MinMaxLHS)) {
CC = ISD::getSetCCSwappedOperands(CC);
- std::swap(TVal, FVal);
+ std::swap(MinMaxLHS, MinMaxRHS);
}
- if (selectCCOpsAreFMaxCompatible(LHS, TVal) &&
- selectCCOpsAreFMaxCompatible(RHS, FVal)) {
+ if (selectCCOpsAreFMaxCompatible(LHS, MinMaxLHS) &&
+ selectCCOpsAreFMaxCompatible(RHS, MinMaxRHS)) {
switch (CC) {
default:
break;
@@ -3141,7 +3142,7 @@ SDValue ARM64TargetLowering::LowerSELECT
case ISD::SETUGE:
case ISD::SETOGT:
case ISD::SETOGE:
- return DAG.getNode(ARM64ISD::FMAX, dl, VT, TVal, FVal);
+ return DAG.getNode(ARM64ISD::FMAX, dl, VT, MinMaxLHS, MinMaxRHS);
break;
case ISD::SETLT:
case ISD::SETLE:
@@ -3149,7 +3150,7 @@ SDValue ARM64TargetLowering::LowerSELECT
case ISD::SETULE:
case ISD::SETOLT:
case ISD::SETOLE:
- return DAG.getNode(ARM64ISD::FMIN, dl, VT, TVal, FVal);
+ return DAG.getNode(ARM64ISD::FMIN, dl, VT, MinMaxLHS, MinMaxRHS);
break;
}
}
Modified: llvm/trunk/test/CodeGen/ARM64/fmax.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM64/fmax.ll?rev=208469&r1=208468&r2=208469&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/ARM64/fmax.ll (original)
+++ llvm/trunk/test/CodeGen/ARM64/fmax.ll Sat May 10 02:37:50 2014
@@ -1,7 +1,7 @@
; RUN: llc -march=arm64 -enable-no-nans-fp-math < %s | FileCheck %s
define double @test_direct(float %in) #1 {
-entry:
+; CHECK-LABEL: test_direct:
%cmp = fcmp olt float %in, 0.000000e+00
%longer = fpext float %in to double
%val = select i1 %cmp, double 0.000000e+00, double %longer
@@ -11,7 +11,7 @@ entry:
}
define double @test_cross(float %in) #1 {
-entry:
+; CHECK-LABEL: test_cross:
%cmp = fcmp olt float %in, 0.000000e+00
%longer = fpext float %in to double
%val = select i1 %cmp, double %longer, double 0.000000e+00
@@ -19,3 +19,16 @@ entry:
; CHECK: fmin
}
+
+; This isn't a min or a max, but passes the first condition for swapping the
+; results. Make sure they're put back before we resort to the normal fcsel.
+define float @test_cross_fail(float %lhs, float %rhs) {
+; CHECK-LABEL: test_cross_fail:
+ %tst = fcmp une float %lhs, %rhs
+ %res = select i1 %tst, float %rhs, float %lhs
+ ret float %res
+
+ ; The register allocator would have to decide to be deliberately obtuse before
+ ; other register were used.
+; CHECK: fcsel s0, s1, s0, ne
+}
\ No newline at end of file
More information about the llvm-commits
mailing list