Skip to content

Conversation

efwright
Copy link

In the CodeExtractor if aggregate arguments are used it allocates a struct to hold variables needed to be passed into an outlined function. Then, if this alloca was not in the default address space an AddressSpaceCast was emitted. However, this new instruction was unused, and the code instead just continued to reference the original alloca instruction.

This PR changes it so that the AddressSpaceCast is actually used instead of the original alloca.

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 Jun 20, 2024

@llvm/pr-subscribers-llvm-transforms

Author: Eric Wright (efwright)

Changes

In the CodeExtractor if aggregate arguments are used it allocates a struct to hold variables needed to be passed into an outlined function. Then, if this alloca was not in the default address space an AddressSpaceCast was emitted. However, this new instruction was unused, and the code instead just continued to reference the original alloca instruction.

This PR changes it so that the AddressSpaceCast is actually used instead of the original alloca.


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

1 Files Affected:

  • (modified) llvm/lib/Transforms/Utils/CodeExtractor.cpp (+7-6)
diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
index b2775eb6c6c7a..2d4d8e62bf3c5 100644
--- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -1195,7 +1195,7 @@ CallInst *CodeExtractor::emitCallAndSwitchStatement(Function *newFunction,
   }
 
   StructType *StructArgTy = nullptr;
-  AllocaInst *Struct = nullptr;
+  Instruction *Struct = nullptr;
   unsigned NumAggregatedInputs = 0;
   if (AggregateArgs && !StructValues.empty()) {
     std::vector<Type *> ArgTypes;
@@ -1204,19 +1204,20 @@ CallInst *CodeExtractor::emitCallAndSwitchStatement(Function *newFunction,
 
     // Allocate a struct at the beginning of this function
     StructArgTy = StructType::get(newFunction->getContext(), ArgTypes);
-    Struct = new AllocaInst(
+    auto *StructAlloca = new AllocaInst(
         StructArgTy, DL.getAllocaAddrSpace(), nullptr, "structArg",
         AllocationBlock ? AllocationBlock->getFirstInsertionPt()
                         : codeReplacer->getParent()->front().begin());
 
     if (ArgsInZeroAddressSpace && DL.getAllocaAddrSpace() != 0) {
       auto *StructSpaceCast = new AddrSpaceCastInst(
-          Struct, PointerType ::get(Context, 0), "structArg.ascast");
-      StructSpaceCast->insertAfter(Struct);
-      params.push_back(StructSpaceCast);
+          StructAlloca, PointerType ::get(Context, 0), "structArg.ascast");
+      StructSpaceCast->insertAfter(StructAlloca);
+      Struct = StructSpaceCast;
     } else {
-      params.push_back(Struct);
+      Struct = StructAlloca;
     }
+    params.push_back(Struct);
     // Store aggregated inputs in the struct.
     for (unsigned i = 0, e = StructValues.size(); i != e; ++i) {
       if (inputs.contains(StructValues[i])) {

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.

2 participants