[llvm] [NVPTX] fixup support for unaligned parameters and returns (PR #82562)

Artem Belevich via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 22 12:11:37 PST 2024


================
@@ -3045,9 +3205,28 @@ SDValue NVPTXTargetLowering::LowerFormalArguments(
                           DAG.getConstant(Offsets[VecIdx], dl, PtrVT));
           Value *srcValue = Constant::getNullValue(PointerType::get(
               EltVT.getTypeForEVT(F->getContext()), ADDRESS_SPACE_PARAM));
+
+          MaybeAlign PartAlign;
+          if (NumElts == 1) {
+            if (aggregateIsPacked) {
+              PartAlign = Align(1);
+            } else if (Offsets[parti] == 0) {
+              if (MaybeAlign ParamAlign = PAL.getParamAlignment(i)) {
+                PartAlign = ParamAlign.value();
+              } else {
+                PartAlign =
+                    DL.getABITypeAlign(EltVT.getTypeForEVT(F->getContext()));
+              }
+            } else {
+              PartAlign =
+                  DL.getABITypeAlign(EltVT.getTypeForEVT(F->getContext()));
+            }
+            PartAlign = commonAlignment(PartAlign.valueOrOne(), Offsets[parti]);
+          } else {
+            PartAlign = MaybeAlign(aggregateIsPacked);
+          }
----------------
Artem-B wrote:

I'm missing something here. What makes this particular line special? 

Unless I've messed something up it all boils down to this:
```
    if (NumElts != 1) return MaybeAlign(aggregateIsPacked);
    if (aggregateIsPacked) return Align(1);
   MaybeAlign PartAlign =
        (Offsets[parti] == 0 && PAL.getParamAlignment(i))
            ? PAL.getParamAlignment(i).value()
            : DL.getABITypeAlign(EltVT.getTypeForEVT(F->getContext()));
    return commonAlignment(PartAlign.valueOrOne(), Offsets[parti]);
```

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


More information about the llvm-commits mailing list