From: Sanjay Patel Date: Mon, 9 Jan 2023 21:27:44 +0000 (-0500) Subject: [InstCombine] simplify code and fix formatting; NFC X-Git-Tag: upstream/17.0.6~21655 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a4f3b236719529bdc987d4f347e8711c27587ce4;p=platform%2Fupstream%2Fllvm.git [InstCombine] simplify code and fix formatting; NFC --- diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp index 6c59185..7b17a8b 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -993,7 +993,8 @@ Instruction *InstCombinerImpl::visitTrunc(TruncInst &Trunc) { return nullptr; } -Instruction *InstCombinerImpl::transformZExtICmp(ICmpInst *Cmp, ZExtInst &Zext) { +Instruction *InstCombinerImpl::transformZExtICmp(ICmpInst *Cmp, + ZExtInst &Zext) { // If we are just checking for a icmp eq of a single bit and zext'ing it // to an integer, then shift the bit to the appropriate place and then // cast to integer to avoid the comparison. @@ -1031,8 +1032,8 @@ Instruction *InstCombinerImpl::transformZExtICmp(ICmpInst *Cmp, ZExtInst &Zext) // canonicalized to this form. APInt KnownZeroMask(~Known.Zero); if (KnownZeroMask.isPowerOf2() && - (Zext.getType()->getScalarSizeInBits() != KnownZeroMask.logBase2() + 1)) { - bool isNE = Cmp->getPredicate() == ICmpInst::ICMP_NE; + (Zext.getType()->getScalarSizeInBits() != + KnownZeroMask.logBase2() + 1)) { uint32_t ShAmt = KnownZeroMask.logBase2(); Value *In = Cmp->getOperand(0); if (ShAmt) { @@ -1042,10 +1043,9 @@ Instruction *InstCombinerImpl::transformZExtICmp(ICmpInst *Cmp, ZExtInst &Zext) In->getName() + ".lobit"); } - if (!isNE) { // Toggle the low bit. - Constant *One = ConstantInt::get(In->getType(), 1); - In = Builder.CreateXor(In, One); - } + // Toggle the low bit for "X == 0". + if (Cmp->getPredicate() == ICmpInst::ICMP_EQ) + In = Builder.CreateXor(In, ConstantInt::get(In->getType(), 1)); if (Zext.getType() == In->getType()) return replaceInstUsesWith(Zext, In);