[llvm-branch-commits] [llvm] [LoongArch] Load suitable immediates with LU12I.W+SLLI.D (PR #242357)

Rong Mantle Bao via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Nov 13 18:47:47 PST 2026


================
@@ -412,12 +419,24 @@ bool LoongArchMergeBaseOffsetOpt::foldLargeOffset(
       MachineOperand ImmOp = Curr->getOperand(2);
       if (ImmOp.getTargetFlags() != LoongArchII::MO_None || !Hi12)
         return false;
-      Offset += ImmOp.getImm() << 52;
+      const int64_t Imm = ImmOp.getImm();
+      Offset += (static_cast<uint64_t>(Imm) << 52) << Shift;
       Mask &= ~0xFFF0000000000000ULL;
       Reg = Curr->getOperand(1).getReg();
       Instrs.push_back(Curr);
       break;
     }
+    case LoongArch::SLLI_D: {
+      MachineOperand ImmOp = Curr->getOperand(2);
+      if (ImmOp.getTargetFlags() != LoongArchII::MO_None)
+        return false;
+      Shift += ImmOp.getImm();
+      if (Shift >= 64)
+        return false;
+      Reg = Curr->getOperand(1).getReg();
+      Instrs.push_back(Curr);
+      break;
+    }
----------------
CSharperMantle wrote:

Item 2 is probably because we need to shift `Mask` bitops as well, e.g. `Mask &= ~(0xFFF0000000000000ULL << Shift)` rather than `Mask &= ~0xFFF0000000000000ULL`.

For Item 1 I think we should reject folding SLLI.D-containing offset sequences into the base if it doesn't contain Lo20 and Hi12 that we can fold into.

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


More information about the llvm-branch-commits mailing list