Skip to content

Commit

Permalink
[AIEX] Fix AIEEliminateDuplicatePHI pass
Browse files Browse the repository at this point in the history
  • Loading branch information
krishnamtibrewala committed Sep 17, 2024
1 parent ded6c50 commit 46f23e1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 9 deletions.
12 changes: 3 additions & 9 deletions llvm/lib/Target/AIE/AIEEliminateDuplicatePHI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,12 @@ class AIEEliminateDuplicatePHI : public MachineFunctionPass {
bool processMBB(MachineBasicBlock &MBB, MachineRegisterInfo &MRI,
MachineIRBuilder &MIB, GISelObserverWrapper &Observer) {
bool Changed = false;
auto LastPHI = MBB.getFirstNonPHI();
auto FirstNonPHI = MBB.getFirstNonPHI();
for (auto &MI : make_early_inc_range(MBB.phis())) {
if (!isPointerTypePHI(MRI, MI))
continue;

// Ensure that next MI is valid
auto NextMI = std::next(MachineBasicBlock::instr_iterator(MI));
if (NextMI == MBB.instr_end() || NextMI == LastPHI)
break;

for (auto &PHI : make_early_inc_range(make_range(
NextMI, MachineBasicBlock::instr_iterator(*LastPHI)))) {
for (auto &PHI : make_early_inc_range(
make_range(++MachineBasicBlock::iterator(MI), FirstNonPHI))) {
if (!isPointerTypePHI(MRI, PHI))
continue;
if (MI.isIdenticalTo(PHI, MachineInstr::IgnoreDefs)) {
Expand Down
50 changes: 50 additions & 0 deletions llvm/test/CodeGen/AIE/GlobalISel/eliminate-duplicate-phi.mir
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,53 @@ body: |
%5:_(p0) = G_PTR_ADD %3:_, %4:_(s20)
G_BR %bb.4
...

---
name: test_two_PHI_nobranch
legalized: false
tracksRegLiveness: true
body: |
; CHECK-LABEL: name: test_two_PHI_nobranch
; CHECK: bb.0:
; CHECK-NEXT: successors: %bb.1(0x40000000), %bb.2(0x40000000)
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
; CHECK-NEXT: [[C1:%[0-9]+]]:_(p0) = G_CONSTANT i20 1
; CHECK-NEXT: [[C2:%[0-9]+]]:_(p0) = G_CONSTANT i20 2
; CHECK-NEXT: G_BRCOND [[C]](s32), %bb.1
; CHECK-NEXT: G_BR %bb.2
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: bb.1:
; CHECK-NEXT: successors: %bb.3(0x80000000)
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: G_BR %bb.3
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: bb.2:
; CHECK-NEXT: successors: %bb.3(0x80000000)
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: G_BR %bb.3
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: bb.3:
; CHECK-NEXT: successors: %bb.4(0x80000000)
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: [[PHI:%[0-9]+]]:_(p0) = G_PHI [[C1]](p0), %bb.1, [[C2]](p0), %bb.2
; CHECK-NEXT: [[PHI1:%[0-9]+]]:_(p0) = G_PHI [[C1]](p0), %bb.1, [[C2]](p0), %bb.2
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: bb.4:
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(p0) = COPY [[PHI]](p0)
bb.0:
%1:_(s32) = G_CONSTANT i32 0
%2:_(p0) = G_CONSTANT i20 1
%3:_(p0) = G_CONSTANT i20 2
G_BRCOND %1:_(s32), %bb.1
G_BR %bb.2
bb.1:
G_BR %bb.3
bb.2:
G_BR %bb.3
bb.3:
%4:_(p0) = G_PHI %2:_(p0), %bb.1, %3:_(p0), %bb.2
%5:_(p0) = G_PHI %2:_(p0), %bb.1, %3:_(p0), %bb.2
bb.4:
%6:_(p0) = COPY %5:_(p0)
...

0 comments on commit 46f23e1

Please sign in to comment.