<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/58699>58699</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Fail to translate the llvm ir to Nvidia PTX code if there exist a 256-bits function parameter.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Kenun99
      </td>
    </tr>
</table>

<pre>
    The PTX backend will raise an error when handing the below IR.   `$ llc ./example.ll -o exe`
Toolchain: pre-compiled releases from Github, clang+llvm-15.0.2-x86_64-unknown-linux-gnu-rhel86.tar.xz
I believe that it is a PTX backend issue because the x86 backend can translate it well, i.e., change the target triple to the default value. 

```
target datalayout = "e-i64:64-i128:128-v16:16-v32:32-n16:32:64"
target triple = "nvptx64-nvidia-cuda"

define  i256 @foo(i256* nocapture readonly byval(i256) align 8 %0) {
  %2 = load i256, i256* %0, align 8
  %3 = add i256 %2, 1
  ret i256 %3
}
```
Crash dump:
```
weimin@ubuntu:~$ ./clang+llvm-15.0.2-x86_64-unknown-linux-gnu/bin/bugpoint -run-llc  t.ll
Read input file      : 't.ll'
*** All input ok
Initializing execution environment: Found llc: /home/weimin/clang+llvm-15.0.2-x86_64-unknown-linux-gnu/bin/llc
Running the code generator to test for a crash: <llc>
Error running tool:
  /home/weimin/clang+llvm-15.0.2-x86_64-unknown-linux-gnu/bin/llc -o bugpoint-test-program-e18d53e.bc-a6c01de.llc.s bugpoint-test-program-e18d53e.bc
free(): invalid pointer
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /home/weimin/clang+llvm-15.0.2-x86_64-unknown-linux-gnu/bin/llc -o bugpoint-test-program-e18d53e.bc-a6c01de.llc.s bugpoint-test-program-e18d53e.bc
1.      Running pass 'Function Pass Manager' on module 'bugpoint-test-program-e18d53e.bc'.
2.      Running pass 'NVPTX DAG->DAG Pattern Instruction Selection' on function '@foo'
 #0 0x0000562b44cf52c3 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/weimin/clang+llvm-15.0.2-x86_64-unknown-linux-gnu/bin/llc+0x266d2c3)
 #1 0x0000562b44cf31be llvm::sys::RunSignalHandlers() (/home/weimin/clang+llvm-15.0.2-x86_64-unknown-linux-gnu/bin/llc+0x266b1be)
 #2 0x0000562b44cf565f SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f113ca94980 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12980)
 #4 0x00007f113b6e3e87 raise /build/glibc-CVJwZb/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
 #5 0x00007f113b6e57f1 abort /build/glibc-CVJwZb/glibc-2.27/stdlib/abort.c:81:0
 #6 0x00007f113b72e837 __libc_message /build/glibc-CVJwZb/glibc-2.27/libio/../sysdeps/posix/libc_fatal.c:181:0
 #7 0x00007f113b7358ba /build/glibc-CVJwZb/glibc-2.27/malloc/malloc.c:5342:0
 #8 0x00007f113b73cdec _int_free /build/glibc-CVJwZb/glibc-2.27/malloc/malloc.c:4167:0
 #9 0x00007f113b73cdec free /build/glibc-CVJwZb/glibc-2.27/malloc/malloc.c:3134:0
#10 0x0000562b43890d39 llvm::NVPTXTargetLowering::LowerReturn(llvm::SDValue, unsigned int, bool, llvm::SmallVectorImpl<llvm::ISD::OutputArg> const&, llvm::SmallVectorImpl<llvm::SDValue> const&, llvm::SDLoc const&, llvm::SelectionDAG&) const (/home/weimin/clang+llvm-15.0.2-x86_64-unknown-linux-gnu/bin/llc+0x1208d39)
#11 0x0000562b49015ab8
*** Debugging code generator crash!

*** Attempting to reduce the number of function attributes in the testcase
Checking for crash with changing conditionals to always jump to true: : <llc><crash>
Emitted bitcode to 'bugpoint-reduced-conditionals.bc'
Checking for crash with only these blocks: : <llc><crash>
Emitted bitcode to 'bugpoint-reduced-blocks.bc'
Checking for crash with CFG simplifying: : <llc><crash>
Emitted bitcode to 'bugpoint-reduced-simplifycfg.bc'
Checking for crash with only 2 instructions: <llc><crash>
Checking for crash with only 1 instruction: <llc><crash>

*** Attempting to reduce testcase by deleting instructions: Simplification Level #1
Checking instruction:   %2 = add i256 undef, 1<llc><crash>

*** Attempting to reduce testcase by deleting instructions: Simplification Level #0
Checking for crash with metadata retained from 1 instruction: <llc><crash>
Emitted bitcode to 'bugpoint-reduced-instructions.bc'

*** Attempting to strip the debug info: <llc><crash>

*** Attempting to strip the debug type info: <llc><crash>

*** Attempting to remove named metadata: Emitted bitcode to 'bugpoint-reduced-named-md.bc'

*** Attempting to perform final cleanups: <llc>
Emitted bitcode to `'bugpoint-reduced-simplified.bc'`
```
Download the bugpoint-reduced-simplified.bc from the below link.
https://drive.google.com/file/d/17dJmObV5RGIcWIESO0V65VeVIltmiK1l/view?usp=sharing
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzFWF9zozgS_zTOiwoKhA34wQ-ZOJ7L7txOapLKXd1LSojG1kZIlAA72U9_LQkc25fJencydSnHFkjq_nWr_6rQ5cvifgPk9v7fpGD8CVRJdkJKYphogTBFwBhtyG4DimyYKoVakw43FCD1jtx8CwkhkzSa0CmRkpNwQlfwzOpGQohUAk3gGex8tJxEl_daS75hQk2SS9IYCLiuGyGhJAYksBZaUhldk8-i2_TFhF4RLplaT-gnKbd1EM_CKKTBc54-ptOgV09K71Qgheqfg7XqA7MBmadhx0z4_IfneGOBCtgCgmYdEfhpCTsSV7Rtb-XhrG_ByYYM9rMcVdAZplrJOrD7dyClRSZCCB1C1Mra70PGa-hwuUDxSafdyxIq1suObJnsISQe1vCNevEf9zhsL1nHJHvRfUcmyZJMKIVApFNUGQotYprjCL-DbZzaURpsE4qDhAbKvXFPuJ7SI7IDqoGk2jbdM9JTW1EKFvC-ZPsN_htxCwWECDpLyWQaVVpPaG6fJvSSKM1Z0_UG8ORYqZV8IcULirhfMidMirUiOXKbRfZ5kn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