[llvm] [InstCombine] Optimize and of overflow checks (PR #141962)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 19 05:16:07 PDT 2026


dtcxzyw wrote:

The following correctness issue was found by [llvm-hackme](https://github.com/dtcxzyw/llvm-hackme).

<!-- llvm-hackme-state: bug_found -->
<!-- llvm-hackme-baseline: 5cae63bd0d31118a15481fc7e5b063a73492d77d -->
<!-- llvm-hackme-head-sha: ad5e0f3cb9f948fc53f5c6136d88cfd23b8804ef -->
<!-- llvm-hackme-patch-sha256: 4f58b8dcad32e9e1c87254a911a2f7b6096e6449f5a4ffe542e952620464a137 -->
<!-- llvm-hackme-kind: miscompilation -->

This comment is generated by an automated correctness checking service designed to help identify critical correctness bugs (opt crashes or Alive2 miscompilations) and improve PR review efficiency under limited reviewer bandwidth.

The reproducer was generated by LLM.

This bug is a regression introduced by this PR. It does not reproduce on the baseline commit.

## Reproducer

**Kind**: miscompilation

**IR Reproducer**:
```llvm
; RUN: opt -passes=instcombine<no-verify-fixpoint> -S
define i1 @f(i8 %x, i8 %y) {
  %not.x = xor i8 %x, -1
  %cmp0 = icmp ult i8 %not.x, %y
  %not.y = xor i8 %y, -1
  %cmp1 = icmp ult i8 %not.y, %x
  %and = and i1 %cmp0, %cmp1
  ret i1 %and
}
```

**Alive2 Counterexample**:
```
----------------------------------------
define i1 @f(i8 %x, i8 %y) {
#0:
  %not.x = xor i8 %x, 255
  %cmp0 = icmp ult i8 %not.x, %y
  %not.y = xor i8 %y, 255
  %cmp1 = icmp ult i8 %not.y, %x
  %and = and i1 %cmp0, %cmp1
  ret i1 %and
}
=>
define i1 @f(i8 %x, i8 %y) {
#0:
  ret i1 0
}
Transformation doesn't verify!

ERROR: Value mismatch

Example:
i8 %x = #x01 (1)
i8 %y = #xff (255, -1)

Source:
i8 %not.x = #xfe (254, -2)
i1 %cmp0 = #x1 (1)
i8 %not.y = #x00 (0)
i1 %cmp1 = #x1 (1)
i1 %and = #x1 (1)

Target:
Source value: #x1 (1)
Target value: #x0 (0)

Summary:
  0 correct transformations
  1 incorrect transformations
  0 failed-to-prove transformations
  0 Alive2 errors
```

**Opt Output**:
```llvm
; ModuleID = '/tmp/tmpcbolnwm8.ll'
source_filename = "/tmp/tmpcbolnwm8.ll"

define i1 @f(i8 %x, i8 %y) {
  ret i1 false
}
```


**Baseline Revision**: `5cae63bd0d31118a15481fc7e5b063a73492d77d`
**PR Head SHA**: `ad5e0f3cb9f948fc53f5c6136d88cfd23b8804ef`
**Patch SHA256**: `4f58b8dcad32e9e1c87254a911a2f7b6096e6449f5a4ffe542e952620464a137`


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


More information about the llvm-commits mailing list