Closed germanium32 closed 1 year ago
It shows that FileChecks passed; but operation time shows as 0.00s.
I'm not sure that FileChecks are fully operated; although my tests are fairly short. Also, I have checked that FileChecks passed in my local environment.
Can I treat it as success? :)
I'm not sure that FileChecks are fully operated; although my tests are fairly short. Also, I have checked that FileChecks passed in my local environment.
Can I treat it as success? :)
Yes I think so =)
LGTM!
LGTM But I think codes that check the type of instruction and generate the function can be improved by removing unneccesary copies
Overview
Implement
IncrDecrPass
, which is an improvement ofArithmeticPass
, implemented by Mingi Choi. The IncrDecrPass optimizes the following simple additions to a new given instruction,incr
anddecr
.add %a n
->incr %a
n timessub %a n
->decr %a
n timesadd %a -n
->decr %a
n timessub %a -n
->incr %a
n timesDependencies of instruction values should be adjusted. Since
add/sub
costs are 5, whereasincr/decr
costs are 1, if a add/sub instruction has a operand with absolute value less than 5, we can optimize it into iteratedincr/decr
instructions. Expected to work well on loops, since canonical loop structures have an induction variable incremented by 1 each iteration. e.g.%idx = add %i, 1
->%idx = incr %i
Implementation
First iterate over a basic block, and find all instructions that can be optimized. Detect all patterns with
add/sub op0, const
, and remind thatadd
is commutative, so check for both operands. Save all optimizable instructions in a container. Iterate over such instructions and replace it with iteratedincr/decr
instructions. Replace all uses of the original instruction with the lastmostincr/decr
instruction, then remove the original instruction.Iterating step and replacement step are separated, since replacing during iterations resulted in segmentation errors; changing instructions of the BB inside the loop
for(Instruction &I : BB)
was harmful.Unit tests (incrdecr/test0*.ll)
add %a, 1
andsub %b 2
-> Must optimizesub %a, -3
andadd %b -4
-> Must optimizeadd %a, 5
andsub %b 6
-> Must not optimizeadd 2, %a
andsub 2, %b
-> Must optimize the first, Must not optimize the secondoracle
-> Must not optimize(maybe up to now)