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
- Repository
- rL LLVM
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 | ||
---|---|---|
76 ↗ | (On Diff #42835) | Please comment what AddrDispShift is and how it should be used by the caller. |
201 ↗ | (On Diff #42835) | differ? |
228 ↗ | (On Diff #42835) | This assert is useless. Moreover, in the previous check (getOperand(0).getReg()), the compiler would have asserted if the operand was not a register. |
246 ↗ | (On Diff #42835) | Could you add a comment over that loop? |
398 ↗ | (On Diff #42835) | The formatting looks funny to me, have you used clang-format? |
415 ↗ | (On Diff #42835) | else llvm_unreachable or assert? |
426 ↗ | (On Diff #42835) | 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 | ||
---|---|---|
76 ↗ | (On Diff #42835) | Done. |
201 ↗ | (On Diff #42835) | Fixed. |
228 ↗ | (On Diff #42835) | Removed. |
246 ↗ | (On Diff #42835) | Done. |
398 ↗ | (On Diff #42835) | Absolutely, that's clang-format's doing. |
415 ↗ | (On Diff #42835) | Done. |
426 ↗ | (On Diff #42835) | Done. |