Skip to content

Conversation

@Camsyn
Copy link
Contributor

@Camsyn Camsyn commented Nov 1, 2025

If we know X ∈ R1, the range check x ∈ R2 can be relaxed into X ∈ R1 ∩ R2 or X ∈ R2 ∪ Inverse(R1).

The relaxed one may be more efficient if we can represent it with one icmp eq, which could motivate more optimization like SimplifyCFG.

This optimization is a more generic version of InstCombine's foldICmpWithDominatingICmp, which only works on those CmpBB with ONE DomBB, i.e., cannot handle the following case:

if (x == 0) return false;
if (x == 1) return false;
// Could be simplified as x == 2;
return x <u 3);

Alive2 Proof : https://alive2.llvm.org/ce/z/HMgkuu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant