[PATCH] InstCombineCompare with constant return false if we know it is never going to be equal

Nick Lewycky nicholas at mxc.ca
Wed Jun 18 00:09:17 PDT 2014


suyog wrote:
> Gentle Ping !!
>
> http://reviews.llvm.org/D3868

	​ // If a bit is known to be zero for A and known to be one for B,
	​ // then A and B cannot be equal.
	​ if (ConstantInt *CI = dyn_cast<ConstantInt>(RHS)) {
	​ uint32_t BitWidth = CI->getBitWidth();
	​ APInt LHSKnownZero(BitWidth, 0);
	​ APInt LHSKnownOne(BitWidth, 0);
	​ computeKnownBits(LHS, LHSKnownZero, LHSKnownOne);
	​ APInt RHSKnownZero(BitWidth, 0);
	​ APInt RHSKnownOne(BitWidth, 0);
	​ computeKnownBits(RHS, RHSKnownZero, RHSKnownOne);
	​ switch (Pred) {
	​ default:
	​ break;

computeKnownBits is really expensive. Please check 
ICmpInst::isEquality(Pred) before the rest of this logic.

Optionally: for the same reason, please sink it lower down in the list 
of checks. At least after the "See if we are doing a comparison with a 
constant integer" code and probably before "Special logic for binary 
operators" code?

Please commit the change to test/Transforms/InstCombine/align-2d-gep.ll. 
You can do that independently of the rest of it if you like, the test is 
clearly wrong.

The compare.ll test looks good.

Please commit with isEquality check. Thanks for the patch!

Nick



More information about the llvm-commits mailing list