llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[AMDGPU][GlobalIsel] ICE: unable to lower arguments: void (i32)

Open mgcarrasco opened this issue 6 months ago • 19 comments

The following bitcode module triggers an internal compiler error for -global-isel -O1 in https://github.com/llvm/llvm-project/commit/f68ef5b4303de763ecf37fd57cbefc3891ee48c0.

Module: https://gist.github.com/mgcarrasco/7487ab0bcf8bbd7be854e1bcfe222bbf Reproducer: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx90a -O1 -global-isel module.ll

Stack trace:

#10 0x00007c5f0eaa638a reportTranslationError(llvm::MachineFunction&, llvm::OptimizationRemarkEmitter&, llvm::OptimizationRemarkMissed&) IRTranslator.cpp:0:0
#11 0x00007c5f0eacc9c1 llvm::IRTranslator::runOnMachineFunction(llvm::MachineFunction&) (/mnt/COW/2026-06-01/trunk_23.0-0/bin/../lib/../lib/libLLVMGlobalISel.so.23.0git+0x1019c1)
#12 0x00007c5f1132633b llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#13 0x00007c5f0fa50251 llvm::FPPassManager::runOnFunction(llvm::Function&) (/mnt/COW/2026-06-01/trunk_23.0-0/bin/../lib/libLLVMCore.so.23.0git+0x297251)
#14 0x00007c5f1007dc12 (anonymous namespace)::CGPassManager::runOnModule(llvm::Module&) CallGraphSCCPass.cpp:0:0
#15 0x00007c5f0fa51250 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/mnt/COW/2026-06-01/trunk_23.0-0/bin/../lib/libLLVMCore.so.23.0git+0x298250)
#16 0x000060cd9261d79a compileModule(char**, llvm::SmallVectorImpl<llvm::PassPlugin>&, llvm::LLVMContext&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&) llc.cpp:0:0
#17 0x000060cd92610b6c main (/COD/LATEST/trunk/bin/llc+0x11b6c)

Bug found by @ElliotBLabs.

mgcarrasco avatar Jun 01 '26 12:06 mgcarrasco

@llvm/issue-subscribers-backend-amdgpu

Author: Manuel Carrasco (mgcarrasco)

The following bitcode module triggers an internal compiler error for `-global-isel -O1` in https://github.com/llvm/llvm-project/commit/f68ef5b4303de763ecf37fd57cbefc3891ee48c0.

Module: https://gist.github.com/mgcarrasco/7487ab0bcf8bbd7be854e1bcfe222bbf Reproducer: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx90a -O1 -global-isel module.ll

Stack trace:

#<!-- -->10 0x00007c5f0eaa638a reportTranslationError(llvm::MachineFunction&amp;, llvm::OptimizationRemarkEmitter&amp;, llvm::OptimizationRemarkMissed&amp;) IRTranslator.cpp:0:0
#<!-- -->11 0x00007c5f0eacc9c1 llvm::IRTranslator::runOnMachineFunction(llvm::MachineFunction&amp;) (/mnt/COW/2026-06-01/trunk_23.0-0/bin/../lib/../lib/libLLVMGlobalISel.so.23.0git+0x1019c1)
#<!-- -->12 0x00007c5f1132633b llvm::MachineFunctionPass::runOnFunction(llvm::Function&amp;) (.part.0) MachineFunctionPass.cpp:0:0
#<!-- -->13 0x00007c5f0fa50251 llvm::FPPassManager::runOnFunction(llvm::Function&amp;) (/mnt/COW/2026-06-01/trunk_23.0-0/bin/../lib/libLLVMCore.so.23.0git+0x297251)
#<!-- -->14 0x00007c5f1007dc12 (anonymous namespace)::CGPassManager::runOnModule(llvm::Module&amp;) CallGraphSCCPass.cpp:0:0
#<!-- -->15 0x00007c5f0fa51250 llvm::legacy::PassManagerImpl::run(llvm::Module&amp;) (/mnt/COW/2026-06-01/trunk_23.0-0/bin/../lib/libLLVMCore.so.23.0git+0x298250)
#<!-- -->16 0x000060cd9261d79a compileModule(char**, llvm::SmallVectorImpl&lt;llvm::PassPlugin&gt;&amp;, llvm::LLVMContext&amp;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt;&amp;) llc.cpp:0:0
#<!-- -->17 0x000060cd92610b6c main (/COD/LATEST/trunk/bin/llc+0x11b6c)

Bug found by @ElliotBLabs.

For these issues, do we want to add "good first issue" tag to some of them? ICE might be good candidate.

shiltian avatar Jun 01 '26 14:06 shiltian

For these issues, do we want to add "good first issue" tag to some of them? ICE might be good candidate.

Ty, it sounds good to me.

mgcarrasco avatar Jun 01 '26 14:06 mgcarrasco

Hi!

This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:

  1. Check that no other contributor is working on this issue. If someone is assigned to the issue or claimed to be working on it, ping the person. After one week without a response, the assignee may be changed.
  2. Leave a comment indicating that you are working on the issue, or just create a pull request after following the steps below. Mention this issue in the description of the pull request.
  3. Fix the issue locally. Be aware that LLVM's AI policy forbids the use of AI tools to fix good first issues since it squanders a learning opportunity. Using LLMs to search and learn is permitted, since the goal is learning.
  4. Run the test suite locally. Remember that the subdirectories under test/ create fine-grained testing targets, so you can e.g. use make check-clang-ast to only run Clang's AST tests.
  5. Create a Git commit.
  6. Run git clang-format HEAD~1 to format your changes.
  7. Open a pull request to the upstream repository on GitHub. Detailed instructions can be found in GitHub's documentation. Mention this issue in the description of the pull request.

If you have any further questions about this issue, don't hesitate to ask via a comment in the thread below.

@llvm/issue-subscribers-good-first-issue

Author: Manuel Carrasco (mgcarrasco)

The following bitcode module triggers an internal compiler error for `-global-isel -O1` in https://github.com/llvm/llvm-project/commit/f68ef5b4303de763ecf37fd57cbefc3891ee48c0.

Module: https://gist.github.com/mgcarrasco/7487ab0bcf8bbd7be854e1bcfe222bbf Reproducer: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx90a -O1 -global-isel module.ll

Stack trace:

#<!-- -->10 0x00007c5f0eaa638a reportTranslationError(llvm::MachineFunction&amp;, llvm::OptimizationRemarkEmitter&amp;, llvm::OptimizationRemarkMissed&amp;) IRTranslator.cpp:0:0
#<!-- -->11 0x00007c5f0eacc9c1 llvm::IRTranslator::runOnMachineFunction(llvm::MachineFunction&amp;) (/mnt/COW/2026-06-01/trunk_23.0-0/bin/../lib/../lib/libLLVMGlobalISel.so.23.0git+0x1019c1)
#<!-- -->12 0x00007c5f1132633b llvm::MachineFunctionPass::runOnFunction(llvm::Function&amp;) (.part.0) MachineFunctionPass.cpp:0:0
#<!-- -->13 0x00007c5f0fa50251 llvm::FPPassManager::runOnFunction(llvm::Function&amp;) (/mnt/COW/2026-06-01/trunk_23.0-0/bin/../lib/libLLVMCore.so.23.0git+0x297251)
#<!-- -->14 0x00007c5f1007dc12 (anonymous namespace)::CGPassManager::runOnModule(llvm::Module&amp;) CallGraphSCCPass.cpp:0:0
#<!-- -->15 0x00007c5f0fa51250 llvm::legacy::PassManagerImpl::run(llvm::Module&amp;) (/mnt/COW/2026-06-01/trunk_23.0-0/bin/../lib/libLLVMCore.so.23.0git+0x298250)
#<!-- -->16 0x000060cd9261d79a compileModule(char**, llvm::SmallVectorImpl&lt;llvm::PassPlugin&gt;&amp;, llvm::LLVMContext&amp;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt;&amp;) llc.cpp:0:0
#<!-- -->17 0x000060cd92610b6c main (/COD/LATEST/trunk/bin/llc+0x11b6c)

Bug found by @ElliotBLabs.

For these issues, do we want to add "good first issue" tag to some of them? ICE might be good candidate.

Ty, it sounds good to me.

In that case, please also clean the assignees such that people know they are still available.

shiltian avatar Jun 01 '26 14:06 shiltian

real bug, something is missing, "Preloading hidden arguments is not supported\n"

petar-avramovic avatar Jun 01 '26 15:06 petar-avramovic

cc to keep you posted @CatherineMoore @kzhuravl

mgcarrasco avatar Jun 01 '26 15:06 mgcarrasco

Hi, can I give this a try?

maomao9-0 avatar Jun 01 '26 15:06 maomao9-0

@maomao9-0 please do, thanks.

mgcarrasco avatar Jun 01 '26 16:06 mgcarrasco

Since there's been a week without any updates, could I request this be assigned to me? @mgcarrasco @maomao9-0

keshavvinayak01 avatar Jun 08 '26 07:06 keshavvinayak01

Hi, I'm still working on it, I'll give an update (and I have some questions to ask) in a few hours time.

maomao9-0 avatar Jun 08 '26 07:06 maomao9-0

Oh I'm sorry, please go ahead.

keshavvinayak01 avatar Jun 08 '26 07:06 keshavvinayak01

The following bitcode module triggers an internal compiler error for -global-isel -O1 in f68ef5b.

Module: https://gist.github.com/mgcarrasco/7487ab0bcf8bbd7be854e1bcfe222bbf Reproducer: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx90a -O1 -global-isel module.ll

Better to use godbolt links on bug reports for the future. It's easier to check if an old issue still reproduces

arsenm avatar Jun 08 '26 08:06 arsenm

Hi, this is my first time working on llvm, so over the last week, I familiarized myself with llc and GlobalIsel, focusing on the code related to AMDGPU in particular. I also looked at three related diffs https://github.com/llvm/llvm-project/pull/98861, https://github.com/llvm/llvm-project/pull/116759 and https://github.com/llvm/llvm-project/pull/130434.

However, I am still not very certain of the direction to proceed. From what I see, it does not look like a "bug", but rather a feature that is not implemented yet (as seen in the TODO comment lowerFormalArgumentsKernel of AMDGPUCallLowering). It seems that the path without global-isel option works fine, so I investigated that path and it looks like the preloading of kernel arguments happen in SISelLowering in the lowerFormalArgument as well (by calling allocatePreloadKernArgSGPRs)

Would it make sense to implement something similar for AMDGPUCallLowering? Or am I missing something and there is an actual bug that is not related to the TODO comment? Would appreciate any guidance from someone with more experience. Thank you :)

maomao9-0 avatar Jun 08 '26 13:06 maomao9-0

probably have to implement similar thing as SISelLowering in the lowerFormalArgument in AMDGPUCallLowering, should get similar result to sdag from global-isel instead of failing to compile

petar-avramovic avatar Jun 08 '26 13:06 petar-avramovic

Ok that makes sense thank you 👍

maomao9-0 avatar Jun 08 '26 13:06 maomao9-0

Unfortunately, I still wasn’t able to make significant progress on this :(. @keshavvinayak01, if you’re still interested, I’d be happy to hand this over to you. If you’re open to it, I’d also love to work with you and understand how you would approach tackling this task. Thank you!

maomao9-0 avatar Jun 15 '26 14:06 maomao9-0

Yeah I can take over. As I go through this and work on a solution, you can communicate with me to share your findings/understand how I'm approaching this. (Find me on the LLVM discord).

cc @mgcarrasco

keshavvinayak01 avatar Jun 16 '26 11:06 keshavvinayak01