<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64403>64403</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Codegen crash with large array in rust
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
P1n3appl3
</td>
</tr>
</table>
<pre>
Minimized bitcode from bugpoint: [bugpoint-reduced-simplified.bc.tar.gz](https://github.com/llvm/llvm-project/files/12255999/bugpoint-reduced-simplified.bc.tar.gz)
<details>
<summary><code>llc</code> stacktrace with minimized bitcode</summary>
```
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: llc bugpoint-reduced-simplified.bc
1. Running pass 'Function Pass Manager' on module 'bugpoint-reduced-simplified.bc'.
2. Running pass 'X86 DAG->DAG Instruction Selection' on function '@_ZN4core3ptr13read_volatile17h99ddefc4e9ada7d9E'
#0 0x00007f1c580c150e llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/nix/store/5z3ghpa4ql3mwiiv2qmnr4s31vw25b69-llvm-16.0.6-lib/lib/libLLVM-16.so+0x10c150e)
#1 0x00007f1c580bec7b SignalHandler(int) (/nix/store/5z3ghpa4ql3mwiiv2qmnr4s31vw25b69-llvm-16.0.6-lib/lib/libLLVM-16.so+0x10bec7b)
#2 0x00007f1c56a52d30 __restore_rt (/nix/store/1x4ijm9r1a88qk7zcmbbfza324gx1aac-glibc-2.37-8/lib/libc.so.6+0x38d30)
#3 0x00007f1c58b36a8f llvm::SelectionDAG::ReplaceAllUsesWith(llvm::SDNode*, llvm::SDValue const*) (/nix/store/5z3ghpa4ql3mwiiv2qmnr4s31vw25b69-llvm-16.0.6-lib/lib/libLLVM-16.so+0x1b36a8f)
#4 0x00007f1c58975b72 (anonymous namespace)::DAGCombiner::visit(llvm::SDNode*) (/nix/store/5z3ghpa4ql3mwiiv2qmnr4s31vw25b69-llvm-16.0.6-lib/lib/libLLVM-16.so+0x1975b72)
#5 0x00007f1c5897766d (anonymous namespace)::DAGCombiner::combine(llvm::SDNode*) (/nix/store/5z3ghpa4ql3mwiiv2qmnr4s31vw25b69-llvm-16.0.6-lib/lib/libLLVM-16.so+0x197766d)
#6 0x00007f1c58978d4f llvm::SelectionDAG::Combine(llvm::CombineLevel, llvm::AAResults*, llvm::CodeGenOpt::Level) (/nix/store/5z3ghpa4ql3mwiiv2qmnr4s31vw25b69-llvm-16.0.6-lib/lib/libLLVM-16.so+0x1978d4f)
#7 0x00007f1c58b4f5c1 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/nix/store/5z3ghpa4ql3mwiiv2qmnr4s31vw25b69-llvm-16.0.6-lib/lib/libLLVM-16.so+0x1b4f5c1)
#8 0x00007f1c58b52355 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/nix/store/5z3ghpa4ql3mwiiv2qmnr4s31vw25b69-llvm-16.0.6-lib/lib/libLLVM-16.so+0x1b52355)
#9 0x00007f1c58b54a15 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (.part.0) (/nix/store/5z3ghpa4ql3mwiiv2qmnr4s31vw25b69-llvm-16.0.6-lib/lib/libLLVM-16.so+0x1b54a15)
#10 0x00007f1c5ba53750 (anonymous namespace)::X86DAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/nix/store/5z3ghpa4ql3mwiiv2qmnr4s31vw25b69-llvm-16.0.6-lib/lib/libLLVM-16.so+0x4a53750)
#11 0x00007f1c585686b8 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) (/nix/store/5z3ghpa4ql3mwiiv2qmnr4s31vw25b69-llvm-16.0.6-lib/lib/libLLVM-16.so+0x15686b8)
#12 0x00007f1c582407f0 llvm::FPPassManager::runOnFunction(llvm::Function&) (/nix/store/5z3ghpa4ql3mwiiv2qmnr4s31vw25b69-llvm-16.0.6-lib/lib/libLLVM-16.so+0x12407f0)
#13 0x00007f1c5824091c llvm::FPPassManager::runOnModule(llvm::Module&) (/nix/store/5z3ghpa4ql3mwiiv2qmnr4s31vw25b69-llvm-16.0.6-lib/lib/libLLVM-16.so+0x124091c)
#14 0x00007f1c5824129d llvm::legacy::PassManagerImpl::run(llvm::Module&) (/nix/store/5z3ghpa4ql3mwiiv2qmnr4s31vw25b69-llvm-16.0.6-lib/lib/libLLVM-16.so+0x124129d)
#15 0x0000000000418ab4 compileModule(char**, llvm::LLVMContext&) (/nix/store/1c4kdhhpxjhf7zr3c9432wlbbf93m447-llvm-16.0.6/bin/llc+0x418ab4)
#16 0x000000000040f54e main (/nix/store/1c4kdhhpxjhf7zr3c9432wlbbf93m447-llvm-16.0.6/bin/llc+0x40f54e)
#17 0x00007f1c56a3dace __libc_start_call_main (/nix/store/1x4ijm9r1a88qk7zcmbbfza324gx1aac-glibc-2.37-8/lib/libc.so.6+0x23ace)
#18 0x00007f1c56a3db89 __libc_start_main@GLIBC_2.2.5 (/nix/store/1x4ijm9r1a88qk7zcmbbfza324gx1aac-glibc-2.37-8/lib/libc.so.6+0x23b89)
#19 0x000000000040fc95 _start (/nix/store/1c4kdhhpxjhf7zr3c9432wlbbf93m447-llvm-16.0.6/bin/llc+0x40fc95)
zsh: segmentation fault llc bugpoint-reduced-simplified.bc
```
</details>
LLVM version: `16.0.5`
`rustc` version: `1.72.0-nightly` (reproduces on multiple nightly versions, including `d9c13cd45 2023-07-05` and `75726cae3 2023-06-28`
I'm getting a crash in LLVM codegen with the following rust code:
```rust
fn main() {
criterion::Benchmark::new("big array", move |b| { // with criterion version 0.2.11
// b.iter(|| [0u8; 2usize.pow(15)]); // doesn't crash
b.iter(|| [0u8; 2usize.pow(16)]); // crashes
});
}
```
The above is a minimization of [this code](https://cs.opensource.google/fuchsia/fuchsia/+/main:src/lib/diagnostics/log/bench/src/encoding.rs) from Fuchsia where we originally observed the issue. There it manifested as taking multiple minutes to eventually OOM when attempting to build on various machines. I believe that the crash that we're seeing in this minimized version is due to the same issue, since both are affected by the array size.
<details>
<summary>Stacktrace from failed fuchsia build</summary>
```
/fuchsia/prebuilt/third_party/rust/linux-x64/bin/../lib/../lib/libLLVM-16-rust-1.72.0-nightly.so(_ZN4llvm12SelectionDAG21RemoveNodeFromCSEMapsEPNS_6SDNodeE+0x74)[0x7fd0ced34244]
/fuchsia/prebuilt/third_party/rust/linux-x64/bin/../lib/../lib/libLLVM-16-rust-1.72.0-nightly.so(_ZN4llvm12SelectionDAG18ReplaceAllUsesWithEPNS_6SDNodeEPKNS_7SDValueE+0x155)[0x7fd0ced7d125]
/fuchsia/prebuilt/third_party/rust/linux-x64/bin/../lib/../lib/libLLVM-16-rust-1.72.0-nightly.so(+0x273a066)[0x7fd0ceb3a066]
/fuchsia/prebuilt/third_party/rust/linux-x64/bin/../lib/../lib/libLLVM-16-rust-1.72.0-nightly.so(+0x2777330)[0x7fd0ceb77330]
/fuchsia/prebuilt/third_party/rust/linux-x64/bin/../lib/../lib/libLLVM-16-rust-1.72.0-nightly.so(+0x273f07d)[0x7fd0ceb3f07d]
/fuchsia/prebuilt/third_party/rust/linux-x64/bin/../lib/../lib/libLLVM-16-rust-1.72.0-nightly.so(_ZN4llvm12SelectionDAG7CombineENS_12CombineLevelEPNS_9AAResultsENS_10CodeGenOpt5LevelE+0xf69)[0x7fd0ceb3bcf9]
/fuchsia/prebuilt/third_party/rust/linux-x64/bin/../lib/../lib/libLLVM-16-rust-1.72.0-nightly.so(_ZN4llvm16SelectionDAGISel17CodeGenAndEmitDAGEv+0xbb)[0x7fd0ced932fb]
/fuchsia/prebuilt/third_party/rust/linux-x64/bin/../lib/../lib/libLLVM-16-rust-1.72.0-nightly.so(_ZN4llvm16SelectionDAGISel20SelectAllBasicBlocksERKNS_8FunctionE+0x2162)[0x7fd0ced925c2]
/fuchsia/prebuilt/third_party/rust/linux-x64/bin/../lib/../lib/libLLVM-16-rust-1.72.0-nightly.so(_ZN4llvm16SelectionDAGISel20runOnMachineFunctionERNS_15MachineFunctionE+0x9c5)[0x7fd0ced8f345]
/fuchsia/prebuilt/third_party/rust/linux-x64/bin/../lib/../lib/libLLVM-16-rust-1.72.0-nightly.so(_ZN4llvm19MachineFunctionPass13runOnFunctionERNS_8FunctionE+0x318)[0x7fd0ce7f8078]
/fuchsia/prebuilt/third_party/rust/linux-x64/bin/../lib/../lib/libLLVM-16-rust-1.72.0-nightly.so(_ZN4llvm13FPPassManager13runOnFunctionERNS_8FunctionE+0x508)[0x7fd0ce4f20a8]
/fuchsia/prebuilt/third_party/rust/linux-x64/bin/../lib/../lib/libLLVM-16-rust-1.72.0-nightly.so(_ZN4llvm13FPPassManager11runOnModuleERNS_6ModuleE+0x33)[0x7fd0ce4fbd73]
/fuchsia/prebuilt/third_party/rust/linux-x64/bin/../lib/../lib/libLLVM-16-rust-1.72.0-nightly.so(_ZN4llvm6legacy15PassManagerImpl3runERNS_6ModuleE+0x9e7)[0x7fd0ce4f2ef7]
/fuchsia/prebuilt/third_party/rust/linux-x64/bin/../lib/librustc_driver-9d2b497b46d0ef1c.so(+0x4136e8e)[0x7fd0d5936e8e]
/fuchsia/prebuilt/third_party/rust/linux-x64/bin/../lib/librustc_driver-9d2b497b46d0ef1c.so(+0x1bdcca0)[0x7fd0d33dcca0]
/fuchsia/prebuilt/third_party/rust/linux-x64/bin/../lib/librustc_driver-9d2b497b46d0ef1c.so(+0x1be0bbc)[0x7fd0d33e0bbc]
/fuchsia/prebuilt/third_party/rust/linux-x64/bin/../lib/librustc_driver-9d2b497b46d0ef1c.so(+0x1c0cfb6)[0x7fd0d340cfb6]
/fuchsia/prebuilt/third_party/rust/linux-x64/bin/../lib/librustc_driver-9d2b497b46d0ef1c.so(+0x1c0d4e2)[0x7fd0d340d4e2]
/fuchsia/prebuilt/third_party/rust/linux-x64/bin/../lib/librustc_driver-9d2b497b46d0ef1c.so(+0x1c8aee9)[0x7fd0d348aee9]
/fuchsia/prebuilt/third_party/rust/linux-x64/bin/../lib/librustc_driver-9d2b497b46d0ef1c.so(+0x1c94002)[0x7fd0d3494002]
/fuchsia/prebuilt/third_party/rust/linux-x64/bin/../lib/libstd-470a3e6f12b1a352.so(rust_metadata_std_200cbbd68e3b9d04+0x10b085)[0x7fd0d5cd5085]
/lib/x86_64-linux-gnu/libc.so.6(+0x88fd4)[0x7fd0d16a7fd4]
/lib/x86_64-linux-gnu/libc.so.6(+0x1095bc)[0x7fd0d17285bc]
```
</details>
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMWltv2zjT_jXKDWGBInW8yIXj2P2Kr4eg6bvvYm8MihzJ3OrgJSnn8OtfkJQdy3W37WLTJChUaUQNn2c4JIcPzLSWdQdwGSRXQXJ9wQaz6dXlTdRRtt029KLsxcPle9nJVj6CQKU0vBeAKtW3qBzqbS87E9A5CpKr_eNMgRg4iJmW7baRlQQRljw0TIX1Y5BcByTfGLPVAZ0HZBWQVS3NZihD3rcBWTXNbv_fbKv6P4GbgKwq2YAOyCoiJEmKogjI6se6I0WArwM8H690IcAw2eiALg8mPbQtUw_WRBeWXkCXTcMDugjIanxG2jD-xSjGAd1Js0HtaUx88yNfx_2mePznHm_eLee3S6SHspUGMRtIpGDbK4NMj346OFLrwUUHsU4g2fFmEIDMBhBXTG9QuUce-u5vLRUkhnZre3EmHAa4uFF9rViLmKqHFjpjQaCm4ejvQ-09RNbDp6HrZFejLdMaBSRbDR03su_QjTW8Zx2rQQUkQ32H2l4MDdhW33FPshE3OdfF73mKrudvZgFdXs_foLedNmrwnd5CA-5u7LHaowlIFsR4_ceHmPcK6NaoiCpgYr3rG2ZkA1G2KQohoOIxFEywTBRL-5GDgQJCMcL3GGOcVRFPcsyjBANyo0PnAZ3rB-1vbpTsjIv3ZzsAAcmfGil2t-61UcDagKQBWSA7l0iBApIHZNXJe5tPplcQkFXySOvNlsV_NbS9k3JH_mo7FWsa7e5IUqbFzOVElIY4TGeNLG2W7K_v3v323r7SfUCu8H3k4R6mhuUTTfmUwLM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