From a4f3b236719529bdc987d4f347e8711c27587ce4 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Mon, 9 Jan 2023 16:27:44 -0500 Subject: [PATCH] [InstCombine] simplify code and fix formatting; NFC --- llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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); -- 2.7.4