[InstCombine] use m_APInt to allow icmp eq (or X, C1), C2 folds for splat constant vectors

llvm-svn: 277752
This commit is contained in:
Sanjay Patel 2016-08-04 19:12:12 +00:00
parent 06db18fbf8
commit b3de75d3a0
2 changed files with 9 additions and 12 deletions

View File

@ -2276,20 +2276,18 @@ Instruction *InstCombiner::foldICmpEqualityWithConstant(ICmpInst &ICI) {
}
}
break;
case Instruction::Or:
// FIXME: Vectors are excluded by ConstantInt.
if (ConstantInt *BOC = dyn_cast<ConstantInt>(BOp1)) {
case Instruction::Or: {
const APInt *BOC;
if (match(BOp1, m_APInt(BOC)) && BO->hasOneUse() && RHS->isAllOnesValue()) {
// Comparing if all bits outside of a constant mask are set?
// Replace (X | C) == -1 with (X & ~C) == ~C.
// This removes the -1 constant.
if (BO->hasOneUse() && RHS->isAllOnesValue()) {
Constant *NotBOC = ConstantExpr::getNot(BOC);
Value *And = Builder->CreateAnd(BOp0, NotBOC);
return new ICmpInst(ICI.getPredicate(), And, NotBOC);
}
Constant *NotBOC = ConstantExpr::getNot(cast<Constant>(BOp1));
Value *And = Builder->CreateAnd(BOp0, NotBOC);
return new ICmpInst(ICI.getPredicate(), And, NotBOC);
}
break;
}
case Instruction::And:
// FIXME: Vectors are excluded by ConstantInt.
if (ConstantInt *BOC = dyn_cast<ConstantInt>(BOp1)) {

View File

@ -2035,11 +2035,10 @@ define i1 @cmp_inverse_mask_bits_set_eq(i32 %x) {
ret i1 %cmp
}
; FIXME: Vectors should fold the same way.
define <2 x i1> @cmp_inverse_mask_bits_set_eq_vec(<2 x i32> %x) {
; CHECK-LABEL: @cmp_inverse_mask_bits_set_eq_vec(
; CHECK-NEXT: [[OR:%.*]] = or <2 x i32> %x, <i32 42, i32 42>
; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[OR]], <i32 -1, i32 -1>
; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i32> %x, <i32 -43, i32 -43>
; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[TMP1]], <i32 -43, i32 -43>
; CHECK-NEXT: ret <2 x i1> [[CMP]]
;
%or = or <2 x i32> %x, <i32 42, i32 42>