Disable the Thumb no-return call optimization:
authorEvan Cheng <evan.cheng@apple.com>
Sat, 10 Nov 2012 02:09:05 +0000 (02:09 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Sat, 10 Nov 2012 02:09:05 +0000 (02:09 +0000)
mov lr, pc
b.w _foo

The "mov" instruction doesn't set bit zero to one, it's putting incorrect
value in lr. It messes up backtraces.

rdar://12663632

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167657 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/ARM/ARMAsmPrinter.cpp
lib/Target/ARM/ARMISelLowering.cpp
lib/Target/ARM/ARMInstrThumb2.td
test/CodeGen/ARM/call-noret-minsize.ll
test/CodeGen/ARM/call-noret.ll

index 8e55a44c56d60588f25d0e41030718d8b0cd7db4..d439d1d7cb7eec4323f584693e65ffb8f45a4417 100644 (file)
@@ -1413,31 +1413,6 @@ void ARMAsmPrinter::EmitInstruction(const MachineInstr *MI) {
     }
     return;
   }
     }
     return;
   }
-  case ARM::t2BMOVPCB_CALL: {
-    {
-      MCInst TmpInst;
-      TmpInst.setOpcode(ARM::tMOVr);
-      TmpInst.addOperand(MCOperand::CreateReg(ARM::LR));
-      TmpInst.addOperand(MCOperand::CreateReg(ARM::PC));
-      // Add predicate operands.
-      TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL));
-      TmpInst.addOperand(MCOperand::CreateReg(0));
-      OutStreamer.EmitInstruction(TmpInst);
-    }
-    {
-      MCInst TmpInst;
-      TmpInst.setOpcode(ARM::t2B);
-      const GlobalValue *GV = MI->getOperand(0).getGlobal();
-      MCSymbol *GVSym = Mang->getSymbol(GV);
-      const MCExpr *GVSymExpr = MCSymbolRefExpr::Create(GVSym, OutContext);
-      TmpInst.addOperand(MCOperand::CreateExpr(GVSymExpr));
-      // Add predicate operands.
-      TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL));
-      TmpInst.addOperand(MCOperand::CreateReg(0));
-      OutStreamer.EmitInstruction(TmpInst);
-    }
-    return;
-  }
   case ARM::MOVi16_ga_pcrel:
   case ARM::t2MOVi16_ga_pcrel: {
     MCInst TmpInst;
   case ARM::MOVi16_ga_pcrel:
   case ARM::t2MOVi16_ga_pcrel: {
     MCInst TmpInst;
index 3b9558bc2a2279c8ba232f75b61461d71d3bc512..ff99b04078e853ce75defd8a6d17a66c97b0a8fe 100644 (file)
@@ -1599,18 +1599,12 @@ ARMTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
   if (Subtarget->isThumb()) {
     if ((!isDirect || isARMFunc) && !Subtarget->hasV5TOps())
       CallOpc = ARMISD::CALL_NOLINK;
   if (Subtarget->isThumb()) {
     if ((!isDirect || isARMFunc) && !Subtarget->hasV5TOps())
       CallOpc = ARMISD::CALL_NOLINK;
-    else if (doesNotRet && isDirect && !isARMFunc &&
-             Subtarget->hasRAS() && !Subtarget->isThumb1Only() &&
-             // Emit regular call when code size is the priority
-             !HasMinSizeAttr)
-      // "mov lr, pc; b _foo" to avoid confusing the RSP
-      CallOpc = ARMISD::CALL_NOLINK;
     else
       CallOpc = isARMFunc ? ARMISD::CALL : ARMISD::tCALL;
   } else {
     else
       CallOpc = isARMFunc ? ARMISD::CALL : ARMISD::tCALL;
   } else {
-    if (!isDirect && !Subtarget->hasV5TOps()) {
+    if (!isDirect && !Subtarget->hasV5TOps())
       CallOpc = ARMISD::CALL_NOLINK;
       CallOpc = ARMISD::CALL_NOLINK;
-    else if (doesNotRet && isDirect && Subtarget->hasRAS() &&
+    else if (doesNotRet && isDirect && Subtarget->hasRAS() &&
                // Emit regular call when code size is the priority
                !HasMinSizeAttr)
       // "mov lr, pc; b _foo" to avoid confusing the RSP
                // Emit regular call when code size is the priority
                !HasMinSizeAttr)
       // "mov lr, pc; b _foo" to avoid confusing the RSP
index 8e8489a26e66985f2ae2de3e7628185f1110c4ea..002d64a2d0399cd582331ed7b1f777636b236bfb 100644 (file)
@@ -3331,20 +3331,6 @@ let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in {
                  Requires<[IsThumb2, IsIOS]>;
 }
 
                  Requires<[IsThumb2, IsIOS]>;
 }
 
-let isCall = 1, Defs = [LR], Uses = [SP] in {
-  // mov lr, pc; b if callee is marked noreturn to avoid confusing the
-  // return stack predictor.
-  def t2BMOVPCB_CALL : tPseudoInst<(outs),
-                                   (ins t_bltarget:$func),
-                               6, IIC_Br, [(ARMcall_nolink tglobaladdr:$func)]>,
-                        Requires<[IsThumb]>;
-}
-
-// Direct calls
-def : T2Pat<(ARMcall_nolink texternalsym:$func),
-            (t2BMOVPCB_CALL texternalsym:$func)>,
-      Requires<[IsThumb]>;
-
 // IT block
 let Defs = [ITSTATE] in
 def t2IT : Thumb2XI<(outs), (ins it_pred:$cc, it_mask:$mask),
 // IT block
 let Defs = [ITSTATE] in
 def t2IT : Thumb2XI<(outs), (ins it_pred:$cc, it_mask:$mask),
index 35490ac69b1668f1b45842dec7cadd00cefae8d0..df3c19eca6a028df7309a282da02fb1bf13c0d00 100644 (file)
@@ -1,6 +1,5 @@
 ; RUN: llc < %s -mtriple=armv7-apple-ios -mcpu=cortex-a8   | FileCheck %s -check-prefix=ARM
 ; RUN: llc < %s -mtriple=armv7-apple-ios -mcpu=swift       | FileCheck %s -check-prefix=SWIFT
 ; RUN: llc < %s -mtriple=armv7-apple-ios -mcpu=cortex-a8   | FileCheck %s -check-prefix=ARM
 ; RUN: llc < %s -mtriple=armv7-apple-ios -mcpu=swift       | FileCheck %s -check-prefix=SWIFT
-; RUN: llc < %s -mtriple=thumbv7-apple-ios -mcpu=cortex-a8 | FileCheck %s -check-prefix=T2
 ; rdar://12348580
 
 define void @t1() noreturn minsize nounwind ssp {
 ; rdar://12348580
 
 define void @t1() noreturn minsize nounwind ssp {
@@ -10,9 +9,6 @@ entry:
 
 ; SWIFT: t1:
 ; SWIFT: bl _bar
 
 ; SWIFT: t1:
 ; SWIFT: bl _bar
-
-; T2: t1:
-; T2: blx _bar
   tail call void @bar() noreturn nounwind
   unreachable
 }
   tail call void @bar() noreturn nounwind
   unreachable
 }
@@ -24,9 +20,6 @@ entry:
 
 ; SWIFT: t2:
 ; SWIFT: bl _t1
 
 ; SWIFT: t2:
 ; SWIFT: bl _t1
-
-; T2: t2:
-; T2: bl _t1
   tail call void @t1() noreturn nounwind
   unreachable
 }
   tail call void @t1() noreturn nounwind
   unreachable
 }
index d294f2cf1abaf80021478fd54512ac31a000ff9c..27062dca38dced641fbc9f4fe7438f4de378b842 100644 (file)
@@ -1,6 +1,5 @@
 ; RUN: llc < %s -mtriple=armv7-apple-ios -mcpu=cortex-a8   | FileCheck %s -check-prefix=ARM
 ; RUN: llc < %s -mtriple=armv7-apple-ios -mcpu=swift       | FileCheck %s -check-prefix=SWIFT
 ; RUN: llc < %s -mtriple=armv7-apple-ios -mcpu=cortex-a8   | FileCheck %s -check-prefix=ARM
 ; RUN: llc < %s -mtriple=armv7-apple-ios -mcpu=swift       | FileCheck %s -check-prefix=SWIFT
-; RUN: llc < %s -mtriple=thumbv7-apple-ios -mcpu=cortex-a8 | FileCheck %s -check-prefix=T2
 ; rdar://8979299
 
 define void @t1() noreturn nounwind ssp {
 ; rdar://8979299
 
 define void @t1() noreturn nounwind ssp {
@@ -12,9 +11,6 @@ entry:
 ; SWIFT: t1:
 ; SWIFT: mov lr, pc
 ; SWIFT: b _bar
 ; SWIFT: t1:
 ; SWIFT: mov lr, pc
 ; SWIFT: b _bar
-
-; T2: t1:
-; T2: blx _bar
   tail call void @bar() noreturn nounwind
   unreachable
 }
   tail call void @bar() noreturn nounwind
   unreachable
 }
@@ -28,10 +24,6 @@ entry:
 ; SWIFT: t2:
 ; SWIFT: mov lr, pc
 ; SWIFT: b _t1
 ; SWIFT: t2:
 ; SWIFT: mov lr, pc
 ; SWIFT: b _t1
-
-; T2: t2:
-; T2: mov lr, pc
-; T2: b.w _t1
   tail call void @t1() noreturn nounwind
   unreachable
 }
   tail call void @t1() noreturn nounwind
   unreachable
 }