[PATCH] D42808: [X86] Teach DAG unfoldMemoryOperand to reconvert CMPs to tests
Nirav Dave via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 1 11:34:39 PST 2018
niravd created this revision.
niravd added reviewers: craig.topper, RKSimon.
Herald added a subscriber: hiraditya.
niravd added a dependency: D41293: [DAG,X86] Improve Dependency analysis when doing multi-node Instruction Selection.
Copy MI-level cmp->test conversion to SelectionDAG-level memory unfold.
This fixes a regression from https://reviews.llvm.org/D41293.
Repository:
rL LLVM
https://reviews.llvm.org/D42808
Files:
llvm/lib/Target/X86/X86InstrInfo.cpp
llvm/test/CodeGen/X86/2009-10-19-atomic-cmp-eflags.ll
llvm/test/CodeGen/X86/2012-01-16-mfence-nosse-flags.ll
Index: llvm/test/CodeGen/X86/2012-01-16-mfence-nosse-flags.ll
===================================================================
--- llvm/test/CodeGen/X86/2012-01-16-mfence-nosse-flags.ll
+++ llvm/test/CodeGen/X86/2012-01-16-mfence-nosse-flags.ll
@@ -14,9 +14,7 @@
; clobbers EFLAGS.
; CHECK: lock orl {{.*}}, (%esp)
-; CHECK-NEXT: cmpl $0, [[REG:%e[a-z]+]]
-; unfoldMemoryOperand should to convert this back to testl.
-; FIXME-NEXT: testl [[REG:%e[a-z]+]], [[REG]]
+; CHECK-NEXT: testl [[REG:%e[a-z]+]], [[REG]]
if.then: ; preds = %entry
tail call void bitcast (void (...)* @foo to void ()*)() nounwind
Index: llvm/test/CodeGen/X86/2009-10-19-atomic-cmp-eflags.ll
===================================================================
--- llvm/test/CodeGen/X86/2009-10-19-atomic-cmp-eflags.ll
+++ llvm/test/CodeGen/X86/2009-10-19-atomic-cmp-eflags.ll
@@ -1,6 +1,6 @@
; RUN: llvm-as <%s | llc | FileCheck %s
; PR 5247
-; check that cmp is not scheduled before the add
+; check that cmp/test is not scheduled before the add
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
target triple = "x86_64-unknown-linux-gnu"
@@ -38,7 +38,7 @@
%5 = sub i64 %4, %2 ; <i64> [#uses=1]
%6 = atomicrmw add i64* getelementptr inbounds ([1216 x i64], [1216 x i64]* @__profiling_callsite_timestamps_live, i32 0, i32 51), i64 %5 monotonic
;CHECK: lock {{xadd|addq}} %rdx, __profiling_callsite_timestamps_live
-;CHECK-NEXT: cmpl $0,
+;CHECK-NEXT: testl [[REG:%e[a-z]+]], [[REG]]
;CHECK-NEXT: jne
%cmp = icmp eq i32 %3, 0 ; <i1> [#uses=1]
br i1 %cmp, label %if.then, label %if.end
Index: llvm/lib/Target/X86/X86InstrInfo.cpp
===================================================================
--- llvm/lib/Target/X86/X86InstrInfo.cpp
+++ llvm/lib/Target/X86/X86InstrInfo.cpp
@@ -9223,6 +9223,32 @@
if (Load)
BeforeOps.push_back(SDValue(Load, 0));
BeforeOps.insert(BeforeOps.end(), AfterOps.begin(), AfterOps.end());
+ // Change CMP32ri r, 0 back to TEST32rr r, r, etc.
+ switch (Opc) {
+ default: break;
+ case X86::CMP64ri32:
+ case X86::CMP64ri8:
+ case X86::CMP32ri:
+ case X86::CMP32ri8:
+ case X86::CMP16ri:
+ case X86::CMP16ri8:
+ case X86::CMP8ri:
+ if (auto *C = dyn_cast<ConstantSDNode>(BeforeOps[1].getNode())) {
+ if(C->getConstantIntValue()->isZeroValue()) {
+ switch (Opc) {
+ default: llvm_unreachable("Unreachable!");
+ case X86::CMP64ri8:
+ case X86::CMP64ri32: Opc = X86::TEST64rr; break;
+ case X86::CMP32ri8:
+ case X86::CMP32ri: Opc = X86::TEST32rr; break;
+ case X86::CMP16ri8:
+ case X86::CMP16ri: Opc = X86::TEST16rr; break;
+ case X86::CMP8ri: Opc = X86::TEST8rr; break;
+ }
+ BeforeOps[1] = BeforeOps[0];
+ }
+ }
+ }
SDNode *NewNode= DAG.getMachineNode(Opc, dl, VTs, BeforeOps);
NewNodes.push_back(NewNode);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42808.132438.patch
Type: text/x-patch
Size: 3126 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180201/ec9616e2/attachment.bin>
More information about the llvm-commits
mailing list