Skip to content

Commit e6375ca

Browse files
goldsteinnnikic
authored andcommitted
[InstCombine] Fix potentially buggy code in ((%x & C) == 0) --> %x u< (-C) transform
While demanded bits constant shrinking appears to prevent this in practice right now, it is principally possible for C2 to have set bits that are known not-needed (zeroable). See: D140858 `+` will overflow here, `|` will get the right logic. Differential Revision: https://reviews.llvm.org/D141089
1 parent 05d722a commit e6375ca

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1722,7 +1722,7 @@ Instruction *InstCombinerImpl::foldICmpAndConstConst(ICmpInst &Cmp,
17221722
APInt NewC2 = *C2;
17231723
KnownBits Know = computeKnownBits(And->getOperand(0), 0, And);
17241724
// Set high zeros of C2 to allow matching negated power-of-2.
1725-
NewC2 = *C2 + APInt::getHighBitsSet(C2->getBitWidth(),
1725+
NewC2 = *C2 | APInt::getHighBitsSet(C2->getBitWidth(),
17261726
Know.countMinLeadingZeros());
17271727

17281728
// Restrict this fold only for single-use 'and' (PR10267).

0 commit comments

Comments
 (0)