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

Commit cc4b526

Browse files
aemersoncramertj
authored andcommitted
[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 0fac2fc commit cc4b526

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

lib/CodeGen/GlobalISel/IRTranslator.cpp

+8-5
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"
@@ -32,6 +33,7 @@
3233
#include "llvm/CodeGen/TargetRegisterInfo.h"
3334
#include "llvm/CodeGen/TargetSubtargetInfo.h"
3435
#include "llvm/IR/BasicBlock.h"
36+
#include "llvm/IR/CFG.h"
3537
#include "llvm/IR/Constant.h"
3638
#include "llvm/IR/Constants.h"
3739
#include "llvm/IR/DataLayout.h"
@@ -1593,19 +1595,20 @@ bool IRTranslator::runOnMachineFunction(MachineFunction &CurMF) {
15931595
ArgIt++;
15941596
}
15951597

1596-
// And translate the function!
1597-
for (const BasicBlock &BB : F) {
1598-
MachineBasicBlock &MBB = getMBB(BB);
1598+
// Need to visit defs before uses when translating instructions.
1599+
ReversePostOrderTraversal<const Function *> RPOT(&F);
1600+
for (const BasicBlock *BB : RPOT) {
1601+
MachineBasicBlock &MBB = getMBB(*BB);
15991602
// Set the insertion point of all the following translations to
16001603
// the end of this basic block.
16011604
CurBuilder.setMBB(MBB);
16021605

1603-
for (const Instruction &Inst : BB) {
1606+
for (const Instruction &Inst : *BB) {
16041607
if (translate(Inst))
16051608
continue;
16061609

16071610
OptimizationRemarkMissed R("gisel-irtranslator", "GISelFailure",
1608-
Inst.getDebugLoc(), &BB);
1611+
Inst.getDebugLoc(), BB);
16091612
R << "unable to translate instruction: " << ore::NV("Opcode", &Inst);
16101613

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

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

+2-2
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

+3-3
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
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)