[all-commits] [llvm/llvm-project] 287294: [ConstraintElim] Do not allow overflows in `Decomp...

Yingwei Zheng via All-commits all-commits at lists.llvm.org
Wed May 21 20:31:25 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 287294d54d7a806e70b0061cf5ccc1fc2bd03eea
      https://github.com/llvm/llvm-project/commit/287294d54d7a806e70b0061cf5ccc1fc2bd03eea
  Author: Yingwei Zheng <dtcxzyw2333 at gmail.com>
  Date:   2025-05-22 (Thu, 22 May 2025)

  Changed paths:
    M llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
    M llvm/test/Transforms/ConstraintElimination/constraint-overflow.ll

  Log Message:
  -----------
  [ConstraintElim] Do not allow overflows in `Decomposition` (#140541)

Consider the following case:
```
define i1 @pr140481(i32 %x) {
  %cond = icmp slt i32 %x, 0
  call void @llvm.assume(i1 %cond)
  %add = add nsw i32 %x, 5001000
  %mul1 = mul nsw i32 %add, -5001000
  %mul2 = mul nsw i32 %mul1, 5001000
  %cmp2 = icmp sgt i32 %mul2, 0
  ret i1 %cmp2
}
```
Before this patch, `decompose(%mul2)` returns `-25010001000000 * %x +
4052193514966861312`.
Therefore, `%cmp2` will be simplified into true because `%x s< 0 &&
-25010001000000 * %x + 4052193514966861312 s<= 0` is unsat.

It is incorrect since the offset `-25010001000000 * 5001000 ->
4052193514966861312` signed wraps.
This patch treats a decomposition as invalid if overflows occur when
computing coefficients.

Closes https://github.com/llvm/llvm-project/issues/140481.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list