[llvm] [AArch64] Replace AND with LSL#2 for LDR target (#34101) (PR #89531)

David Green via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 2 23:45:04 PDT 2024


================
@@ -16918,6 +16918,24 @@ 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) {
+    auto C2 = dyn_cast_or_null<ConstantSDNode>(N->getOperand(1));
+    if (C2 && C2->getZExtValue() == 2) {
+      auto ShouldADD =
+          dyn_cast_or_null<SDNode>(N->use_begin().getUse().getUser());
----------------
davemgreen wrote:

I don't believe the _or_null is required. Can the `N->use_begin().getUse().getUser()` just be `*N->use_begin()`? It should also probably check that N->hasOneUse().

Same below for the load.

https://github.com/llvm/llvm-project/pull/89531


More information about the llvm-commits mailing list