Skip to content

Commit 5044dd4

Browse files
committed
[EXTERNAL] Cherry-pick llvm/llvm-project#148205
1 parent 4423eaf commit 5044dd4

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

external/llvm-project/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,6 +1657,7 @@ bool SIFoldOperandsImpl::foldInstOperand(MachineInstr &MI,
16571657
for (MachineInstr *Copy : CopiesToReplace)
16581658
Copy->addImplicitDefUseOperands(*MF);
16591659

1660+
SetVector<MachineInstr *> ConstantFoldCandidates;
16601661
for (FoldCandidate &Fold : FoldList) {
16611662
assert(!Fold.isReg() || Fold.OpToFold);
16621663
if (Fold.isReg() && Fold.OpToFold->getReg().isVirtual()) {
@@ -1679,16 +1680,21 @@ bool SIFoldOperandsImpl::foldInstOperand(MachineInstr &MI,
16791680
<< static_cast<int>(Fold.UseOpNo) << " of "
16801681
<< *Fold.UseMI);
16811682

1682-
if (Fold.isImm() && tryConstantFoldOp(Fold.UseMI)) {
1683-
LLVM_DEBUG(dbgs() << "Constant folded " << *Fold.UseMI);
1684-
Changed = true;
1683+
if (Fold.isImm()) {
1684+
ConstantFoldCandidates.insert(Fold.UseMI);
16851685
}
16861686

16871687
} else if (Fold.Commuted) {
16881688
// Restoring instruction's original operand order if fold has failed.
16891689
TII->commuteInstruction(*Fold.UseMI, false);
16901690
}
16911691
}
1692+
for (MachineInstr *MI : ConstantFoldCandidates) {
1693+
if (tryConstantFoldOp(MI)) {
1694+
LLVM_DEBUG(dbgs() << "Constant folded " << *MI);
1695+
Changed = true;
1696+
}
1697+
}
16921698
return true;
16931699
}
16941700

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5
2+
# RUN: llc -mtriple=amdgcn-amd-hsa -mcpu=gfx1031 -run-pass=si-fold-operands -o - %s | FileCheck %s
3+
---
4+
name: snork
5+
body: |
6+
bb.0:
7+
; CHECK-LABEL: name: snork
8+
; CHECK: [[S_MOV_B32_:%[0-9]+]]:sreg_32 = S_MOV_B32 0
9+
; CHECK-NEXT: [[REG_SEQUENCE:%[0-9]+]]:sgpr_128 = REG_SEQUENCE [[S_MOV_B32_]], %subreg.sub0, [[S_MOV_B32_]], %subreg.sub1, [[S_MOV_B32_]], %subreg.sub2, [[S_MOV_B32_]], %subreg.sub3
10+
; CHECK-NEXT: SI_RETURN
11+
%0:sreg_32 = S_MOV_B32 0
12+
%1:sgpr_128 = REG_SEQUENCE %0, %subreg.sub0, %0, %subreg.sub1, %0, %subreg.sub2, %0, %subreg.sub3
13+
%2:sreg_32 = S_OR_B32 %1.sub0, %1.sub3, implicit-def dead $scc
14+
SI_RETURN
15+
...

0 commit comments

Comments
 (0)