Skip to content

Commit 6ef22da

Browse files
committedAug 23, 2016
[InstCombine] remove icmp shr folds that are already handled by InstSimplify
AFAICT, these already worked in all cases for scalar types, and I enhanced the code to work for vector types in: https://reviews.llvm.org/rL279543 llvm-svn: 279568
1 parent bdf67c9 commit 6ef22da

File tree

1 file changed

+3
-17
lines changed

1 file changed

+3
-17
lines changed
 

‎llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

+3-17
Original file line numberDiff line numberDiff line change
@@ -1391,24 +1391,10 @@ Instruction *InstCombiner::foldICmpShrConstConst(ICmpInst &ICI,
13911391
return Res;
13921392
}
13931393

1394-
// If we are comparing against bits always shifted out, the
1395-
// comparison cannot succeed.
1396-
APInt Comp = CmpRHSV << ShAmtVal;
1397-
ConstantInt *ShiftedCmpRHS = Builder->getInt(Comp);
1398-
if (Shr->getOpcode() == Instruction::LShr)
1399-
Comp = Comp.lshr(ShAmtVal);
1400-
else
1401-
Comp = Comp.ashr(ShAmtVal);
1402-
1403-
if (Comp != CmpRHSV) { // Comparing against a bit that we know is zero.
1404-
bool IsICMP_NE = ICI.getPredicate() == ICmpInst::ICMP_NE;
1405-
Constant *Cst = Builder->getInt1(IsICMP_NE);
1406-
return replaceInstUsesWith(ICI, Cst);
1407-
}
1408-
1409-
// Otherwise, check to see if the bits shifted out are known to be zero.
1410-
// If so, we can compare against the unshifted value:
1394+
// Check if the bits shifted out are known to be zero. If so, we can compare
1395+
// against the unshifted value:
14111396
// (X & 4) >> 1 == 2 --> (X & 4) == 4.
1397+
ConstantInt *ShiftedCmpRHS = Builder->getInt(CmpRHSV << ShAmtVal);
14121398
if (Shr->hasOneUse() && Shr->isExact())
14131399
return new ICmpInst(ICI.getPredicate(), Shr->getOperand(0), ShiftedCmpRHS);
14141400

0 commit comments

Comments
 (0)
Please sign in to comment.