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

Justin Fargnoli via llvm-commits llvm-commits at lists.llvm.org
Fri May 31 15:13:28 PDT 2024


================
@@ -28338,6 +28340,50 @@ bool DAGCombiner::findBetterNeighborChains(StoreSDNode *St) {
   return false;
 }
 
+bool DAGCombiner::isCanBeLoadedWithLsl(SDNode *N) {
+  if (!N->hasOneUse())
+    return false;
+
+  APInt SrlAmt;
+  if (sd_match(N,
+               m_Shl(m_Srl(m_Value(), m_ConstInt(SrlAmt)), m_SpecificInt(2)))) {
+    // Srl knownbits
+    SDValue ShlV = SDValue(N, 0);
+    unsigned RegSize = ShlV.getValueType().getScalarSizeInBits();
+    KnownBits Known = DAG.computeKnownBits(ShlV);
+    if (Known.getBitWidth() != RegSize)
+      return false;
+
+    // check load (ldr x, (add x, (shl (srl x, c1) 2)))
+    SDNode *User = N->use_begin().getUse().getUser();
+    if (!User || User->getOpcode() != ISD::ADD)
+      return false;
+
+    SDNode *Load = User->use_begin().getUse().getUser();
+    if (!Load || Load->getOpcode() != ISD::LOAD)
+      return false;
+
+    auto LoadN = dyn_cast<LoadSDNode>(Load);
+    if (!LoadN)
+      return false;
----------------
justinfargnoli wrote:

If `Load->getOpcode() == ISD::LOAD`, can `dyn_cast<LoadSDNode>(Load) == nullptr`? 

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


More information about the llvm-commits mailing list