[llvm] [AMDGPU] Folding imm offset in more cases for scratch access (PR #70634)

via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 16 18:34:15 PST 2023


================
@@ -1146,13 +1146,57 @@ bool AMDGPUDAGToDAGISel::isDSOffset2Legal(SDValue Base, unsigned Offset0,
   return CurDAG->SignBitIsZero(Base);
 }
 
-bool AMDGPUDAGToDAGISel::isFlatScratchBaseLegal(SDValue Base,
-                                                uint64_t FlatVariant) const {
+// Whether we can infer the operands are non-negative if the result is
+// non-negative.
+static bool canInferNonNegativeOperands(SDValue Addr) {
+  return (Addr.getOpcode() == ISD::ADD &&
+          Addr->getFlags().hasNoUnsignedWrap()) ||
+         Addr->getOpcode() == ISD::OR;
----------------
ruiling wrote:

I don't quite follow your point. Do you mean the scratch buffer starting offset can be negative? or the base address can be negative? but if the base address is negative, then `OR` with immediate offset would still be negative, then the scratch instruction would access address out of scratch memory region, right?

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


More information about the llvm-commits mailing list