Skip to content

DAG: Move get_dynamic_area_offset type check to IR verifier #145268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

arsenm
Copy link
Contributor

@arsenm arsenm commented Jun 23, 2025

Also fix the LangRef to match the implementation. This was checking
against the alloca address space size rather than the default address
space.

The check was also more permissive than the LangRef. The error
check permitted any size less than the pointer size; follow the
stricter wording of the LangRef.

Also fix the LangRef to match the implementation. This was checking
against the alloca address space size rather than the default address
space.

The check was also more permissive than the LangRef. The error
check permitted any size less than the pointer size; follow the
stricter wording of the LangRef.
Copy link
Contributor Author

arsenm commented Jun 23, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@arsenm arsenm added the llvm:SelectionDAG SelectionDAGISel as well label Jun 23, 2025 — with Graphite App
@arsenm arsenm requested review from RKSimon and topperc June 23, 2025 05:45
@llvmbot
Copy link
Member

llvmbot commented Jun 23, 2025

@llvm/pr-subscribers-llvm-ir

@llvm/pr-subscribers-llvm-selectiondag

Author: Matt Arsenault (arsenm)

Changes

Also fix the LangRef to match the implementation. This was checking
against the alloca address space size rather than the default address
space.

The check was also more permissive than the LangRef. The error
check permitted any size less than the pointer size; follow the
stricter wording of the LangRef.


Full diff: https://github.com/llvm/llvm-project/pull/145268.diff

4 Files Affected:

  • (modified) llvm/docs/LangRef.rst (+1-1)
  • (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (-6)
  • (modified) llvm/lib/IR/Verifier.cpp (+9)
  • (added) llvm/test/Verifier/get_dynamic_area_offset.ll (+30)
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index cc72a37f68599..2e875be375e94 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -14597,7 +14597,7 @@ Semantics:
       compile-time-known constant value.
 
       The return value type of :ref:`llvm.get.dynamic.area.offset <int_get_dynamic_area_offset>`
-      must match the target's default address space's (address space 0) pointer type.
+      must match the target's :ref:`alloca address space <alloca_addrspace>` type.
 
 '``llvm.prefetch``' Intrinsic
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index c01f1e7928477..04d6fd5f48cc3 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -7320,13 +7320,7 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
     return;
   case Intrinsic::get_dynamic_area_offset: {
     SDValue Op = getRoot();
-    EVT PtrTy = TLI.getFrameIndexTy(DAG.getDataLayout());
     EVT ResTy = TLI.getValueType(DAG.getDataLayout(), I.getType());
-    // Result type for @llvm.get.dynamic.area.offset should match PtrTy for
-    // target.
-    if (PtrTy.getFixedSizeInBits() < ResTy.getFixedSizeInBits())
-      report_fatal_error("Wrong result type for @llvm.get.dynamic.area.offset"
-                         " intrinsic!");
     Res = DAG.getNode(ISD::GET_DYNAMIC_AREA_OFFSET, sdl, DAG.getVTList(ResTy),
                       Op);
     DAG.setRoot(Op);
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index f0a4d7b6a4c1e..71261343b3482 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -6061,6 +6061,15 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
           "va_start called in a non-varargs function");
     break;
   }
+  case Intrinsic::get_dynamic_area_offset: {
+    auto *IntTy = dyn_cast<IntegerType>(Call.getType());
+    Check(IntTy && DL.getPointerSizeInBits(DL.getAllocaAddrSpace()) ==
+                       IntTy->getBitWidth(),
+          "get_dynamic_area_offset result type must be scalar integer matching "
+          "alloca address space width",
+          Call);
+    break;
+  }
   case Intrinsic::vector_reduce_and:
   case Intrinsic::vector_reduce_or:
   case Intrinsic::vector_reduce_xor:
diff --git a/llvm/test/Verifier/get_dynamic_area_offset.ll b/llvm/test/Verifier/get_dynamic_area_offset.ll
new file mode 100644
index 0000000000000..89c060e390b9f
--- /dev/null
+++ b/llvm/test/Verifier/get_dynamic_area_offset.ll
@@ -0,0 +1,30 @@
+; RUN: not llvm-as -disable-output %s 2>&1 | FileCheck %s
+
+target datalayout = "p0:64:64-p5:32:32-A5"
+
+declare i64 @llvm.get.dynamic.area.offset.i64()
+
+; CHECK: get_dynamic_area_offset result type must be scalar integer matching alloca address space width
+; CHECK-NEXT: %res = call i64 @llvm.get.dynamic.area.offset.i64()
+define i64 @test_dynamic_area_too_big() {
+  %res = call i64 @llvm.get.dynamic.area.offset.i64()
+  ret i64 %res
+}
+
+declare i16 @llvm.get.dynamic.area.offset.i16()
+
+; CHECK: get_dynamic_area_offset result type must be scalar integer matching alloca address space width
+; CHECK-NEXT: %res = call i16 @llvm.get.dynamic.area.offset.i16()
+define i16 @test_dynamic_area_too_small() {
+  %res = call i16 @llvm.get.dynamic.area.offset.i16()
+  ret i16 %res
+}
+
+declare <2 x i32> @llvm.get.dynamic.area.offset.v2i32()
+
+; CHECK: get_dynamic_area_offset result type must be scalar integer matching alloca address space width
+; CHECK-NEXT: %res = call <2 x i32> @llvm.get.dynamic.area.offset.v2i32()
+define <2 x i32> @test_dynamic_area_vector() {
+  %res = call <2 x i32> @llvm.get.dynamic.area.offset.v2i32()
+  ret <2 x i32> %res
+}

@arsenm arsenm requested a review from RolandF77 June 23, 2025 05:45
@arsenm arsenm marked this pull request as ready for review June 23, 2025 05:45
Copy link
Collaborator

@RKSimon RKSimon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@arsenm arsenm merged commit f0d898f into main Jun 24, 2025
13 checks passed
@arsenm arsenm deleted the users/arsenm/dag/move-get-dynamic-area-offset-check-to-ir-verifier branch June 24, 2025 02:11
DrSergei pushed a commit to DrSergei/llvm-project that referenced this pull request Jun 24, 2025
)

Also fix the LangRef to match the implementation. This was checking
against the alloca address space size rather than the default address
space.

The check was also more permissive than the LangRef. The error
check permitted any size less than the pointer size; follow the
stricter wording of the LangRef.
anthonyhatran pushed a commit to anthonyhatran/llvm-project that referenced this pull request Jun 26, 2025
)

Also fix the LangRef to match the implementation. This was checking
against the alloca address space size rather than the default address
space.

The check was also more permissive than the LangRef. The error
check permitted any size less than the pointer size; follow the
stricter wording of the LangRef.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:ir llvm:SelectionDAG SelectionDAGISel as well
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants