From 452b54a8aebee45088b2157a66ae0f9f6a9088fa Mon Sep 17 00:00:00 2001 From: Sandeep Patel Date: Thu, 15 Oct 2009 22:25:32 +0000 Subject: [PATCH] Branches must be the last instruction in a Thumb2 IT block. Approved by Evan Cheng. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84212 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/ARM/Thumb2ITBlockPass.cpp | 6 ++- .../Thumb2/2009-10-15-ITBlockBranch.ll | 44 +++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 test/CodeGen/Thumb2/2009-10-15-ITBlockBranch.ll diff --git a/lib/Target/ARM/Thumb2ITBlockPass.cpp b/lib/Target/ARM/Thumb2ITBlockPass.cpp index 98b5cbdfb98..427c0bb22b2 100644 --- a/lib/Target/ARM/Thumb2ITBlockPass.cpp +++ b/lib/Target/ARM/Thumb2ITBlockPass.cpp @@ -107,8 +107,12 @@ bool Thumb2ITBlockPass::InsertITBlocks(MachineBasicBlock &MBB) { // Finalize IT mask. ARMCC::CondCodes OCC = ARMCC::getOppositeCondition(CC); unsigned Mask = 0, Pos = 3; - while (MBBI != E && Pos) { + // Branches, including tricky ones like LDM_RET, need to end an IT + // block so check the instruction we just put in the block. + while (MBBI != E && Pos && + (!MI->getDesc().isBranch() && !MI->getDesc().isReturn())) { MachineInstr *NMI = &*MBBI; + MI = NMI; DebugLoc ndl = NMI->getDebugLoc(); unsigned NPredReg = 0; ARMCC::CondCodes NCC = getPredicate(NMI, NPredReg); diff --git a/test/CodeGen/Thumb2/2009-10-15-ITBlockBranch.ll b/test/CodeGen/Thumb2/2009-10-15-ITBlockBranch.ll new file mode 100644 index 00000000000..b4b6ed9ff39 --- /dev/null +++ b/test/CodeGen/Thumb2/2009-10-15-ITBlockBranch.ll @@ -0,0 +1,44 @@ +; RUN: llc < %s -mtriple=thumbv7-eabi -mcpu=cortex-a8 -float-abi=hard | FileCheck %s + +; A fix for PR5204 will require this check to be changed. + +%"struct.__gnu_cxx::__normal_iterator, std::allocator > >" = type { i8* } +%"struct.__gnu_cxx::new_allocator" = type <{ i8 }> +%"struct.std::basic_string,std::allocator >" = type { %"struct.__gnu_cxx::__normal_iterator, std::allocator > >" } +%"struct.std::basic_string,std::allocator >::_Rep" = type { %"struct.std::basic_string,std::allocator >::_Rep_base" } +%"struct.std::basic_string,std::allocator >::_Rep_base" = type { i32, i32, i32 } + + +define weak arm_aapcs_vfpcc i32 @_ZNKSs7compareERKSs(%"struct.std::basic_string,std::allocator >"* %this, %"struct.std::basic_string,std::allocator >"* %__str) { +; CHECK: _ZNKSs7compareERKSs: +; CHECK: it ne +; CHECK-NEXT: ldmfdne.w +; CHECK-NEXT: itt eq +; CHECK-NEXT: subeq.w +; CHECK-NEXT: ldmfdeq.w +entry: + %0 = tail call arm_aapcs_vfpcc i32 @_ZNKSs4sizeEv(%"struct.std::basic_string,std::allocator >"* %this) ; [#uses=3] + %1 = tail call arm_aapcs_vfpcc i32 @_ZNKSs4sizeEv(%"struct.std::basic_string,std::allocator >"* %__str) ; [#uses=3] + %2 = icmp ult i32 %1, %0 ; [#uses=1] + %3 = select i1 %2, i32 %1, i32 %0 ; [#uses=1] + %4 = tail call arm_aapcs_vfpcc i8* @_ZNKSs7_M_dataEv(%"struct.std::basic_string,std::allocator >"* %this) ; [#uses=1] + %5 = tail call arm_aapcs_vfpcc i8* @_ZNKSs4dataEv(%"struct.std::basic_string,std::allocator >"* %__str) ; [#uses=1] + %6 = tail call arm_aapcs_vfpcc i32 @memcmp(i8* %4, i8* %5, i32 %3) nounwind readonly ; [#uses=2] + %7 = icmp eq i32 %6, 0 ; [#uses=1] + br i1 %7, label %bb, label %bb1 + +bb: ; preds = %entry + %8 = sub i32 %0, %1 ; [#uses=1] + ret i32 %8 + +bb1: ; preds = %entry + ret i32 %6 +} + +declare arm_aapcs_vfpcc i32 @memcmp(i8* nocapture, i8* nocapture, i32) nounwind readonly + +declare arm_aapcs_vfpcc i32 @_ZNKSs4sizeEv(%"struct.std::basic_string,std::allocator >"* %this) + +declare arm_aapcs_vfpcc i8* @_ZNKSs7_M_dataEv(%"struct.std::basic_string,std::allocator >"* %this) + +declare arm_aapcs_vfpcc i8* @_ZNKSs4dataEv(%"struct.std::basic_string,std::allocator >"* %this)