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

    <tr>
        <th>Summary</th>
        <td>
            [LSR] Assertion `(!F.ScaledReg || !F.ScaledReg->isZero()) && "Zero allocated in a scaled register!"' failed.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          max-quazan
      </td>
    </tr>
</table>

<pre>
    https://godbolt.org/z/65j5Wfd95

Run llc on the following test:
```
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128-ni:1-p2:32:8:8:32-ni:2"
target triple = "x86_64-unknown-linux-gnu"

define void @test() {
bb:
  %tmp = load atomic i64, i64 addrspace(1)* undef unordered, align 8
  %tmp1 = sub i64 4294967294, undef
  br label %bb5

bb2:                                              ; No predecessors!
  %tmp3 = add i32 undef, %tmp24
  unreachable

bb5:                                              ; preds = %bb5, %bb
  %tmp6 = phi i64 [ %tmp18, %bb5 ], [ %tmp, %bb ]
  %tmp7 = phi i32 [ %tmp19, %bb5 ], [ undef, %bb ]
  %tmp8 = phi i32 [ %tmp24, %bb5 ], [ undef, %bb ]
  %tmp9 = sub i32 %tmp8, undef
  %tmp10 = zext i32 %tmp9 to i64
  %tmp11 = add i32 %tmp7, 1
  %tmp12 = zext i32 %tmp11 to i64
  %tmp13 = add i64 %tmp1, %tmp12
  %tmp14 = add i64 %tmp6, %tmp10
  %tmp15 = sub i64 %tmp14, %tmp13
  %tmp16 = trunc i64 %tmp15 to i32
  %tmp17 = add i32 undef, %tmp16
  %tmp18 = add i64 %tmp6, 2
  %tmp19 = add i32 %tmp7, 2
  %tmp20 = xor i64 %tmp6, -1
  %tmp21 = add i64 %tmp1, %tmp20
  %tmp22 = trunc i64 %tmp21 to i32
  %tmp23 = add i32 %tmp19, %tmp22
  %tmp24 = add i32 %tmp17, %tmp23
  br label %bb5
}

```

Crash would be
```
llc: /root/llvm-project/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1582: bool {anonymous}::LSRUse::InsertFormula(const {anonymous}::Formula&, const llvm::Loop&): Assertion `(!F.ScaledReg || !F.ScaledReg->isZero()) && "Zero allocated in a scaled register!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/llc -o /app/output.s <source>
1.      Running pass 'Function Pass Manager' on module '<source>'.
2.      Running pass 'Loop Pass Manager' on function '@test'
3.      Running pass 'Loop Strength Reduction' on basic block '%bb5'
 #0 0x00005602a00f6dff PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #1 0x00005602a00f482c SignalHandler(int) Signals.cpp:0:0
 #2 0x00007fe80ae843c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x143c0)
 #3 0x00007fe80a95103b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4303b)
 #4 0x00007fe80a930859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #5 0x00007fe80a930729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #6 0x00007fe80a942006 (/lib/x86_64-linux-gnu/libc.so.6+0x34006)
 #7 0x000056029fae12c8 (anonymous namespace)::LSRUse::InsertFormula((anonymous namespace)::Formula const&, llvm::Loop const&) LoopStrengthReduce.cpp:0:0
 #8 0x000056029fae134d (anonymous namespace)::LSRInstance::InsertFormula((anonymous namespace)::LSRUse&, unsigned int, (anonymous namespace)::Formula const&) LoopStrengthReduce.cpp:0:0
 #9 0x000056029faefd4d (anonymous namespace)::LSRInstance::GenerateAllReuseFormulae() LoopStrengthReduce.cpp:0:0
#10 0x000056029faf7260 (anonymous namespace)::LSRInstance::LSRInstance(llvm::Loop*, llvm::IVUsers&, llvm::ScalarEvolution&, llvm::DominatorTree&, llvm::LoopInfo&, llvm::TargetTransformInfo const&, llvm::AssumptionCache&, llvm::TargetLibraryInfo&, llvm::MemorySSAUpdater*) LoopStrengthReduce.cpp:0:0
#11 0x000056029fafa65f ReduceLoopStrength(llvm::Loop*, llvm::IVUsers&, llvm::ScalarEvolution&, llvm::DominatorTree&, llvm::LoopInfo&, llvm::TargetTransformInfo const&, llvm::AssumptionCache&, llvm::TargetLibraryInfo&, llvm::MemorySSA*) LoopStrengthReduce.cpp:0:0
#12 0x000056029fafd99b (anonymous namespace)::LoopStrengthReduce::runOnLoop(llvm::Loop*, llvm::LPPassManager&) LoopStrengthReduce.cpp:0:0
#13 0x000056029f004cb3 llvm::LPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2204cb3)
#14 0x000056029f8cb3d6 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2acb3d6)
#15 0x000056029f8cb729 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2acb729)
#16 0x000056029f8cc089 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2acc089)
#17 0x000056029d9a9256 compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
#18 0x000056029d901607 main (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0xb01607)
#19 0x00007fe80a9320b3 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x240b3)
#20 0x000056029d99fc1a _start (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0xb9fc1a)
Compiler returned: 139
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztWVtznLgS_jX4RTVTIO4PfhjfzqbKOcflyeZUnReXADHDBiRWiGScX7_dgsGIjGM7m9rKw3HNYJDUX3_qbnU3diaLx_O91m3n-BuH3sBnJ4tM1not1Q6evsI3Cv8I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