Skip to content

Commit 1cf517d

Browse files
[EVM] Disable some optimizations at -O1
Since -O1 will be used during development, skip slower and debug-unfriendly optimizations at this level. Signed-off-by: Vladimir Radosavljevic <vr@matterlabs.dev>
1 parent a33d492 commit 1cf517d

File tree

2 files changed

+166
-4
lines changed

2 files changed

+166
-4
lines changed

llvm/lib/Target/EVM/EVMTargetMachine.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,11 @@ void EVMTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
159159
[](FunctionPassManager &PM, OptimizationLevel Level) {
160160
if (Level.getSizeLevel() || Level.getSpeedupLevel() > 1)
161161
PM.addPass(MergeIdenticalBBPass());
162-
if (Level.isOptimizingForSpeed())
162+
163+
// Don't run this pass if optimizing for size, since result of SHA3
164+
// calls will be replaced with a 32-byte constant, thus PUSH32 will
165+
// be emitted. This will increase code size.
166+
if (!Level.getSizeLevel() && Level.getSpeedupLevel() > 1)
163167
PM.addPass(EVMSHA3ConstFoldingPass());
164168
});
165169

@@ -170,7 +174,7 @@ void EVMTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
170174
PB.registerOptimizerLastEPCallback([](ModulePassManager &PM,
171175
OptimizationLevel Level,
172176
ThinOrFullLTOPhase Phase) {
173-
if (Level != OptimizationLevel::O0)
177+
if (Level.getSpeedupLevel() > 1)
174178
// Earlier transformations may expose new opportunities for DSE,
175179
// so we run it again.
176180
PM.addPass(createModuleToFunctionPassAdaptor(DSEPass()));
@@ -246,7 +250,7 @@ class EVMPassConfig final : public TargetPassConfig {
246250

247251
void EVMPassConfig::addIRPasses() {
248252
addPass(createEVMLowerIntrinsicsPass());
249-
if (TM->getOptLevel() != CodeGenOptLevel::None) {
253+
if (TM->getOptLevel() > CodeGenOptLevel::Less) {
250254
addPass(createEarlyCSEPass(true));
251255
addPass(createGVNPass());
252256
// Tests show that running the DSE pass at the end of the optimization
@@ -256,9 +260,12 @@ void EVMPassConfig::addIRPasses() {
256260
.hoistCommonInsts(true)
257261
.sinkCommonInsts(true)));
258262
addPass(createLICMPass());
263+
}
264+
if (TM->getOptLevel() != CodeGenOptLevel::None) {
259265
addPass(createEVMAAWrapperPass());
260266
addPass(createEVMExternalAAWrapperPass());
261267
}
268+
262269
TargetPassConfig::addIRPasses();
263270
}
264271

@@ -325,7 +332,7 @@ void EVMPassConfig::addPreEmitPass() {
325332
// Optimize branch instructions after stackification. This is done again
326333
// here, since EVMSplitCriticalEdges may introduce new BBs that could
327334
// contain only branches after stackification.
328-
if (getOptLevel() != CodeGenOptLevel::None) {
335+
if (getOptLevel() > CodeGenOptLevel::Less) {
329336
addPass(&BranchFolderPassID);
330337
addPass(&TailDuplicateLegacyID);
331338
}
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
; RUN: llc -O1 -debug-pass=Structure < %s -o /dev/null 2>&1 | FileCheck %s
2+
target triple = "evm"
3+
4+
; REQUIRES: asserts
5+
6+
; CHECK-LABEL: Pass Arguments:
7+
; CHECK-NEXT: Target Library Information
8+
; CHECK-NEXT: Target Pass Configuration
9+
; CHECK-NEXT: Machine Module Information
10+
; CHECK-NEXT: Target Transform Information
11+
; CHECK-NEXT: EVM Address space based Alias Analysis
12+
; CHECK-NEXT: EVM Address space based Alias Analysis Wrapper
13+
; CHECK-NEXT: Type-Based Alias Analysis
14+
; CHECK-NEXT: Scoped NoAlias Alias Analysis
15+
; CHECK-NEXT: Assumption Cache Tracker
16+
; CHECK-NEXT: Profile summary info
17+
; CHECK-NEXT: Create Garbage Collector Module Metadata
18+
; CHECK-NEXT: Machine Branch Probability Analysis
19+
; CHECK-NEXT: ModulePass Manager
20+
; CHECK-NEXT: Pre-ISel Intrinsic Lowering
21+
; CHECK-NEXT: EVM Lower Intrinsics
22+
; CHECK-NEXT: FunctionPass Manager
23+
; CHECK-NEXT: Module Verifier
24+
; CHECK-NEXT: Dominator Tree Construction
25+
; CHECK-NEXT: Basic Alias Analysis (stateless AA impl)
26+
; CHECK-NEXT: Natural Loop Information
27+
; CHECK-NEXT: Canonicalize natural loops
28+
; CHECK-NEXT: Scalar Evolution Analysis
29+
; CHECK-NEXT: Loop Pass Manager
30+
; CHECK-NEXT: Canonicalize Freeze Instructions in Loops
31+
; CHECK-NEXT: Induction Variable Users
32+
; CHECK-NEXT: Loop Strength Reduction
33+
; CHECK-NEXT: Basic Alias Analysis (stateless AA impl)
34+
; CHECK-NEXT: Function Alias Analysis Results
35+
; CHECK-NEXT: Merge contiguous icmps into a memcmp
36+
; CHECK-NEXT: Natural Loop Information
37+
; CHECK-NEXT: Lazy Branch Probability Analysis
38+
; CHECK-NEXT: Lazy Block Frequency Analysis
39+
; CHECK-NEXT: Expand memcmp() to load/stores
40+
; CHECK-NEXT: Lower Garbage Collection Instructions
41+
; CHECK-NEXT: Shadow Stack GC Lowering
42+
; CHECK-NEXT: Remove unreachable blocks from the CFG
43+
; CHECK-NEXT: Natural Loop Information
44+
; CHECK-NEXT: Post-Dominator Tree Construction
45+
; CHECK-NEXT: Branch Probability Analysis
46+
; CHECK-NEXT: Block Frequency Analysis
47+
; CHECK-NEXT: Constant Hoisting
48+
; CHECK-NEXT: Replace intrinsics with calls to vector library
49+
; CHECK-NEXT: Lazy Branch Probability Analysis
50+
; CHECK-NEXT: Lazy Block Frequency Analysis
51+
; CHECK-NEXT: Optimization Remark Emitter
52+
; CHECK-NEXT: Partially inline calls to library functions
53+
; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (post inlining)
54+
; CHECK-NEXT: Scalarize Masked Memory Intrinsics
55+
; CHECK-NEXT: Expand reduction intrinsics
56+
; CHECK-NEXT: Final transformations before code generation
57+
; CHECK-NEXT: Dominator Tree Construction
58+
; CHECK-NEXT: Natural Loop Information
59+
; CHECK-NEXT: CodeGen Prepare
60+
; CHECK-NEXT: Lower invoke and unwind, for unwindless code generators
61+
; CHECK-NEXT: Remove unreachable blocks from the CFG
62+
; CHECK-NEXT: CallGraph Construction
63+
; CHECK-NEXT: EVM mark recursive functions
64+
; CHECK-NEXT: FunctionPass Manager
65+
; CHECK-NEXT: Dominator Tree Construction
66+
; CHECK-NEXT: Basic Alias Analysis (stateless AA impl)
67+
; CHECK-NEXT: Function Alias Analysis Results
68+
; CHECK-NEXT: ObjC ARC contraction
69+
; CHECK-NEXT: Prepare callbr
70+
; CHECK-NEXT: Safe Stack instrumentation pass
71+
; CHECK-NEXT: Insert stack protectors
72+
; CHECK-NEXT: Module Verifier
73+
; CHECK-NEXT: Basic Alias Analysis (stateless AA impl)
74+
; CHECK-NEXT: Function Alias Analysis Results
75+
; CHECK-NEXT: Natural Loop Information
76+
; CHECK-NEXT: Post-Dominator Tree Construction
77+
; CHECK-NEXT: Branch Probability Analysis
78+
; CHECK-NEXT: Assignment Tracking Analysis
79+
; CHECK-NEXT: Lazy Branch Probability Analysis
80+
; CHECK-NEXT: Lazy Block Frequency Analysis
81+
; CHECK-NEXT: Unnamed pass: implement Pass::getPassName()
82+
; CHECK-NEXT: EVM Argument Move
83+
; CHECK-NEXT: Finalize ISel and expand pseudo-instructions
84+
; CHECK-NEXT: Optimize machine instruction PHIs
85+
; CHECK-NEXT: Slot index numbering
86+
; CHECK-NEXT: Merge disjoint stack slots
87+
; CHECK-NEXT: Local Stack Slot Allocation
88+
; CHECK-NEXT: Remove dead machine instructions
89+
; CHECK-NEXT: MachineDominator Tree Construction
90+
; CHECK-NEXT: Machine Natural Loop Construction
91+
; CHECK-NEXT: Machine Block Frequency Analysis
92+
; CHECK-NEXT: Early Machine Loop Invariant Code Motion
93+
; CHECK-NEXT: MachineDominator Tree Construction
94+
; CHECK-NEXT: Machine Block Frequency Analysis
95+
; CHECK-NEXT: Machine Common Subexpression Elimination
96+
; CHECK-NEXT: MachinePostDominator Tree Construction
97+
; CHECK-NEXT: Machine Cycle Info Analysis
98+
; CHECK-NEXT: Machine code sinking
99+
; CHECK-NEXT: Peephole Optimizations
100+
; CHECK-NEXT: Remove dead machine instructions
101+
; CHECK-NEXT: Detect Dead Lanes
102+
; CHECK-NEXT: Init Undef Pass
103+
; CHECK-NEXT: Process Implicit Definitions
104+
; CHECK-NEXT: Remove unreachable machine basic blocks
105+
; CHECK-NEXT: Live Variable Analysis
106+
; CHECK-NEXT: Eliminate PHI nodes for register allocation
107+
; CHECK-NEXT: Two-Address instruction pass
108+
; CHECK-NEXT: MachineDominator Tree Construction
109+
; CHECK-NEXT: Slot index numbering
110+
; CHECK-NEXT: Live Interval Analysis
111+
; CHECK-NEXT: Register Coalescer
112+
; CHECK-NEXT: Rename Disconnected Subregister Components
113+
; CHECK-NEXT: Machine Instruction Scheduler
114+
; CHECK-NEXT: Remove Redundant DEBUG_VALUE analysis
115+
; CHECK-NEXT: Fixup Statepoint Caller Saved
116+
; CHECK-NEXT: Lazy Machine Block Frequency Analysis
117+
; CHECK-NEXT: Machine Optimization Remark Emitter
118+
; CHECK-NEXT: Prologue/Epilogue Insertion & Frame Finalization
119+
; CHECK-NEXT: Machine Block Frequency Analysis
120+
; CHECK-NEXT: Control Flow Optimizer
121+
; CHECK-NEXT: Post-RA pseudo instruction expansion pass
122+
; CHECK-NEXT: Insert fentry calls
123+
; CHECK-NEXT: Insert XRay ops
124+
; CHECK-NEXT: EVM split critical edges
125+
; CHECK-NEXT: MachineDominator Tree Construction
126+
; CHECK-NEXT: Slot index numbering
127+
; CHECK-NEXT: Live Interval Analysis
128+
; CHECK-NEXT: EVM Optimize Live Intervals
129+
; CHECK-NEXT: EVM Single use expressions
130+
; CHECK-NEXT: Slot index numbering
131+
; CHECK-NEXT: Live Interval Analysis
132+
; CHECK-NEXT: Machine Natural Loop Construction
133+
; CHECK-NEXT: Virtual Register Map
134+
; CHECK-NEXT: Live Stack Slot Analysis
135+
; CHECK-NEXT: Machine Block Frequency Analysis
136+
; CHECK-NEXT: EVM backward propagation stackification
137+
; CHECK-NEXT: Stack Slot Coloring
138+
; CHECK-NEXT: EVM finalize stack frames
139+
; CHECK-NEXT: FunctionPass Manager
140+
; CHECK-NEXT: Machine Sanitizer Binary Metadata
141+
; CHECK-NEXT: Lazy Machine Block Frequency Analysis
142+
; CHECK-NEXT: Machine Optimization Remark Emitter
143+
; CHECK-NEXT: Stack Frame Layout Analysis
144+
; CHECK-NEXT: EVM Lower jump_unless
145+
; CHECK-NEXT: EVM constant unfolding
146+
; CHECK-NEXT: FunctionPass Manager
147+
; CHECK-NEXT: EVM Peephole
148+
; CHECK-NEXT: Lazy Machine Block Frequency Analysis
149+
; CHECK-NEXT: Machine Optimization Remark Emitter
150+
; CHECK-NEXT: EVM Assembly
151+
; CHECK-NEXT: Free MachineFunction
152+
153+
define void @f() {
154+
ret void
155+
}

0 commit comments

Comments
 (0)