llvm.org GIT mirror llvm / 1332459
X86: Don't generate 64-bit movd after cmpneqsd in 32-bit mode (PR19059) This fixes the bug where we would bitcast the 64-bit floating point result of cmpneqsd to a 64-bit integer even on 32-bit targets. Differential Revision: http://llvm-reviews.chandlerc.com/D3009 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203581 91177308-0d34-0410-b5e6-96231b3b80d8 Hans Wennborg 5 years ago
2 changed file(s) with 46 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
1804318043
1804418044 if ((cc0 == X86::COND_E && cc1 == X86::COND_NP) ||
1804518045 (cc0 == X86::COND_NE && cc1 == X86::COND_P)) {
18046 bool is64BitFP = (CMP00.getValueType() == MVT::f64);
1804718046 // FIXME: need symbolic constants for these magic numbers.
1804818047 // See X86ATTInstPrinter.cpp:printSSECC().
1804918048 unsigned x86cc = (cc0 == X86::COND_E) ? 0 : 4;
1805818057 SDValue OnesOrZeroesF = DAG.getNode(X86ISD::FSETCC, DL,
1805918058 CMP00.getValueType(), CMP00, CMP01,
1806018059 DAG.getConstant(x86cc, MVT::i8));
18061 MVT IntVT = (is64BitFP ? MVT::i64 : MVT::i32);
18062 SDValue OnesOrZeroesI = DAG.getNode(ISD::BITCAST, DL, IntVT,
18063 OnesOrZeroesF);
18060
18061 bool is64BitFP = (CMP00.getValueType() == MVT::f64);
18062 MVT IntVT = is64BitFP ? MVT::i64 : MVT::i32;
18063
18064 if (is64BitFP && !Subtarget->is64Bit()) {
18065 // On a 32-bit target, we cannot bitcast the 64-bit float to a
18066 // 64-bit integer, since that's not a legal type. Since
18067 // OnesOrZeroesF is all ones of all zeroes, we don't need all the
18068 // bits, but can do this little dance to extract the lowest 32 bits
18069 // and work with those going forward.
18070 SDValue Vector64 = DAG.getNode(ISD::SCALAR_TO_VECTOR, DL, MVT::v2f64,
18071 OnesOrZeroesF);
18072 SDValue Vector32 = DAG.getNode(ISD::BITCAST, DL, MVT::v4f32,
18073 Vector64);
18074 OnesOrZeroesF = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f32,
18075 Vector32, DAG.getIntPtrConstant(0));
18076 IntVT = MVT::i32;
18077 }
18078
18079 SDValue OnesOrZeroesI = DAG.getNode(ISD::BITCAST, DL, IntVT, OnesOrZeroesF);
1806418080 SDValue ANDed = DAG.getNode(ISD::AND, DL, IntVT, OnesOrZeroesI,
1806518081 DAG.getConstant(1, IntVT));
1806618082 SDValue OneBitOfTruth = DAG.getNode(ISD::TRUNCATE, DL, MVT::i8, ANDed);
None ; RUN: llc < %s -march=x86 -mattr=+sse2 -mcpu=penryn| FileCheck %s
0 ; RUN: llc < %s -mtriple=x86_64-pc-unknown -mattr=+sse2 -mcpu=penryn | FileCheck %s
1 ; RUN: llc < %s -mtriple=i686-pc-unknown -mattr=+sse2 -mcpu=penryn | FileCheck %s
2
3 ; PR19059
4 ; RUN: llc < %s -mtriple=i686-pc-unknown -mattr=+sse2 -mcpu=penryn | FileCheck -check-prefix=CHECK32 %s
15
26 define i32 @isint_return(double %d) nounwind {
7 ; CHECK-LABEL: isint_return:
38 ; CHECK-NOT: xor
49 ; CHECK: cvt
510 %i = fptosi double %d to i32
712 %e = sitofp i32 %i to double
813 ; CHECK: cmpeqsd
914 %c = fcmp oeq double %d, %e
15 ; CHECK32-NOT: movd {{.*}}, %r{{.*}}
16 ; CHECK32-NOT: andq
1017 ; CHECK-NEXT: movd
11 ; CHECK-NEXT: andq
18 ; CHECK-NEXT: andl
19 %z = zext i1 %c to i32
20 ret i32 %z
21 }
22
23 define i32 @isint_float_return(float %f) nounwind {
24 ; CHECK-LABEL: isint_float_return:
25 ; CHECK-NOT: xor
26 ; CHECK: cvt
27 %i = fptosi float %f to i32
28 ; CHECK-NEXT: cvt
29 %g = sitofp i32 %i to float
30 ; CHECK: cmpeqss
31 %c = fcmp oeq float %f, %g
32 ; CHECK-NOT: movd {{.*}}, %r{{.*}}
33 ; CHECK-NEXT: movd
34 ; CHECK-NEXT: andl
1235 %z = zext i1 %c to i32
1336 ret i32 %z
1437 }
1639 declare void @foo()
1740
1841 define void @isint_branch(double %d) nounwind {
42 ; CHECK-LABEL: isint_branch:
1943 ; CHECK: cvt
2044 %i = fptosi double %d to i32
2145 ; CHECK-NEXT: cvt