Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 59a658d

Browse files
committed
[GlobalISel][IRTranslator] Use RPO traversal when visiting blocks to translate.
Previously we were just visiting the blocks in the function in IR order, which is rather arbitrary. Therefore we wouldn't always visit defs before uses, but the translation code relies on this assumption in some places. Only codegen change seen in tests is an elision of a redundant copy. Fixes PR38396 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338476 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent b47f061 commit 59a658d

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

lib/CodeGen/GlobalISel/IRTranslator.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "llvm/CodeGen/GlobalISel/IRTranslator.h"
14+
#include "llvm/ADT/PostOrderIterator.h"
1415
#include "llvm/ADT/STLExtras.h"
1516
#include "llvm/ADT/ScopeExit.h"
1617
#include "llvm/ADT/SmallSet.h"
@@ -33,6 +34,7 @@
3334
#include "llvm/CodeGen/TargetRegisterInfo.h"
3435
#include "llvm/CodeGen/TargetSubtargetInfo.h"
3536
#include "llvm/IR/BasicBlock.h"
37+
#include "llvm/IR/CFG.h"
3638
#include "llvm/IR/Constant.h"
3739
#include "llvm/IR/Constants.h"
3840
#include "llvm/IR/DataLayout.h"
@@ -1613,19 +1615,20 @@ bool IRTranslator::runOnMachineFunction(MachineFunction &CurMF) {
16131615
ArgIt++;
16141616
}
16151617

1616-
// And translate the function!
1617-
for (const BasicBlock &BB : F) {
1618-
MachineBasicBlock &MBB = getMBB(BB);
1618+
// Need to visit defs before uses when translating instructions.
1619+
ReversePostOrderTraversal<const Function *> RPOT(&F);
1620+
for (const BasicBlock *BB : RPOT) {
1621+
MachineBasicBlock &MBB = getMBB(*BB);
16191622
// Set the insertion point of all the following translations to
16201623
// the end of this basic block.
16211624
CurBuilder.setMBB(MBB);
16221625

1623-
for (const Instruction &Inst : BB) {
1626+
for (const Instruction &Inst : *BB) {
16241627
if (translate(Inst))
16251628
continue;
16261629

16271630
OptimizationRemarkMissed R("gisel-irtranslator", "GISelFailure",
1628-
Inst.getDebugLoc(), &BB);
1631+
Inst.getDebugLoc(), BB);
16291632
R << "unable to translate instruction: " << ore::NV("Opcode", &Inst);
16301633

16311634
if (ORE->allowExtraAnalysis("gisel-irtranslator")) {

test/CodeGen/AArch64/GlobalISel/arm64-fallback.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ define fp128 @test_quad_dump() {
141141
ret fp128 0xL00000000000000004000000000000000
142142
}
143143

144-
; FALLBACK-WITH-REPORT-ERR: remark: <unknown>:0:0: unable to legalize instruction: %0:_(p0) = G_EXTRACT_VECTOR_ELT %1:_(<2 x p0>), %2:_(s32) (in function: vector_of_pointers_extractelement)
144+
; FALLBACK-WITH-REPORT-ERR: remark: <unknown>:0:0: unable to legalize instruction: %2:_(p0) = G_EXTRACT_VECTOR_ELT %0:_(<2 x p0>), %3:_(s32) (in function: vector_of_pointers_extractelement)
145145
; FALLBACK-WITH-REPORT-ERR: warning: Instruction selection used fallback path for vector_of_pointers_extractelement
146146
; FALLBACK-WITH-REPORT-OUT-LABEL: vector_of_pointers_extractelement:
147147
@var = global <2 x i16*> zeroinitializer
@@ -158,7 +158,7 @@ end:
158158
br label %block
159159
}
160160

161-
; FALLBACK-WITH-REPORT-ERR: remark: <unknown>:0:0: unable to legalize instruction: G_STORE %0:_(<2 x p0>), %5:_(p0) :: (store 16 into `<2 x i16*>* undef`) (in function: vector_of_pointers_insertelement)
161+
; FALLBACK-WITH-REPORT-ERR: remark: <unknown>:0:0: unable to legalize instruction: G_STORE %2:_(<2 x p0>), %1:_(p0) :: (store 16 into `<2 x i16*>* undef`) (in function: vector_of_pointers_insertelement)
162162
; FALLBACK-WITH-REPORT-ERR: warning: Instruction selection used fallback path for vector_of_pointers_insertelement
163163
; FALLBACK-WITH-REPORT-OUT-LABEL: vector_of_pointers_insertelement:
164164
define void @vector_of_pointers_insertelement() {

test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ false:
138138
; CHECK: %0:_(s32) = COPY $w0
139139
; CHECK: %[[reg100:[0-9]+]]:_(s32) = G_CONSTANT i32 100
140140
; CHECK: %[[reg200:[0-9]+]]:_(s32) = G_CONSTANT i32 200
141-
; CHECK: %[[reg0:[0-9]+]]:_(s32) = G_CONSTANT i32 0
142-
; CHECK: %[[reg1:[0-9]+]]:_(s32) = G_CONSTANT i32 1
143141
; CHECK: %[[reg2:[0-9]+]]:_(s32) = G_CONSTANT i32 2
142+
; CHECK: %[[reg1:[0-9]+]]:_(s32) = G_CONSTANT i32 1
143+
; CHECK: %[[reg0:[0-9]+]]:_(s32) = G_CONSTANT i32 0
144144
; CHECK: %[[regicmp100:[0-9]+]]:_(s1) = G_ICMP intpred(eq), %[[reg100]](s32), %0
145145
; CHECK: G_BRCOND %[[regicmp100]](s1), %[[BB_CASE100]]
146146
; CHECK: G_BR %[[BB_NOTCASE100_CHECKNEXT]]
@@ -413,9 +413,9 @@ define i64* @trivial_bitcast(i8* %a) {
413413
; CHECK: G_BR %[[CAST:bb\.[0-9]+]]
414414

415415
; CHECK: [[END:bb\.[0-9]+]].{{[a-zA-Z0-9.]+}}:
416+
; CHECK: $x0 = COPY [[A]]
416417

417418
; CHECK: [[CAST]].{{[a-zA-Z0-9.]+}}:
418-
; CHECK: {{%[0-9]+}}:_(p0) = COPY [[A]]
419419
; CHECK: G_BR %[[END]]
420420
define i64* @trivial_bitcast_with_copy(i8* %a) {
421421
br label %cast
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; RUN: llc -O0 -o - %s | FileCheck %s
2+
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
3+
target triple = "aarch64-unknown-linux-gnu"
4+
5+
; CHECK-LABEL: testfn
6+
; CHECK: ret
7+
define void @testfn() {
8+
start:
9+
br label %bb2
10+
11+
bb1:
12+
store i8 %0, i8* undef, align 4
13+
ret void
14+
15+
bb2:
16+
%0 = extractvalue { i32, i8 } undef, 1
17+
br label %bb1
18+
}
19+

0 commit comments

Comments
 (0)