| Issue |
244587
|
| Summary |
[fuzzer-found][DAGCombiner][M68k] visitANY_EXTEND folds aext(setcc) to select_cc with constant 1 as "true": always-true lanes of `sext <12 x i1>` are stored as 1 instead of -1
|
| Labels |
miscompilation,
backend:m68k,
llvm:SelectionDAG,
generated by fuzzer
|
| Assignees |
|
| Reporter |
YuanchengJiang
|
The following code:
IR-only reproducer (InstCombine folds these compares away from C); run with `llc -O2 -mtriple=m68k -mcpu=M68020 repro.ll -o -`:
```llvm
; [DAGCombiner][M68k] visitANY_EXTEND folds aext(setcc x,y,cc) -> select_cc x,y,1,0,cc with
; the constant 1 as "true". M68k uses ZeroOrNegativeOneBooleanContent, so the setcc value
; is all-ones (0xFF); lanes whose any_extend is folded become 0x01 instead of 0xFF.
; Godbolt: compiler "llc (trunk)" (llctrunk), flags: -O2 -mtriple=m68k -mcpu=M68020
; Look at the stores into the <N x i8> result near the end of @f:
; buggy (trunk): move.b #1, (%a0) ; move.b #-1, (1,%a0) ; move.b #1, (2,%a0) ; ... move.b #1, (4,%a0)
; correct: move.b #-1 for every always-true lane (they are `sext <N x i1>` of compares that
; fold to true after legalization).
; (Generated by an IR fuzzer.)
define void @f(ptr %pa, ptr %pb, ptr %po) noinline {
%a = load <12 x i8>, ptr %pa, align 1
%b = load <12 x i8>, ptr %pb, align 1
%v0 = call <12 x i8> @llvm.umin.v12i8(<12 x i8> %a, <12 x i8> %b)
%c1 = icmp eq <12 x i8> %v0, <i8 128, i8 48, i8 1, i8 127, i8 254, i8 32, i8 221, i8 0, i8 17, i8 0, i8 128, i8 128>
%v1 = zext <12 x i1> %c1 to <12 x i8>
%c2 = icmp uge <12 x i8> %v1, %b
%v2 = select <12 x i1> %c2, <12 x i8> %a, <12 x i8> <i8 255, i8 128, i8 128, i8 128, i8 128, i8 128, i8 128, i8 128, i8 128, i8 128, i8 128, i8 128>
%c3 = icmp sge <12 x i8> %v1, <i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 1, i8 128, i8 255, i8 2, i8 255, i8 254>
%v3 = sext <12 x i1> %c3 to <12 x i8>
store <12 x i8> %v3, ptr %po, align 1
ret void
}
```
Resulted in this output:
```
; tail of @f, stores of the <12 x i8> result
move.b #1, (%a0) ; lane 0: expected -1 (0 >= 0 is always true)
move.b #-1, (1,%a0)
move.b #1, (2,%a0) ; lane 2: expected -1
move.b #-1, (3,%a0)
move.b #1, (4,%a0) ; lane 4: expected -1
move.b #-1, (5,%a0)
move.b #-1, (7,%a0)
```
Lanes 0-5 and 7 compare a 0/1 value with `sge 0` (or `sge -128`), so they are always true and `sext` must give -1 (0xFF).
| lane | expected | actual |
|------|----------|--------|
| 0, 2, 4 | -1 (0xFF) | 1 (0x01) |
| 1, 3, 5, 7 | -1 | -1 |
With the fix, every one of these stores is `move.b #-1`.
Trunk: https://godbolt.org/z/E5c3eMfvj (llc trunk, `-O2 -mtriple=m68k -mcpu=M68020`; reproduces as of 2026-10-22)
Root cause: In `DAGCombiner::visitANY_EXTEND` (llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp), the fold `aext(setcc x,y,cc) -> select_cc x,y,1,0,cc` uses `DAG.getConstant(1, DL, VT)` for the true arm. An `any_extend` may leave the high bits undefined, but its low bits must keep the setcc value, and M68k uses `ZeroOrNegativeOneBooleanContent`, where "true" is all-ones. If `SimplifySelectCC` can decide the compare (always true after legalization), the result folds to the constant 1. The `sext <N x i1>` lanes built from that `any_extend` (through `shl`/`or`) then hold 0x01 instead of 0xFF.
Suggested fix: Use the target's boolean true for the select arm: `DAG.getBoolConstant(true, DL, VT, N0.getOperand(0).getValueType())` instead of `DAG.getConstant(1, DL, VT)`. Validated locally (a local tree carries this fix and the reproducer then emits `move.b #-1` for all always-true lanes).
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs