[llvm] [ConstraintElim] Simplify cmp after uadd.sat/usub.sat (PR #135603)

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 17 18:16:55 PDT 2025


aeubanks wrote:

I believe this is causing a miscompile:

```
$ cat /tmp/a.ll
define i1 @f(i64 %conv6, i64 %str.coerce, ptr %conv) {
  %a = load i32, ptr %conv, align 4
  %cmp = icmp sgt i32 %a, -1
  %conv2 = zext nneg i32 %a to i64
  %add = add i64 %str.coerce, %conv6
  %spec.select = call i64 @llvm.usub.sat.i64(i64 %conv2, i64 %add)
  ret i1 %cmp
}

declare i64 @llvm.usub.sat.i64(i64, i64)

$ opt -p constraint-elimination -S /tmp/a.ll
define i1 @f(i64 %conv6, i64 %str.coerce, ptr %conv) {
  %a = load i32, ptr %conv, align 4
  %conv2 = zext nneg i32 %a to i64
  %add = add i64 %str.coerce, %conv6
  %spec.select = call i64 @llvm.usub.sat.i64(i64 %conv2, i64 %add)
  ret i1 true
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.usub.sat.i64(i64, i64) #0
```

https://github.com/llvm/llvm-project/pull/135603


More information about the llvm-commits mailing list