Skip to content

Commit a4f3b23

Browse files
committed
[InstCombine] simplify code and fix formatting; NFC
1 parent 7306541 commit a4f3b23

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,8 @@ Instruction *InstCombinerImpl::visitTrunc(TruncInst &Trunc) {
993993
return nullptr;
994994
}
995995

996-
Instruction *InstCombinerImpl::transformZExtICmp(ICmpInst *Cmp, ZExtInst &Zext) {
996+
Instruction *InstCombinerImpl::transformZExtICmp(ICmpInst *Cmp,
997+
ZExtInst &Zext) {
997998
// If we are just checking for a icmp eq of a single bit and zext'ing it
998999
// to an integer, then shift the bit to the appropriate place and then
9991000
// cast to integer to avoid the comparison.
@@ -1031,8 +1032,8 @@ Instruction *InstCombinerImpl::transformZExtICmp(ICmpInst *Cmp, ZExtInst &Zext)
10311032
// canonicalized to this form.
10321033
APInt KnownZeroMask(~Known.Zero);
10331034
if (KnownZeroMask.isPowerOf2() &&
1034-
(Zext.getType()->getScalarSizeInBits() != KnownZeroMask.logBase2() + 1)) {
1035-
bool isNE = Cmp->getPredicate() == ICmpInst::ICMP_NE;
1035+
(Zext.getType()->getScalarSizeInBits() !=
1036+
KnownZeroMask.logBase2() + 1)) {
10361037
uint32_t ShAmt = KnownZeroMask.logBase2();
10371038
Value *In = Cmp->getOperand(0);
10381039
if (ShAmt) {
@@ -1042,10 +1043,9 @@ Instruction *InstCombinerImpl::transformZExtICmp(ICmpInst *Cmp, ZExtInst &Zext)
10421043
In->getName() + ".lobit");
10431044
}
10441045

1045-
if (!isNE) { // Toggle the low bit.
1046-
Constant *One = ConstantInt::get(In->getType(), 1);
1047-
In = Builder.CreateXor(In, One);
1048-
}
1046+
// Toggle the low bit for "X == 0".
1047+
if (Cmp->getPredicate() == ICmpInst::ICMP_EQ)
1048+
In = Builder.CreateXor(In, ConstantInt::get(In->getType(), 1));
10491049

10501050
if (Zext.getType() == In->getType())
10511051
return replaceInstUsesWith(Zext, In);

0 commit comments

Comments
 (0)