[PATCH] D107303: [RISCV] Indicate that RISCVMergeBaseOffsetOpt preserves the CFG.
Craig Topper via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 2 12:36:34 PDT 2021
craig.topper created this revision.
craig.topper added reviewers: asb, luismarques, frasercrmck, evandro, HsiangKai, khchen, arcbbb, jrtc27.
Herald added subscribers: StephenFan, vkmr, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya.
craig.topper requested review of this revision.
Herald added a subscriber: MaskRay.
Herald added a project: LLVM.
Return false from runOnFunction if nothing changed. Curiously
we already returned a bool from detectAndFoldOffset, but didn't
use it.
Fix a couple breaks after returns that I saw while auditing
detectAndFoldOffset.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D107303
Files:
llvm/lib/Target/RISCV/RISCVMergeBaseOffset.cpp
Index: llvm/lib/Target/RISCV/RISCVMergeBaseOffset.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVMergeBaseOffset.cpp
+++ llvm/lib/Target/RISCV/RISCVMergeBaseOffset.cpp
@@ -53,6 +53,11 @@
MachineFunctionProperties::Property::IsSSA);
}
+ void getAnalysisUsage(AnalysisUsage &AU) const override {
+ AU.setPreservesCFG();
+ MachineFunctionPass::getAnalysisUsage(AU);
+ }
+
StringRef getPassName() const override {
return RISCV_MERGE_BASE_OFFSET_NAME;
}
@@ -193,7 +198,7 @@
LLVM_DEBUG(dbgs() << " Offset Instr: " << Tail);
foldOffset(HiLUI, LoADDI, Tail, Offset);
return true;
- } break;
+ }
case RISCV::ADD: {
// The offset is too large to fit in the immediate field of ADDI.
// This can be in two forms:
@@ -208,7 +213,7 @@
return false;
foldOffset(HiLUI, LoADDI, Tail, Offset);
return true;
- } break;
+ }
case RISCV::LB:
case RISCV::LH:
case RISCV::LW:
@@ -252,7 +257,7 @@
Tail.getOperand(1).setReg(HiLUI.getOperand(0).getReg());
DeadInstrs.insert(&LoADDI);
return true;
- } break;
+ }
}
return false;
}
@@ -261,6 +266,7 @@
if (skipFunction(Fn.getFunction()))
return false;
+ bool MadeChange = false;
DeadInstrs.clear();
MRI = &Fn.getRegInfo();
for (MachineBasicBlock &MBB : Fn) {
@@ -272,13 +278,13 @@
LLVM_DEBUG(dbgs() << " Found lowered global address with one use: "
<< *LoADDI->getOperand(2).getGlobal() << "\n");
// If the use count is only one, merge the offset
- detectAndFoldOffset(HiLUI, *LoADDI);
+ MadeChange |= detectAndFoldOffset(HiLUI, *LoADDI);
}
}
// Delete dead instructions.
for (auto *MI : DeadInstrs)
MI->eraseFromParent();
- return true;
+ return MadeChange;
}
/// Returns an instance of the Merge Base Offset Optimization pass.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107303.363547.patch
Type: text/x-patch
Size: 1917 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210802/715a92aa/attachment.bin>
More information about the llvm-commits
mailing list