Issue 233689
Summary [SandboxVectorizer] A bundle of `udiv exact` and `udiv` is widened with the first lane's `exact` flag
Labels miscompilation, vectorizers, generated by fuzzer
Assignees
Reporter ChoKyuWon
    ### reproducer
godbolt: https://godbolt.org/z/6xa3qedsW

```llvm
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@out = global [2 x i32] zeroinitializer, align 4

define void @f(i32 %x, i32 %y) {
entry:
  %a = udiv exact i32 %x, 3
  %b = udiv i32 %y, 3
  store i32 %a, ptr @out, align 4
  %p = getelementptr inbounds [2 x i32], ptr @out, i64 0, i64 1
  store i32 %b, ptr %p, align 4
  ret void
}

define i32 @main() {
entry:
 call void @f(i32 3, i32 1)
  %x = load i32, ptr @out, align 4
  %p = getelementptr inbounds [2 x i32], ptr @out, i64 0, i64 1
  %y = load i32, ptr %p, align 4
  %s = add i32 %x, %y
  ret i32 %s
}
```

```console
$ opt -S -passes=sandbox-vectorizer repro.ll
define void @f(i32 %x, i32 %y) {
entry:
  %Pack = insertelement <2 x i32> poison, i32 %x, i32 0, !sandboxvec !0
  %Pack1 = insertelement <2 x i32> %Pack, i32 %y, i32 1, !sandboxvec !0
  %Vec = udiv exact <2 x i32> %Pack1, splat (i32 3), !sandboxvec !0
  store <2 x i32> %Vec, ptr @out, align 4, !sandboxvec !0
 ret void
}

$ llubi repro.ll; echo $?
1
$ opt -S -passes=sandbox-vectorizer repro.ll | llubi -
error: Execution of function 'main' resulted in poison return value.

$ # local alive-tv (LLVM 6af0a79d7a4e); the Alive2 web instance does not run sandbox-vectorizer
$ alive-tv --disable-undef-input --disable-poison-input --passes=sandbox-vectorizer repro.ll
ERROR: Mismatch in memory
Example:
i32 %x = #x00000003 (3)
i32 %y = #x00000002 (2)
...
Mismatch in pointer(non-local, block_id=0, offset=4)
Source value: #x00000000
Target value: poison
```

### suggested fix
`BundleVec::createVectorInstr` (BundleVec.cpp) creates the vector binop with `BinaryOperator::createWithCopiedFlags(..., BinOp0, ...)`, i.e. with the flags of lane 0 only. `LegalityAnalysis` packs bundles whose fast-math or `nuw`/`nsw` flags differ, but does not compare `exact` or `disjoint` (an `or disjoint` / `or` pair becomes `or disjoint <2 x i32>` the same way).
Intersect the flags of all lanes on the new instruction (e.g. `llvm::Instruction::andIRFlags` over the bundle), or reject such bundles in Legality.

> Disclaimer: This test case was generated by a fuzzer, and the report was written with LLM assistance.

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to