[llvm] deaeb16 - [RISCV] Indicate that RISCVMergeBaseOffsetOpt preserves the CFG.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 3 08:42:00 PDT 2021
Author: Craig Topper
Date: 2021-08-03T08:32:36-07:00
New Revision: deaeb16d88e92be644a157d499e9862cde4f22aa
URL: https://github.com/llvm/llvm-project/commit/deaeb16d88e92be644a157d499e9862cde4f22aa
DIFF: https://github.com/llvm/llvm-project/commit/deaeb16d88e92be644a157d499e9862cde4f22aa.diff
LOG: [RISCV] Indicate that RISCVMergeBaseOffsetOpt preserves the CFG.
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.
Differential Revision: https://reviews.llvm.org/D107303
Added:
Modified:
llvm/lib/Target/RISCV/RISCVMergeBaseOffset.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVMergeBaseOffset.cpp b/llvm/lib/Target/RISCV/RISCVMergeBaseOffset.cpp
index 87586023caa4..70d15d6af566 100644
--- a/llvm/lib/Target/RISCV/RISCVMergeBaseOffset.cpp
+++ b/llvm/lib/Target/RISCV/RISCVMergeBaseOffset.cpp
@@ -53,6 +53,11 @@ struct RISCVMergeBaseOffsetOpt : public MachineFunctionPass {
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 @@ bool RISCVMergeBaseOffsetOpt::detectAndFoldOffset(MachineInstr &HiLUI,
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 @@ bool RISCVMergeBaseOffsetOpt::detectAndFoldOffset(MachineInstr &HiLUI,
return false;
foldOffset(HiLUI, LoADDI, Tail, Offset);
return true;
- } break;
+ }
case RISCV::LB:
case RISCV::LH:
case RISCV::LW:
@@ -252,7 +257,7 @@ bool RISCVMergeBaseOffsetOpt::detectAndFoldOffset(MachineInstr &HiLUI,
Tail.getOperand(1).setReg(HiLUI.getOperand(0).getReg());
DeadInstrs.insert(&LoADDI);
return true;
- } break;
+ }
}
return false;
}
@@ -261,6 +266,7 @@ bool RISCVMergeBaseOffsetOpt::runOnMachineFunction(MachineFunction &Fn) {
if (skipFunction(Fn.getFunction()))
return false;
+ bool MadeChange = false;
DeadInstrs.clear();
MRI = &Fn.getRegInfo();
for (MachineBasicBlock &MBB : Fn) {
@@ -272,13 +278,13 @@ bool RISCVMergeBaseOffsetOpt::runOnMachineFunction(MachineFunction &Fn) {
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.
More information about the llvm-commits
mailing list