[llvm] r357353 - [X86] Teach isel for RMW binops to handle negate
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 30 11:59:17 PDT 2019
Author: ctopper
Date: Sat Mar 30 11:59:17 2019
New Revision: 357353
URL: http://llvm.org/viewvc/llvm-project?rev=357353&view=rev
Log:
[X86] Teach isel for RMW binops to handle negate
Negate updates flags like a subtract. We should be able to use the flags from the RMW form of negate when we have (store (X86ISD::SUB 0, load A), A)
Differential Revision: https://reviews.llvm.org/D60007
Modified:
llvm/trunk/lib/Target/X86/X86ISelDAGToDAG.cpp
llvm/trunk/test/CodeGen/X86/fold-rmw-ops.ll
Modified: llvm/trunk/lib/Target/X86/X86ISelDAGToDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelDAGToDAG.cpp?rev=357353&r1=357352&r2=357353&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelDAGToDAG.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelDAGToDAG.cpp Sat Mar 30 11:59:17 2019
@@ -2634,10 +2634,13 @@ bool X86DAGToDAGISel::foldLoadStoreIntoM
return false;
bool IsCommutable = false;
+ bool IsNegate = false;
switch (Opc) {
default:
return false;
case X86ISD::SUB:
+ IsNegate = isNullConstant(StoredVal.getOperand(0));
+ break;
case X86ISD::SBB:
break;
case X86ISD::ADD:
@@ -2649,7 +2652,7 @@ bool X86DAGToDAGISel::foldLoadStoreIntoM
break;
}
- unsigned LoadOpNo = 0;
+ unsigned LoadOpNo = IsNegate ? 1 : 0;
LoadSDNode *LoadNode = nullptr;
SDValue InputChain;
if (!isFusableLoadOpStorePattern(StoreNode, StoredVal, CurDAG, LoadOpNo,
@@ -2687,8 +2690,18 @@ bool X86DAGToDAGISel::foldLoadStoreIntoM
MachineSDNode *Result;
switch (Opc) {
- case X86ISD::ADD:
case X86ISD::SUB:
+ // Handle negate.
+ if (IsNegate) {
+ unsigned NewOpc = SelectOpcode(X86::NEG64m, X86::NEG32m, X86::NEG16m,
+ X86::NEG8m);
+ const SDValue Ops[] = {Base, Scale, Index, Disp, Segment, InputChain};
+ Result = CurDAG->getMachineNode(NewOpc, SDLoc(Node), MVT::i32,
+ MVT::Other, Ops);
+ break;
+ }
+ LLVM_FALLTHROUGH;
+ case X86ISD::ADD:
// Try to match inc/dec.
if (!Subtarget->slowIncDec() || OptForSize) {
bool IsOne = isOneConstant(StoredVal.getOperand(1));
Modified: llvm/trunk/test/CodeGen/X86/fold-rmw-ops.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/fold-rmw-ops.ll?rev=357353&r1=357352&r2=357353&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/fold-rmw-ops.ll (original)
+++ llvm/trunk/test/CodeGen/X86/fold-rmw-ops.ll Sat Mar 30 11:59:17 2019
@@ -2434,10 +2434,7 @@ b:
define void @neg64_br() nounwind {
; CHECK-LABEL: neg64_br:
; CHECK: # %bb.0: # %entry
-; CHECK-NEXT: xorl %eax, %eax # encoding: [0x31,0xc0]
-; CHECK-NEXT: subq {{.*}}(%rip), %rax # encoding: [0x48,0x2b,0x05,A,A,A,A]
-; CHECK-NEXT: # fixup A - offset: 3, value: g64-4, kind: reloc_riprel_4byte_relax_rex
-; CHECK-NEXT: movq %rax, {{.*}}(%rip) # encoding: [0x48,0x89,0x05,A,A,A,A]
+; CHECK-NEXT: negq {{.*}}(%rip) # encoding: [0x48,0xf7,0x1d,A,A,A,A]
; CHECK-NEXT: # fixup A - offset: 3, value: g64-4, kind: reloc_riprel_4byte
; CHECK-NEXT: js .LBB76_1 # encoding: [0x78,A]
; CHECK-NEXT: # fixup A - offset: 1, value: .LBB76_1-1, kind: FK_PCRel_1
@@ -2468,10 +2465,7 @@ b:
define void @neg32_br() nounwind {
; CHECK-LABEL: neg32_br:
; CHECK: # %bb.0: # %entry
-; CHECK-NEXT: xorl %eax, %eax # encoding: [0x31,0xc0]
-; CHECK-NEXT: subl {{.*}}(%rip), %eax # encoding: [0x2b,0x05,A,A,A,A]
-; CHECK-NEXT: # fixup A - offset: 2, value: g32-4, kind: reloc_riprel_4byte
-; CHECK-NEXT: movl %eax, {{.*}}(%rip) # encoding: [0x89,0x05,A,A,A,A]
+; CHECK-NEXT: negl {{.*}}(%rip) # encoding: [0xf7,0x1d,A,A,A,A]
; CHECK-NEXT: # fixup A - offset: 2, value: g32-4, kind: reloc_riprel_4byte
; CHECK-NEXT: js .LBB77_1 # encoding: [0x78,A]
; CHECK-NEXT: # fixup A - offset: 1, value: .LBB77_1-1, kind: FK_PCRel_1
@@ -2502,10 +2496,7 @@ b:
define void @neg16_br() nounwind {
; CHECK-LABEL: neg16_br:
; CHECK: # %bb.0: # %entry
-; CHECK-NEXT: xorl %eax, %eax # encoding: [0x31,0xc0]
-; CHECK-NEXT: subw {{.*}}(%rip), %ax # encoding: [0x66,0x2b,0x05,A,A,A,A]
-; CHECK-NEXT: # fixup A - offset: 3, value: g16-4, kind: reloc_riprel_4byte
-; CHECK-NEXT: movw %ax, {{.*}}(%rip) # encoding: [0x66,0x89,0x05,A,A,A,A]
+; CHECK-NEXT: negw {{.*}}(%rip) # encoding: [0x66,0xf7,0x1d,A,A,A,A]
; CHECK-NEXT: # fixup A - offset: 3, value: g16-4, kind: reloc_riprel_4byte
; CHECK-NEXT: js .LBB78_1 # encoding: [0x78,A]
; CHECK-NEXT: # fixup A - offset: 1, value: .LBB78_1-1, kind: FK_PCRel_1
@@ -2536,10 +2527,7 @@ b:
define void @neg8_br() nounwind {
; CHECK-LABEL: neg8_br:
; CHECK: # %bb.0: # %entry
-; CHECK-NEXT: xorl %eax, %eax # encoding: [0x31,0xc0]
-; CHECK-NEXT: subb {{.*}}(%rip), %al # encoding: [0x2a,0x05,A,A,A,A]
-; CHECK-NEXT: # fixup A - offset: 2, value: g8-4, kind: reloc_riprel_4byte
-; CHECK-NEXT: movb %al, {{.*}}(%rip) # encoding: [0x88,0x05,A,A,A,A]
+; CHECK-NEXT: negb {{.*}}(%rip) # encoding: [0xf6,0x1d,A,A,A,A]
; CHECK-NEXT: # fixup A - offset: 2, value: g8-4, kind: reloc_riprel_4byte
; CHECK-NEXT: js .LBB79_1 # encoding: [0x78,A]
; CHECK-NEXT: # fixup A - offset: 1, value: .LBB79_1-1, kind: FK_PCRel_1
More information about the llvm-commits
mailing list