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

    <tr>
        <th>Summary</th>
        <td>
            [LoopInterchange]  Assertion `getActiveBits() <= 64 && "Too many bits for uint64_t"
        </td>
    </tr>

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

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

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

<pre>
    With these options and "-O3 --target=aarch64 func.cpp -enable-loopinterchange" and this input:
```
unsigned int A[11][11][11] __attribute__((aligned(16)));
void a(int b) {
  for (int c;; c += b)
    for (long d = 0; d < -3ULL; d += 2ULL)
      A[c][d][d] = 0;
}
```

Loop-interchange runs in an assert:

```
llvm-project/llvm/include/llvm/ADT/APInt.h:1501: uint64_t llvm::APInt::getZExtValue() const: Assertion `getActiveBits() <= 64 && "Too many bits for uint64_t"' failed.
```

IR reproducer:

```
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32"
target triple = "aarch64-unknown-linux-gnu"

@A = local_unnamed_addr global [11 x [11 x [11 x i32]]] zeroinitializer, align 16

define void @_Z1ai(i32 noundef %b) local_unnamed_addr #0 {
entry:
  %0 = sext i32 %b to i64
  br label %for.cond

; Loop:
for.cond: ; preds = %for.cond.cleanup, %entry
  %indvars.iv = phi i64 [ %indvars.iv.next, %for.cond.cleanup ], [ 0, %entry ]
  br label %for.body

for.cond.cleanup:                                 ; preds = %for.body
  %indvars.iv.next = add nsw i64 %indvars.iv, %0
  br label %for.cond

for.body:                                         ; preds = %for.cond, %for.body
  %d.010 = phi i64 [ 0, %for.cond ], [ %add, %for.body ]
  %arrayidx3 = getelementptr inbounds [11 x [11 x [11 x i32]]], ptr @A, i64 0, i64 %indvars.iv, i64 %d.010, i64 %d.010
  store i32 0, ptr %arrayidx3, align 4
  %add = add nuw i64 %d.010, 2
  %cmp = icmp ult i64 %d.010, -5
  br i1 %cmp, label %for.body, label %for.cond.cleanup
}
```

Compile with: "opt -passes=loop-interchange -S"
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0Vk2P4ygT_jXkUnKEwXaSQw5O521ppJHe1c7srjSXCJtKzCwBC3B3en79CuJO3Elvqy8bOTZQH9TzFAUI79XBIK5JuSHldiaG0Fm39j8tOnlE9RPdrLHyZf2XCh2EDj2C7YOyxoMwEghj2f85ZFkQ7oCB8K0Qru2qAvaDaedt30OGRjQaM21tr0xA13bCHJAwljyETnlQph8C4TWhW0JrUtHxSd3BpBglKBOgJuUmz0m5vf3CbidCcKoZAu52hC0JWwqdDAlb5hVhq_Hhm7PfJ6skCMKW0W9D2ArIYhQB7K2DUdRGC76BFgjbEL5Nuq96F01tzQEkRDmN2rH5ABn_4-vXsXs2ZnFgag8JU3uGIq-fi6uRlMX2XXbO76_W9tmEXXCDibSCMCC8Rzdh9z0vWj8ds97Zn9gGwh5jl7BHZVo9SLwO1Nvv8f3bFxPmHeF1XtKc8BoGZUJV7AIkPV4TXielc_OA4cf_TuFPoQdMiVlBa42PUqhTcMoaIBU9YKjboJ5wo4IfNQl_iERUBRBWEVbFJffdWjgK8wKNCj4l4DUAwhhhC9gLpVHOPyDsy-_gsHdWDi26j7k5L22QIggtXuwQUmYIY5hFrJipJeF1_HOWqbyKvFRjryoIr6siUzmLCjlbZoaz89i32HuMXcbezBSc6jW-zjIWVDaYv419NplWZjhlBzNczMZ3Qetko20r9G4wRhxR7oSUDg7aNkJDqhU43X0VZ2ndxQd-obPKqKCEVr_QEfYAqY4gr6bTSdwrg5CKiBR09yMXKhYMZ2DsYCTugbAyldU7ARHG6bXc0AT3ckkCREOaoHg8hRhdcgXBQiR0VGocaNGgjrK9dfPWGvmGD76BWBYXvxclHnnaQO9Q-pHli4d5q1GYoY-wCSvPkV3DUkY-Cefn6ikZ9p2KIUUi30rnBk9h9HHrGiL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