Skip to content

Power of two assumption optimized away #128152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
nikic opened this issue Feb 21, 2025 · 0 comments
Open

Power of two assumption optimized away #128152

nikic opened this issue Feb 21, 2025 · 0 comments

Comments

@nikic
Copy link
Contributor

nikic commented Feb 21, 2025

https://llvm.godbolt.org/z/z3E6641E1

; RUN: opt -S -passes=instsimplify < %s
define i1 @foo(i32 %x) {
  %ctpop = call i32 @llvm.ctpop.i32(i32 %x)
  %cond = icmp eq i32 %ctpop, 1
  %ext = zext i1 %cond to i8
  call void @llvm.assume(i1 %cond)
  %res = icmp eq i32 %x, 0
  ret i1 %res
}

Results in:

define i1 @foo(i32 %x) {
  %res = icmp eq i32 %x, 0
  ret i1 %res
}

Note that the dead %ext is relevant.

Without looking into it, I assume that the problem is that we're using

// ctpop(X) -> 1 iff X is non-zero power of 2.
if (isKnownToBeAPowerOfTwo(Op0, Q.DL, /*OrZero*/ false, 0, Q.AC, Q.CxtI,
Q.DT))
return ConstantInt::get(Op0->getType(), 1);
with an ephemeral value, and the extra use in %ext is what makes use currently think it is non-ephemeral.

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

No branches or pull requests

2 participants