Skip to content

[llvm][sroa] Fixed failing assertion caused by no handling for {launder,strip}.invariant.group in AggLoadStoreRewriter #151574

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

Closed
wants to merge 4 commits into from

Conversation

tommymcm
Copy link
Contributor

@tommymcm tommymcm commented Jul 31, 2025

SROA pass does not perform aggregate load/store rewriting on a pointer whose source is a launder.invariant.group.

This causes failed assertion in AllocaSlices.

void (anonymous namespace)::AllocaSlices::SliceBuilder::visitStoreInst(StoreInst &):
 Assertion `(!SI.isSimple() || ValOp->getType()->isSingleValueType()) &&
 "All simple FCA stores should have been pre-split"' failed.

Added test for launder.invariant.group intrinsic inside of a loop, which causes a failing assertion on debug build:

Fixed by adding handling to the AggLoadStoreRewriter for {launder,strip}.invariant.group intrinsic.

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Jul 31, 2025

@llvm/pr-subscribers-llvm-transforms

Author: Tommy MᶜMichen (tommymcm)

Changes

Added test for launder.invariant.group intrinsic inside of a loop, which causes a failing assertion on debug build:

void (anonymous namespace)::AllocaSlices::SliceBuilder::visitStoreInst(StoreInst &):
 Assertion `(!SI.isSimple() || ValOp->getType()->isSingleValueType()) &&
 "All simple FCA stores should have been pre-split"' failed.

This is fixed by adding handling to the AggLoadStoreRewriter for {launder,strip}.invariant.group intrinsic.


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

2 Files Affected:

  • (modified) llvm/lib/Transforms/Scalar/SROA.cpp (+6)
  • (modified) llvm/test/Transforms/SROA/invariant-group.ll (+38)
diff --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp
index 23256cf2acbd2..821b41f0583f3 100644
--- a/llvm/lib/Transforms/Scalar/SROA.cpp
+++ b/llvm/lib/Transforms/Scalar/SROA.cpp
@@ -4261,6 +4261,12 @@ class AggLoadStoreRewriter : public InstVisitor<AggLoadStoreRewriter, bool> {
     enqueueUsers(SI);
     return false;
   }
+
+  bool visitIntrinsicInst(IntrinsicInst &II) {
+    if (II.isLaunderOrStripInvariantGroup())
+      enqueueUsers(II);
+    return false;
+  }
 };
 
 } // end anonymous namespace
diff --git a/llvm/test/Transforms/SROA/invariant-group.ll b/llvm/test/Transforms/SROA/invariant-group.ll
index 1be6f6e2fc32b..4eac8fc1b48d6 100644
--- a/llvm/test/Transforms/SROA/invariant-group.ll
+++ b/llvm/test/Transforms/SROA/invariant-group.ll
@@ -155,6 +155,44 @@ define void @partial_promotion_of_alloca() {
   ret void
 }
 
+define void @launder_in_loop() {
+; CHECK-LABEL: @launder_in_loop(
+; CHECK-NEXT:    br label %[[HEADER:.*]]
+;
+  %struct_ptr = alloca %t, i64 1, align 4
+  br label %header
+
+; CHECK:       [[HEADER]]:
+; CHECK-NEXT:    br i1 true, label %[[BODY:.*]], label %[[EXIT:.*]]
+;
+header:
+  br i1 true, label %body, label %exit
+
+; CHECK:       [[BODY]]:
+; CHECK-NEXT:    [[STRUCT:%.*]] = call %t @make_t()
+; CHECK-NEXT:    [[FIRST:%.*]] = extractvalue %t [[STRUCT]], 0
+; CHECK-NEXT:    [[SECOND:%.*]] = extractvalue %t [[STRUCT]], 1
+; CHECK-NEXT:    br label %[[HEADER]]
+;
+body:                                                ; preds = %6
+  %struct_ptr_fresh = call ptr @llvm.launder.invariant.group.p0(ptr %struct_ptr)
+  %struct = call %t @make_t()
+  store %t %struct, ptr %struct_ptr_fresh, align 4, !invariant.group !0
+  %first_ptr = getelementptr %t, ptr %struct_ptr_fresh, i32 0, i32 0
+  %first = load i32, ptr %first_ptr, align 4
+  %second_ptr = getelementptr %t, ptr %struct_ptr_fresh, i32 0, i32 1
+  %second = load i32, ptr %second_ptr, align 4
+  br label %header
+
+; CHECK:       [[EXIT]]:
+; CHECK-NEXT:    ret void
+;
+exit:
+  ret void
+}
+
+declare %t @make_t()
+
 declare void @use(ptr)
 
 !0 = !{}

@smeenai smeenai requested a review from nikic July 31, 2025 19:04
@nikic
Copy link
Contributor

nikic commented Aug 1, 2025

Though TBH I think we should just revert invariant.group support in SROA, it's broken right now.

@tommymcm
Copy link
Contributor Author

tommymcm commented Aug 1, 2025

Though TBH I think we should just revert invariant.group support in SROA, it's broken right now.

That would also work for my purposes.

@tommymcm
Copy link
Contributor Author

tommymcm commented Aug 1, 2025

@nikic #151743 disables invariant.group support. Either one of these solutions works for me.

tommymcm pushed a commit to tommymcm/llvm-project that referenced this pull request Aug 1, 2025
tommymcm added a commit to tommymcm/llvm-project that referenced this pull request Aug 1, 2025
@nikic nikic closed this in #151743 Aug 5, 2025
nikic pushed a commit that referenced this pull request Aug 5, 2025
Resolves #151574.

> SROA pass does not perform aggregate load/store rewriting on a pointer
whose source is a `launder.invariant.group`.
> 
> This causes failed assertion in `AllocaSlices`.
> 
> ```
> void (anonymous
namespace)::AllocaSlices::SliceBuilder::visitStoreInst(StoreInst &):
> Assertion `(!SI.isSimple() || ValOp->getType()->isSingleValueType())
&&
>  "All simple FCA stores should have been pre-split"' failed.
> ```

Disables support for `{launder,strip}.invariant.group` intrinsics in
SROA.

Updates SROA test for `invariant.group` support.
@tommymcm tommymcm deleted the sroa-launder branch August 5, 2025 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants