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

Alex MacLean via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 21 18:56:30 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);
+          }
----------------
AlexMaclean wrote:

I agree this is a bit ugly. Unfortunately, I think line 3224 means that we won't be able to significantly clean it up this way. 
```c++
 PartAlign = commonAlignment(PartAlign.valueOrOne(), Offsets[parti]);
``` 

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


More information about the llvm-commits mailing list