[PATCH] D45501: example

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 10 13:57:24 PDT 2018


craig.topper updated this revision to Diff 141906.
craig.topper added a comment.

Used the mayStore flag instead of checking operand 0 for def. It felt a little clearer to think about.

I made a whole new instruction, but I was wondering if we could just mutate the original instruction by changing the opcode and adding the extra input register.


https://reviews.llvm.org/D45501

Files:
  lib/Target/X86/X86FlagsCopyLowering.cpp
  test/CodeGen/X86/flags-copy-lowering.mir


Index: test/CodeGen/X86/flags-copy-lowering.mir
===================================================================
--- test/CodeGen/X86/flags-copy-lowering.mir
+++ test/CodeGen/X86/flags-copy-lowering.mir
@@ -208,11 +208,10 @@
     %3:gr8 = SETAr implicit $eflags
     %4:gr8 = SETBr implicit $eflags
     %5:gr8 = SETEr implicit $eflags
-    %6:gr8 = SETNEr implicit killed $eflags
+    SETNEm $rsp, 1, $noreg, -16, $noreg, implicit killed $eflags
     MOV8mr $rsp, 1, $noreg, -16, $noreg, killed %3
     MOV8mr $rsp, 1, $noreg, -16, $noreg, killed %4
     MOV8mr $rsp, 1, $noreg, -16, $noreg, killed %5
-    MOV8mr $rsp, 1, $noreg, -16, $noreg, killed %6
   ; CHECK-NOT:     $eflags =
   ; CHECK-NOT:             = SET{{.*}}
   ; CHECK:         MOV8mr {{.*}}, killed %[[A_REG]]
Index: lib/Target/X86/X86FlagsCopyLowering.cpp
===================================================================
--- lib/Target/X86/X86FlagsCopyLowering.cpp
+++ lib/Target/X86/X86FlagsCopyLowering.cpp
@@ -727,8 +727,27 @@
   if (!CondReg)
     CondReg = promoteCondToReg(TestMBB, TestPos, TestLoc, Cond);
 
-  // Rewriting this is trivial: we just replace the register and remove the
-  // setcc.
-  MRI->replaceRegWith(SetCCI.getOperand(0).getReg(), CondReg);
+  // Rewriting a register def is trivial: we just replace the register and
+  // remove the setcc.
+  if (!SetCCI.mayStore()) {
+    assert(SetCCI.getOperand(0).isReg() &&
+           "Cannot have a non-register defined operand to SETcc!");
+    MRI->replaceRegWith(SetCCI.getOperand(0).getReg(), CondReg);
+    SetCCI.eraseFromParent();
+    return;
+  }
+
+  // Otherwise, we need to emit a store.
+  auto MIB = BuildMI(*SetCCI.getParent(), SetCCI.getIterator(),
+                     SetCCI.getDebugLoc(), TII->get(X86::MOV8mr));
+  // Copy the address operands.
+  for (int i = 0; i < X86::AddrNumOperands; ++i)
+    MIB.add(SetCCI.getOperand(i));
+
+  MIB.addReg(CondReg);
+
+  MIB->setMemRefs(SetCCI.memoperands_begin(), SetCCI.memoperands_end());
+
   SetCCI.eraseFromParent();
+  return;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45501.141906.patch
Type: text/x-patch
Size: 2044 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180410/2c24172b/attachment.bin>


More information about the llvm-commits mailing list