[llvm] [GlobalISel][AArch64] Optimize shl, lshr, ashr (PR #213576)
David Green via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 4 01:26:53 PDT 2026
davemgreen wrote:
I remember, this is #199870 and how shifts work on AArch64, as opposed to being poison for IR.
The problem is that a shift in llvm IR, and by extension GISel, will return poison if the shift amount is larger than the shift amount. The Arm shifts take the shift amount mod the lower bits, so we can optimize the code to remove the extend.
SDAG will do that as it folds the shift into a LSLVWr in AArch64DAGToDAGISel::tryShiftAmountMod. https://github.com/llvm/llvm-project/blob/ad0465266346682f39a44e7ca9e971b5fa101cc2/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp#L4226. The equivalent of that for GISel would be during InstructionSelection, somewhere in AArch64InstructionSelector::select probably. It could maybe be done as a post-selection combine, but I think it is probably simpler to perform during selection. Could we add the same optimization as SDAG, into AArch64InstructionSelector::select when selecting the shift?
https://github.com/llvm/llvm-project/pull/213576
More information about the llvm-commits
mailing list