diff --git a/llvm/lib/Target/RISCV/RISCVMergeBaseOffset.cpp b/llvm/lib/Target/RISCV/RISCVMergeBaseOffset.cpp --- a/llvm/lib/Target/RISCV/RISCVMergeBaseOffset.cpp +++ b/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.