llvm / llvm/llvm-project

[InstCombine] Discuss generalizing icmp eq/ne X, 0 to trunc X to i1 using KnownBits

Open
#183,584 5 comments 0 reactions 0 assignees View on GitHub
llvm:instcombine missed-optimization
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

1. Previous State
InstCombine currently folds icmp ne (and X, 1), 0 to trunc X to i1 using strict syntactic pattern matching. It does not handle cases where the upper bits are known to be zero through other operations without an explicit and X, 1.

2. Purpose of Improvement
Generalize the conversion from icmp eq/ne X, 0 to trunc X to i1 (or not trunc) by utilizing KnownBits.
If Known.countMinLeadingZeros() >= BitWidth - 1 for X, all bits except the LSB are guaranteed to be zero. Therefore, comparing X with 0 is mathematically equivalent to truncating X to i1.

Is folding icmp ne X, 0 to trunc X to i1 using KnownBits desirable in InstCombine?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.