Skip to content

Commit 096312c

Browse files
[EraVM] Run MachineCopyPropagation Pass one more time
Run MCP one more time after pseudo expansion, since we can produce copy like instructions (e.g. from PTR_TO_INT) that can be optimized. This patch implements isCopyInstrImpl target hook which is called from MCP to detect copy instructions after expansion from COPY is performed. Signed-off-by: Vladimir Radosavljevic <[email protected]>
1 parent b263c01 commit 096312c

File tree

5 files changed

+17
-2
lines changed

5 files changed

+17
-2
lines changed

llvm/lib/Target/EraVM/EraVMInstrInfo.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,16 @@ EraVMCC::CondCodes EraVMInstrInfo::getCCCode(const MachineInstr &MI) const {
732732
return EraVMCC::COND_INVALID;
733733
}
734734

735+
std::optional<DestSourcePair>
736+
EraVMInstrInfo::isCopyInstrImpl(const MachineInstr &MI) const {
737+
if (MI.getOpcode() == EraVM::ADDrrr_s &&
738+
MI.getOperand(2).getReg() == EraVM::R0 &&
739+
getCCCode(MI) == EraVMCC::COND_NONE) {
740+
return DestSourcePair{MI.getOperand(0), MI.getOperand(1)};
741+
}
742+
return std::nullopt;
743+
}
744+
735745
/// Return whether outlining candidate ends with a tail call. This is true only
736746
/// if it is a terminator that ends function, call to outlined function that
737747
/// ends with a tail call, or call to a no return function.

llvm/lib/Target/EraVM/EraVMInstrInfo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,9 @@ class EraVMInstrInfo : public EraVMGenInstrInfo {
406406
// return true if the update is successful
407407
bool updateCCCode(MachineInstr &MI, EraVMCC::CondCodes CC) const;
408408

409+
std::optional<DestSourcePair>
410+
isCopyInstrImpl(const MachineInstr &MI) const override;
411+
409412
unsigned defaultOutlineReruns() const override { return 5; }
410413

411414
bool shouldOutlineFromFunctionByDefault(MachineFunction &MF) const override;

llvm/lib/Target/EraVM/EraVMTargetMachine.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ void EraVMPassConfig::addPreSched2() {
319319
}
320320

321321
void EraVMPassConfig::addPreEmitPass() {
322+
if (getOptLevel() != CodeGenOpt::None)
323+
addPass(createMachineCopyPropagationPass(true));
322324
addPass(createEraVMCombineAddressingModePass());
323325
addPass(createEraVMExpandSelectPass());
324326
addPass(createEraVMOptimizeSelectPostRAPass());

llvm/test/CodeGen/EraVM/O3-pipeline.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ target triple = "eravm"
200200
; CHECK-NEXT: Branch Probability Basic Block Placement
201201
; CHECK-NEXT: Insert fentry calls
202202
; CHECK-NEXT: Insert XRay ops
203+
; CHECK-NEXT: Machine Copy Propagation Pass
203204
; CHECK-NEXT: ReachingDefAnalysis
204205
; CHECK-NEXT: MachineDominator Tree Construction
205206
; CHECK-NEXT: EraVM combine instuctions to use complex addressing modes

llvm/test/CodeGen/EraVM/machine-cp.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ target triple = "eravm"
77
define i256 @test(i256 %dummy, ptr addrspace(3) %0) {
88
; CHECK-LABEL: test:
99
; CHECK: ; %bb.0:
10-
; CHECK-NEXT: add r2, r0, r1
11-
; CHECK-NEXT: and 255, r1, r1
10+
; CHECK-NEXT: and 255, r2, r1
1211
; CHECK-NEXT: ret
1312
%ptrtoint = ptrtoint ptr addrspace(3) %0 to i256
1413
%and = and i256 %ptrtoint, 255

0 commit comments

Comments
 (0)