[llvm] 142a75a - Revert "[InstCombine] reduce indentation; NFC"
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 6 11:20:10 PST 2019
Author: Sanjay Patel
Date: 2019-12-06T14:19:02-05:00
New Revision: 142a75a9b16632d5bad60ae50b9171bfddbe422a
URL: https://github.com/llvm/llvm-project/commit/142a75a9b16632d5bad60ae50b9171bfddbe422a
DIFF: https://github.com/llvm/llvm-project/commit/142a75a9b16632d5bad60ae50b9171bfddbe422a.diff
LOG: Revert "[InstCombine] reduce indentation; NFC"
This reverts commit 8bf8ef7116bd0daec570b35480ca969b74e66c6e.
At least 1 of these supposedly NFC commits wasn't - sanitizer bot is angry.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
index a981b3d59b99..1ba017d479e9 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -926,31 +926,34 @@ Instruction *InstCombiner::transformZExtICmp(ICmpInst *Cmp, ZExtInst &Zext,
// icmp ne A, B is equal to xor A, B when A and B only really have one bit.
// It is also profitable to transform icmp eq into not(xor(A, B)) because that
// may lead to additional simplifications.
- if (!isa<IntegerType>(ZType) || !Cmp->isEquality() || ZType != CmpOpType)
- return nullptr;
-
- KnownBits KnownOp0 = computeKnownBits(Op0, 0, &Zext);
- KnownBits KnownOp1 = computeKnownBits(Op1, 0, &Zext);
- if (KnownOp0.Zero == KnownOp1.Zero && KnownOp0.One == KnownOp1.One) {
- APInt KnownBits = KnownOp0.Zero | KnownOp0.One;
- APInt UnknownBit = ~KnownBits;
- if (UnknownBit.countPopulation() == 1) {
- if (!DoTransform) return Cmp;
-
- Value *Result = Builder.CreateXor(Op0, Op1);
-
- // Mask off any bits that are set and won't be shifted away.
- if (KnownOp0.One.uge(UnknownBit))
- Result = Builder.CreateAnd(Result, ConstantInt::get(ZType, UnknownBit));
-
- // Shift the bit we're testing down to the lsb.
- Result = Builder.CreateLShr(
- Result, ConstantInt::get(ZType, UnknownBit.countTrailingZeros()));
-
- if (Pred == ICmpInst::ICMP_EQ)
- Result = Builder.CreateXor(Result, ConstantInt::get(ZType, 1));
- Result->takeName(Cmp);
- return replaceInstUsesWith(Zext, Result);
+ if (Cmp->isEquality() && ZType == CmpOpType) {
+ if (IntegerType *ITy = dyn_cast<IntegerType>(ZType)) {
+ KnownBits KnownOp0 = computeKnownBits(Op0, 0, &Zext);
+ KnownBits KnownOp1 = computeKnownBits(Op1, 0, &Zext);
+
+ if (KnownOp0.Zero == KnownOp1.Zero && KnownOp0.One == KnownOp1.One) {
+ APInt KnownBits = KnownOp0.Zero | KnownOp0.One;
+ APInt UnknownBit = ~KnownBits;
+ if (UnknownBit.countPopulation() == 1) {
+ if (!DoTransform) return Cmp;
+
+ Value *Result = Builder.CreateXor(Op0, Op1);
+
+ // Mask off any bits that are set and won't be shifted away.
+ if (KnownOp0.One.uge(UnknownBit))
+ Result = Builder.CreateAnd(Result,
+ ConstantInt::get(ITy, UnknownBit));
+
+ // Shift the bit we're testing down to the lsb.
+ Result = Builder.CreateLShr(
+ Result, ConstantInt::get(ITy, UnknownBit.countTrailingZeros()));
+
+ if (Pred == ICmpInst::ICMP_EQ)
+ Result = Builder.CreateXor(Result, ConstantInt::get(ITy, 1));
+ Result->takeName(Cmp);
+ return replaceInstUsesWith(Zext, Result);
+ }
+ }
}
}
More information about the llvm-commits
mailing list