| Issue |
244804
|
| Summary |
[DAGCombiner] Assertion failed at -O1 and above: `!Loads.empty() && "All the bytes of the value must be loaded from memory..."` in MatchLoadCombine at -O1 (`_BitInt(1024)` sub_overflow & select)
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
haoxintu
|
## Description
```c
int c;
void f(long e, long b)
{
_BitInt(7) a = e;
unsigned _BitInt(1024) g;
_Bool o = __builtin_sub_overflow(0, a, &g);
c = ((g + o) & __builtin_clzg((unsigned _BitInt(2))(b & 1), 2)) != 0;
}
```
```
$ clang -O1 -c repro.c
clang: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:10370: llvm::SDValue {anonymous}::DAGCombiner::MatchLoadCombine(llvm::SDNode*): Assertion `!Loads.empty() && "All the bytes of the value must be loaded from " "memory, so there must be at least one load which produces the value"' failed.
...
3. Running pass 'Function Pass Manager' on module 'repro.c'.
4. Running pass 'X86 DAG->DAG Instruction Selection' on function '@f'
#12 (anonymous namespace)::DAGCombiner::MatchLoadCombine(llvm::SDNode*)
#13 (anonymous namespace)::DAGCombiner::visitOR(llvm::SDNode*)
#14 (anonymous namespace)::DAGCombiner::combine(llvm::SDNode*)
```
It crashes at -O1/-O2/-O3/-Os; -O0 is fine. IR reproducer (`llc -O1 repro.ll`):
```llvm
target triple = "x86_64-unknown-linux-gnu"
define i1 @f(i64 %a0, i64 %b0) {
entry:
%conv1.mask = and i64 %b0, 1
%conv = trunc i64 %a0 to i7
%conv10 = sext i7 %conv to i256
%0 = zext i256 %conv10 to i1024
%1 = tail call { i1024, i1 } @llvm.usub.with.overflow.i1024(i1024 0, i1024 %0)
%2 = extractvalue { i1024, i1 } %1, 0
%iszero = icmp eq i64 %conv1.mask, 0
%conv17 = select i1 %iszero, i1024 2, i1024 1
%and = and i1024 %2, %conv17
%cmp = icmp ne i1024 %and, 0
ret i1 %cmp
}
declare { i1024, i1 } @llvm.usub.with.overflow.i1024(i1024, i1024)
```
There is no load in the function, so the byte-provider walk in `MatchLoadCombine` finds providers for all bytes of an `or` (the last combine before the assert is `t170: i64 = or t145, t120`) without any of them being a load. Probably some bytes are constant zero, which the AND-mask lookthrough (#200247) now accepts.
Reproduced in Godbolt (x86-64 clang assertions trunk, -O1): https://godbolt.org/z/7KjWM5ejd
Thanks.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs