Make x86 OptimizeLEAs pass remove LEA instruction if there is another LEA (in the same basic block) which calculates address differing only be a displacement. Works only for -Oz.
Details
Diff Detail
Event Timeline
Hi Andrey,
Thanks for working on this.
Out of curiosity, what performance impact do you see?
I.e., compile time and code size improvements.
Couple more comments inlined.
Thanks,
-Quentin
lib/Target/X86/X86OptimizeLEAs.cpp | ||
---|---|---|
81 | Please comment what AddrDispShift is and how it should be used by the caller. | |
213 | differ? | |
240 | This assert is useless. Moreover, in the previous check (getOperand(0).getReg()), the compiler would have asserted if the operand was not a register. | |
258 | Could you add a comment over that loop? | |
426 | The formatting looks funny to me, have you used clang-format? | |
443 | else llvm_unreachable or assert? | |
454 | Add a message in the assert. |
Hi Quentin,
Thanks for the review.
This part reduces code size on Spec2000 for additional 0.1%, making it total 0.3% at -Oz.
The performance impact I measured was negative, yet very close to zero. I didn't want to possibly hurt performance at any rate at -Os, so I enabled it only for -Oz and I intend to keep it so until I do some analysis.
I don't see any significant compile time impact on Spec 2000 or the test from https://llvm.org/bugs/show_bug.cgi?id=25843. The complexity of removeRedundantLEAs is something like O(n^2), so the compile time should not blow up for big basic blocks.
lib/Target/X86/X86OptimizeLEAs.cpp | ||
---|---|---|
81 | Done. | |
213 | Fixed. | |
240 | Removed. | |
258 | Done. | |
426 | Absolutely, that's clang-format's doing. | |
443 | Done. | |
454 | Done. |
Please comment what AddrDispShift is and how it should be used by the caller.