[llvm] [AArch64] Replace AND with LSL#2 for LDR target (#34101) (PR #89531)
David Green via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 5 00:27:20 PDT 2024
================
@@ -16918,6 +16918,23 @@ bool AArch64TargetLowering::shouldFoldConstantShiftPairToMask(
return (!C1 || !C2 || C1->getZExtValue() >= C2->getZExtValue());
}
+ // We do not need to fold when this shifting used in specific load case:
+ // (ldr x, (add x, (shl (srl x, c1) 2)))
+ if (N->getOpcode() == ISD::SHL && N->hasOneUse()) {
+ if (auto C2 = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
+ unsigned ShlAmt = C2->getZExtValue();
+ auto ShouldADD = *N->use_begin();
+ if (ShlAmt <= 3 && ShouldADD && ShouldADD->getOpcode() == ISD::ADD) {
----------------
davemgreen wrote:
I don't believe that use_begin will return null if there are no uses - it would try to access an invalid iterator. Maybe add a `&& ShouldADD->hasOneUse()` or `&& !ShouldADD->use_empty()` just to make sure it exists and we don't get any weird crashes.
https://github.com/llvm/llvm-project/pull/89531
More information about the llvm-commits
mailing list