[llvm] [PowerPC] Add special handling for arguments that are smaller than pointer size. (PR #119003)

Hubert Tong via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 10 12:38:15 PST 2024


================
@@ -7291,7 +7294,21 @@ SDValue PPCTargetLowering::LowerFormalArguments_AIX(
       SDValue FIN = DAG.getFrameIndex(FI, PtrVT);
       SDValue ArgValue =
           DAG.getLoad(ValVT, dl, Chain, FIN, MachinePointerInfo());
-      InVals.push_back(ArgValue);
+
+      // While the ABI specifies that the higher bits of the load should be
+      // zeroed out or sign extended this is not always the case. For safety
+      // this code will zero or sign extend the loaded value if the size of
+      // the argument type is smaller than the load.
+      if (!ArgVT.isVector() && !ValVT.isVector() && ArgVT.isInteger() &&
+          ValVT.isInteger() &&
+          ArgVT.getScalarSizeInBits() < ValVT.getScalarSizeInBits()) {
+        SDValue ArgValueTrunc = DAG.getNode(ISD::TRUNCATE, dl, ArgVT, ArgValue);
+        SDValue ArgValueExt =
+            ArgSignExt ? DAG.getSExtOrTrunc(ArgValueTrunc, dl, ValVT)
+                       : DAG.getZExtOrTrunc(ArgValueTrunc, dl, ValVT);
+        InVals.push_back(ArgValueExt);
+      } else
+        InVals.push_back(ArgValue);
----------------
hubert-reinterpretcast wrote:

Coding guidelines discourage `} else` now: https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements
```suggestion
      } else {
        InVals.push_back(ArgValue);
      }
```

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


More information about the llvm-commits mailing list