From de65337f1810667a6a5bd771fdea3457295972c9 Mon Sep 17 00:00:00 2001 From: Ahmed Bougacha Date: Tue, 21 Mar 2017 23:42:50 +0000 Subject: [PATCH] [GlobalISel] Don't translate br to layout successor. MI can represent fallthrough to layout successor blocks, and our post-isel representation uses that extensively. We might as well use it too, to avoid translating and carrying along unnecessary branches. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298459 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/GlobalISel/IRTranslator.cpp | 7 +++- .../AArch64/GlobalISel/arm64-irtranslator.ll | 37 +++++++++++++++---- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/lib/CodeGen/GlobalISel/IRTranslator.cpp b/lib/CodeGen/GlobalISel/IRTranslator.cpp index b6e6fbd03d0..b3f131b5eeb 100644 --- a/lib/CodeGen/GlobalISel/IRTranslator.cpp +++ b/lib/CodeGen/GlobalISel/IRTranslator.cpp @@ -223,10 +223,13 @@ bool IRTranslator::translateBr(const User &U, MachineIRBuilder &MIRBuilder) { const BasicBlock &BrTgt = *cast(BrInst.getSuccessor(Succ)); MachineBasicBlock &TgtBB = getMBB(BrTgt); - MIRBuilder.buildBr(TgtBB); + MachineBasicBlock &CurBB = MIRBuilder.getMBB(); + + // If the unconditional target is the layout successor, fallthrough. + if (!CurBB.isLayoutSuccessor(&TgtBB)) + MIRBuilder.buildBr(TgtBB); // Link successors. - MachineBasicBlock &CurBB = MIRBuilder.getMBB(); for (const BasicBlock *Succ : BrInst.successors()) CurBB.addSuccessor(&getMBB(*Succ)); return true; diff --git a/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll b/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll index 73411983c06..d837968ed2e 100644 --- a/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll +++ b/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll @@ -52,18 +52,40 @@ define void @allocai64() { ; CHECK: body: ; ; ABI/constant lowering and IR-level entry basic block. -; CHECK: {{bb.[0-9]+}} (%ir-block.{{[0-9]+}}): +; CHECK: {{bb.[0-9]+}}.entry: ; ; Make sure we have one successor and only one. -; CHECK-NEXT: successors: %[[END:bb.[0-9]+.end]](0x80000000) +; CHECK-NEXT: successors: %[[BB2:bb.[0-9]+.bb2]](0x80000000) ; ; Check that we emit the correct branch. -; CHECK: G_BR %[[END]] +; CHECK: G_BR %[[BB2]] ; ; Check that end contains the return instruction. -; CHECK: [[END]]: +; CHECK: [[END:bb.[0-9]+.end]]: ; CHECK-NEXT: RET_ReallyLR +; +; CHECK: {{bb.[0-9]+}}.bb2: +; CHECK-NEXT: successors: %[[END]](0x80000000) +; CHECK: G_BR %[[END]] define void @uncondbr() { +entry: + br label %bb2 +end: + ret void +bb2: + br label %end +} + +; CHECK-LABEL: name: uncondbr_fallthrough +; CHECK: body: +; CHECK: {{bb.[0-9]+}}.entry: +; CHECK-NEXT: successors: %[[END:bb.[0-9]+.end]](0x80000000) +; We don't emit a branch here, as we can fallthrough to the successor. +; CHECK-NOT: G_BR +; CHECK: [[END]]: +; CHECK-NEXT: RET_ReallyLR +define void @uncondbr_fallthrough() { +entry: br label %end end: ret void @@ -140,7 +162,6 @@ false: ; CHECK: [[BB_CASE200]]: ; CHECK-NEXT: successors: %[[BB_RET]](0x80000000) ; CHECK: %[[regretc200:[0-9]+]](s32) = G_ADD %0, %[[reg2]] -; CHECK: G_BR %[[BB_RET]] ; ; CHECK: [[BB_RET]]: ; CHECK-NEXT: %[[regret:[0-9]+]](s32) = PHI %[[regretdefault]](s32), %[[BB_DEFAULT]], %[[regretc100]](s32), %[[BB_CASE100]] @@ -232,7 +253,7 @@ phi.block: ; CHECK: {{bb.[0-9]+.entry}}: ; Make sure we have one successor ; CHECK-NEXT: successors: %[[BB_L1:bb.[0-9]+.L1]](0x80000000) -; CHECK: G_BR %[[BB_L1]] +; CHECK-NOT: G_BR ; ; Check basic block L1 has 2 successors: BBL1 and BBL2 ; CHECK: [[BB_L1]] (address-taken): @@ -525,8 +546,8 @@ define void @unreachable(i32 %a) { ; CHECK-LABEL: name: constant_int ; CHECK: [[IN:%[0-9]+]](s32) = COPY %w0 ; CHECK: [[ONE:%[0-9]+]](s32) = G_CONSTANT i32 1 -; CHECK: G_BR +; CHECK: {{bb.[0-9]+}}.next: ; CHECK: [[SUM1:%[0-9]+]](s32) = G_ADD [[IN]], [[ONE]] ; CHECK: [[SUM2:%[0-9]+]](s32) = G_ADD [[IN]], [[ONE]] ; CHECK: [[RES:%[0-9]+]](s32) = G_ADD [[SUM1]], [[SUM2]] @@ -1181,7 +1202,7 @@ define i8* @test_const_placement() { ; CHECK: bb.{{[0-9]+}} (%ir-block.{{[0-9]+}}): ; CHECK: [[VAL_INT:%[0-9]+]](s32) = G_CONSTANT i32 42 ; CHECK: [[VAL:%[0-9]+]](p0) = G_INTTOPTR [[VAL_INT]](s32) -; CHECK: G_BR +; CHECK: {{bb.[0-9]+}}.next: br label %next next: -- 2.40.0