[x86] refine conditions for immediate hoisting to save code-size
authorSanjay Patel <spatel@rotateright.com>
Tue, 9 Jun 2020 19:43:34 +0000 (15:43 -0400)
committerSanjay Patel <spatel@rotateright.com>
Tue, 9 Jun 2020 19:44:55 +0000 (15:44 -0400)
commit6f6d2d238360883039cd17986c9ef598d04995a3
tree50b446114dcd3dfda487c7789e6917b0a27781fb
parent90ee8cf63613df525c4dab5e715fbae5f7310a78
[x86] refine conditions for immediate hoisting to save code-size

As shown in PR46237:
https://bugs.llvm.org/show_bug.cgi?id=46237

The size-savings win for hoisting an 8-bit ALU immediate (intentionally
excluding store constants) requires extreme conditions; it may not even
be possible when including REX prefix bytes on x86-64.

I did draft a version of this patch that included use counts after the
loop, but I suspect that accounting is not working as expected. I think
that is because the number of constant uses are changing as we select
instructions (for example as we transform shl/add into LEA).

Differential Revision: https://reviews.llvm.org/D81468
llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
llvm/test/CodeGen/X86/immediate_merging.ll
llvm/test/CodeGen/X86/immediate_merging64.ll
llvm/test/CodeGen/X86/pr27202.ll