[llvm] r278144 - [X86] Don't model UD2/UD2B as a terminator

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 9 10:55:12 PDT 2016


Author: majnemer
Date: Tue Aug  9 12:55:12 2016
New Revision: 278144

URL: http://llvm.org/viewvc/llvm-project?rev=278144&view=rev
Log:
[X86] Don't model UD2/UD2B as a terminator

A UD2 might make its way into the program via a call to @llvm.trap.
Obviously, calls are not terminators.  However, we modeled the X86
instruction, UD2, as a terminator.  Later on, this confuses the epilogue
insertion machinery which results in the epilogue getting inserted
before the UD2.  For some platforms, like x64, the result is a
violation of the ABI.

Instead, model UD2/UD2B as a side effecting instruction which may
observe memory.

Modified:
    llvm/trunk/lib/Target/X86/X86InstrSystem.td
    llvm/trunk/test/CodeGen/X86/x86-framelowering-trap.ll

Modified: llvm/trunk/lib/Target/X86/X86InstrSystem.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86InstrSystem.td?rev=278144&r1=278143&r2=278144&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86InstrSystem.td (original)
+++ llvm/trunk/lib/Target/X86/X86InstrSystem.td Tue Aug  9 12:55:12 2016
@@ -23,7 +23,7 @@ let Defs = [RAX, RCX, RDX] in
 
 // CPU flow control instructions
 
-let isTerminator = 1, isBarrier = 1, hasCtrlDep = 1 in {
+let mayLoad = 1, mayStore = 0, hasSideEffects = 1 in {
   def TRAP    : I<0x0B, RawFrm, (outs), (ins), "ud2", [(trap)]>, TB;
   def UD2B    : I<0xB9, RawFrm, (outs), (ins), "ud2b", []>, TB;
 }

Modified: llvm/trunk/test/CodeGen/X86/x86-framelowering-trap.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/x86-framelowering-trap.ll?rev=278144&r1=278143&r2=278144&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/x86-framelowering-trap.ll (original)
+++ llvm/trunk/test/CodeGen/X86/x86-framelowering-trap.ll Tue Aug  9 12:55:12 2016
@@ -3,13 +3,18 @@ target datalayout = "e-m:e-i64:64-f80:12
 target triple = "x86_64-unknown-linux-gnu"
 
 ; CHECK-LABEL: bar:
+; CHECK: pushq
 ; CHECK: ud2
+; CHECK-NEXT: popq
 ; CHECK-NEXT: retq
 define void @bar() {
 entry:
+  call void @callee()
   call void @llvm.trap()
   ret void
 }
 
 ; Function Attrs: noreturn nounwind
 declare void @llvm.trap()
+
+declare void @callee()




More information about the llvm-commits mailing list