[llvm] [ValueTracking] Compute known bits of or/and/xor recurrences from start and step (PR #222334)
Ömer Sinan Ağacan via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 23 07:40:32 PDT 2026
================
@@ -1919,8 +1920,17 @@ static void computeKnownBitsFromOperator(const Operator *I,
RecQ.CxtI = LatchTerm;
computeKnownBits(Step, DemandedElts, KnownStep, RecQ, Depth + 1);
- Known.Zero.setLowBits(std::min(KnownStart.countMinTrailingZeros(),
- KnownStep.countMinTrailingZeros()));
+ if (Opcode == Instruction::Or || Opcode == Instruction::Xor) {
+ Known.Zero |= KnownStart.Zero & KnownStep.Zero;
+ if (Opcode == Instruction::Or)
+ Known.One |= KnownStart.One;
+ } else if (Opcode == Instruction::And) {
+ Known.Zero |= KnownStart.Zero;
+ Known.One |= KnownStart.One & KnownStep.One;
+ } else {
+ Known.Zero.setLowBits(std::min(KnownStart.countMinTrailingZeros(),
+ KnownStep.countMinTrailingZeros()));
+ }
----------------
osa1 wrote:
I think the code becomes easier to read and understand if you move `and`, `or`, `xor` cases to their own `case` blocks instead of having them with `add`, `sub` etc. and then special case here. I wasn't aware of this PR and implemented the `and` and `or` handling that way in https://github.com/llvm/llvm-project/pull/225775 if you want to compare.
https://github.com/llvm/llvm-project/pull/222334
More information about the llvm-commits
mailing list