[llvm] [SelectionDAG] Handling Oversized Alloca Types under 32 bit Mode to Avoid Code Generator Crash (PR #71472)

Qiongsi Wu via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 10 12:40:42 PST 2023


================
@@ -4138,9 +4138,10 @@ void SelectionDAGBuilder::visitAlloca(const AllocaInst &I) {
                                           APInt(IntPtr.getScalarSizeInBits(),
                                                 TySize.getKnownMinValue())));
   else
-    AllocSize =
-        DAG.getNode(ISD::MUL, dl, IntPtr, AllocSize,
-                    DAG.getConstant(TySize.getFixedValue(), dl, IntPtr));
+    AllocSize = DAG.getNode(ISD::MUL, dl, IntPtr, AllocSize,
+                            DAG.getConstant(APInt(IntPtr.getScalarSizeInBits(),
----------------
qiongsiwu wrote:

Thanks so much @arsenm ! The code is revised to take advantage of `getZExtOrTrunc` and to avoid creating an extra `APInt`. I still had some issues trying to figure out a good way to compute `TySize`'s bit width, but since it is represented by a `uint64_t`, the bitwidth is hardcoded to 64. Using `IntPtr.getScalarSizeInBits` does not work for me because it is too narrow for the big constants under our concern. 

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


More information about the llvm-commits mailing list