Closed sharaelong closed 1 year ago
Adding pass and test cases looks good to me. Handle the opt.cpp
where you've commented all other passes.
Also, a caveat to your test case; your second test case clashes with the loop2sum pass, which should be prioritized? I'm considering putting loop2sum directly after the first pass: SimplifyCFG. Which pass will reduce more instruction costs?
Overview
The GVN (Global Value Numbering) pass in LLVM is an optimization pass that performs a technique called global value numbering. GVN is designed to eliminate redundant computations by identifying expressions that compute the same value and replacing them with a single computation. This optimization can improve both the execution speed and code size of the program.
The GVN pass performs the following key steps:
Implementation
It's just including appropriate headers and passes. Read
opt.cpp
!Test cases
I tested this pass for 2 aspects especially: redundant expression elimination and value propagation. In test01,
int a, b
has same declaration with combinations of previously declared variables. Its return value isreturn a+b
, so GVN pass will change it toreturn 2*a
. Test02 is the one which is not trivial.is pretty simple code which maybe thought as no optimization can be possible. However, pointer addition is redundant here. GVN pass will change it like:
Lastly, test03 is about constant propagation. You can see it directly in my commits.