Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 406e5ea

Browse files
committed
Simplify code; NFC.
Also, moved test cases from CodeGen/X86/fold-buildvector-bug.ll into CodeGen/X86/buildvec-insertvec.ll and regenerated CHECK lines using update_llc_test_checks.py. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239142 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent edbc0df commit 406e5ea

File tree

3 files changed

+55
-54
lines changed

3 files changed

+55
-54
lines changed

lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ static SDValue GetNegatedExpression(SDValue Op, SelectionDAG &DAG,
619619

620620
// fold (fneg (fsub 0, B)) -> B
621621
if (ConstantFPSDNode *N0CFP = dyn_cast<ConstantFPSDNode>(Op.getOperand(0)))
622-
if (N0CFP->getValueAPF().isZero())
622+
if (N0CFP->isZero())
623623
return Op.getOperand(1);
624624

625625
// fold (fneg (fsub A, B)) -> (fsub B, A)
@@ -7864,7 +7864,7 @@ SDValue DAGCombiner::visitFADD(SDNode *N) {
78647864
bool AllowNewConst = (Level < AfterLegalizeDAG);
78657865

78667866
// fold (fadd A, 0) -> A
7867-
if (N1CFP && N1CFP->getValueAPF().isZero())
7867+
if (N1CFP && N1CFP->isZero())
78687868
return N0;
78697869

78707870
// fold (fadd (fadd x, c1), c2) -> (fadd x, (fadd c1, c2))
@@ -7995,11 +7995,11 @@ SDValue DAGCombiner::visitFSUB(SDNode *N) {
79957995
// If 'unsafe math' is enabled, fold lots of things.
79967996
if (Options.UnsafeFPMath) {
79977997
// (fsub A, 0) -> A
7998-
if (N1CFP && N1CFP->getValueAPF().isZero())
7998+
if (N1CFP && N1CFP->isZero())
79997999
return N0;
80008000

80018001
// (fsub 0, B) -> -B
8002-
if (N0CFP && N0CFP->getValueAPF().isZero()) {
8002+
if (N0CFP && N0CFP->isZero()) {
80038003
if (isNegatibleForFree(N1, LegalOperations, TLI, &Options))
80048004
return GetNegatedExpression(N1, DAG, LegalOperations);
80058005
if (!LegalOperations || TLI.isOperationLegal(ISD::FNEG, VT))
@@ -8065,7 +8065,7 @@ SDValue DAGCombiner::visitFMUL(SDNode *N) {
80658065

80668066
if (Options.UnsafeFPMath) {
80678067
// fold (fmul A, 0) -> 0
8068-
if (N1CFP && N1CFP->getValueAPF().isZero())
8068+
if (N1CFP && N1CFP->isZero())
80698069
return N1;
80708070

80718071
// fold (fmul (fmul x, c1), c2) -> (fmul x, (fmul c1, c2))
@@ -12995,7 +12995,7 @@ SDValue DAGCombiner::SimplifyVBinOp(SDNode *N) {
1299512995
if (N->getOpcode() == ISD::SDIV || N->getOpcode() == ISD::UDIV ||
1299612996
N->getOpcode() == ISD::FDIV) {
1299712997
if (isNullConstant(RHSOp) || (RHSOp.getOpcode() == ISD::ConstantFP &&
12998-
cast<ConstantFPSDNode>(RHSOp.getNode())->getValueAPF().isZero()))
12998+
cast<ConstantFPSDNode>(RHSOp.getNode())->isZero()))
1299912999
break;
1300013000
}
1300113001

@@ -13259,7 +13259,7 @@ SDValue DAGCombiner::SimplifySelectCC(SDLoc DL, SDValue N0, SDValue N1,
1325913259
// Check to see if we can simplify the select into an fabs node
1326013260
if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(N1)) {
1326113261
// Allow either -0.0 or 0.0
13262-
if (CFP->getValueAPF().isZero()) {
13262+
if (CFP->isZero()) {
1326313263
// select (setg[te] X, +/-0.0), X, fneg(X) -> fabs
1326413264
if ((CC == ISD::SETGE || CC == ISD::SETGT) &&
1326513265
N0 == N2 && N3.getOpcode() == ISD::FNEG &&
Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,56 @@
1-
; RUN: llc < %s -mcpu=corei7 -mtriple=x86_64-unknown-linux-gnu | FileCheck %s
1+
; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+sse4.1 | FileCheck %s
22

33
define void @foo(<3 x float> %in, <4 x i8>* nocapture %out) nounwind {
4+
; CHECK-LABEL: foo:
5+
; CHECK: # BB#0:
6+
; CHECK-NEXT: cvttps2dq %xmm0, %xmm0
7+
; CHECK-NEXT: movl $255, %eax
8+
; CHECK-NEXT: pinsrd $3, %eax, %xmm0
9+
; CHECK-NEXT: pshufb {{.*#+}} xmm0 = xmm0[0,4,8,12,u,u,u,u,u,u,u,u,u,u,u,u]
10+
; CHECK-NEXT: movd %xmm0, (%rdi)
11+
; CHECK-NEXT: retq
412
%t0 = fptoui <3 x float> %in to <3 x i8>
513
%t1 = shufflevector <3 x i8> %t0, <3 x i8> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 undef>
614
%t2 = insertelement <4 x i8> %t1, i8 -1, i32 3
715
store <4 x i8> %t2, <4 x i8>* %out, align 4
816
ret void
9-
; CHECK: foo
10-
; CHECK: cvttps2dq
11-
; CHECK-NOT: pextrd
12-
; CHECK: pinsrd
13-
; CHECK-NEXT: pshufb
14-
; CHECK: ret
17+
}
18+
19+
; Verify that the DAGCombiner doesn't wrongly fold a build_vector into a
20+
; blend with a zero vector if the build_vector contains negative zero.
21+
;
22+
; TODO: the codegen for function 'test_negative_zero_1' is sub-optimal.
23+
; Ideally, we should generate a single shuffle blend operation.
24+
25+
define <4 x float> @test_negative_zero_1(<4 x float> %A) {
26+
; CHECK-LABEL: test_negative_zero_1:
27+
; CHECK: # BB#0: # %entry
28+
; CHECK-NEXT: movapd %xmm0, %xmm1
29+
; CHECK-NEXT: shufpd {{.*#+}} xmm1 = xmm1[1,0]
30+
; CHECK-NEXT: xorps %xmm2, %xmm2
31+
; CHECK-NEXT: blendps {{.*#+}} xmm2 = xmm1[0],xmm2[1,2,3]
32+
; CHECK-NEXT: movss {{.*#+}} xmm1 = mem[0],zero,zero,zero
33+
; CHECK-NEXT: unpcklps {{.*#+}} xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
34+
; CHECK-NEXT: unpcklpd {{.*#+}} xmm0 = xmm0[0],xmm2[0]
35+
; CHECK-NEXT: retq
36+
entry:
37+
%0 = extractelement <4 x float> %A, i32 0
38+
%1 = insertelement <4 x float> undef, float %0, i32 0
39+
%2 = insertelement <4 x float> %1, float -0.0, i32 1
40+
%3 = extractelement <4 x float> %A, i32 2
41+
%4 = insertelement <4 x float> %2, float %3, i32 2
42+
%5 = insertelement <4 x float> %4, float 0.0, i32 3
43+
ret <4 x float> %5
44+
}
45+
46+
define <2 x double> @test_negative_zero_2(<2 x double> %A) {
47+
; CHECK-LABEL: test_negative_zero_2:
48+
; CHECK: # BB#0: # %entry
49+
; CHECK-NEXT: movhpd {{.*}}(%rip), %xmm0
50+
; CHECK-NEXT: retq
51+
entry:
52+
%0 = extractelement <2 x double> %A, i32 0
53+
%1 = insertelement <2 x double> undef, double %0, i32 0
54+
%2 = insertelement <2 x double> %1, double -0.0, i32 1
55+
ret <2 x double> %2
1556
}

test/CodeGen/X86/fold-buildvector-bug.ll

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)