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

    <tr>
        <th>Summary</th>
        <td>
            Hang while building 32-bit arm Linux 5.4 kernel after 9485d983ac0c
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            llvm:instcombine,
            llvm:hang
      </td>
    </tr>

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

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

<pre>
    After https://github.com/llvm/llvm-project/commit/9485d983ac0c56d412c958b40f4e150a3c30ca7c, I noticed my `ARCH=arm` Linux kernel builds from the `linux-5.4.y` branch were hanging, with `clang` appearing to be in an infinite loop in two of the files.

A C reproducer from `cvise`:

```c
unsigned bpf_prog_calc_tag___trans_tmp_3;
long bpf_prog_calc_tag_bits;
long __fswab64(long long val) {
  unsigned h = val >> 32, t;
  int x = h;
  if (!__builtin_constant_p(h))
    asm("" : "=r"(t));
  else
    t = h << 16 | h >> 16;
  x ^= t >> 8;
  return x;
}
void bpf_prog_calc_tag() {
  bpf_prog_calc_tag_bits = __fswab64(bpf_prog_calc_tag___trans_tmp_3);
}
```

Before patch:

```
Benchmark 1: clang --target=arm-linux-gnueabi -O2 -c -o /dev/null core.i
  Time (mean ± σ):      18.3 ms ±   0.2 ms    [User: 9.1 ms, System: 9.0 ms]
  Range (min … max):    17.3 ms …  19.2 ms    1000 runs
```

After patch:

```
$ timeout 5s clang --target=arm-linux-gnueabi -O2 -c -o /dev/null core.i

$ echo $status
124
```

An LLVM IR reproducer from `llvm-reduce`:

```
target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
target triple = "armv4t-unknown-linux-gnueabi"

define i32 @__fswab64(i64 %val, i32 %conv) {
entry:
  %0 = lshr i64 %val, 32
  %conv1 = trunc i64 %0 to i32
  %1 = call i1 @llvm.is.constant.i32(i32 %conv1)
  br i1 %1, label %if.else, label %if.then

if.then:                                          ; preds = %entry
  %2 = load volatile i32, ptr null, align 2147483648
  br label %if.end

if.else:                                          ; preds = %entry
  %or = call i32 @llvm.fshl.i32(i32 %conv1, i32 %conv, i32 16)
  br label %if.end

if.end:                                           ; preds = %if.else, %if.then
  %t.0 = phi i32 [ %or, %if.else ], [ %2, %if.then ]
  %shr2 = lshr i32 %t.0, 1
  ret i32 %shr2
}

; Function Attrs: convergent nocallback nofree nosync nounwind willreturn memory(none)
declare i1 @llvm.is.constant.i32(i32) #0

define void @bpf_prog_calc_tag(ptr %bpf_prog_calc_tag___trans_tmp_3, i32 %0) {
entry:
  %conv = zext i32 %0 to i64
  %call1 = call i32 @__fswab64(i64 %conv, i32 0)
  store i32 %call1, ptr %bpf_prog_calc_tag___trans_tmp_3, align 4
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.fshl.i32(i32, i32, i32) #1

attributes #0 = { convergent nocallback nofree nosync nounwind willreturn memory(none) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
```

Before patch:

```
Benchmark 1: opt -O2 -disable-output reduced.ll
  Time (mean ± σ):       8.9 ms ±   0.2 ms    [User: 3.6 ms, System: 5.1 ms]
  Range (min … max):     7.9 ms …   9.7 ms    1000 runs
```

After patch:

```
$ timeout 3s opt -O2 -disable-output reduced.ll

$ echo $status
124
```

If there is any additional information I can provide or patches I can test, I am more than happy to do so.

cc @pmatos @nikic 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0WF2P4yrS_jXkpmTLBtuxL3KR7p7ojDSvXmnO7t5GGOOYbQwW4HRnf_0KyIfT02d6Wjtn1OPYxQP1XRRQa8VBcb5B5QMqn1Z0doM2G0XdQBXz__mq1d1ps-0dNzA4N1lEtgjvEN4dhBvmNmV6RHgn5fHyk0xG_5szh_CO6XEU_qUp6rJrakJZxsqqK3LMmrJui6wveF5mlDCSMbpmCD_CV1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