return NV;
Value *X;
- if (match(Op0, m_ZExt(m_Value(X))) && X->getType()->getScalarSizeInBits() == 1)
- // zext(bool) + C -> bool ? C + 1 : C
+ // zext(bool) + C -> bool ? C + 1 : C
+ if (match(Op0, m_ZExt(m_Value(X))) &&
+ X->getType()->getScalarSizeInBits() == 1)
return SelectInst::Create(X, AddOne(Op1C), Op1);
+ // ~X + C --> (C-1) - X
+ if (match(Op0, m_Not(m_Value(X))))
+ return BinaryOperator::CreateSub(SubOne(Op1C), X);
+
const APInt *C;
if (!match(Op1, m_APInt(C)))
return nullptr;
if (haveNoCommonBitsSet(LHS, RHS, DL, &AC, &I, &DT))
return BinaryOperator::CreateOr(LHS, RHS);
- if (Constant *CRHS = dyn_cast<Constant>(RHS)) {
- Value *X;
- if (match(LHS, m_Not(m_Value(X)))) // ~X + C --> (C-1) - X
- return BinaryOperator::CreateSub(SubOne(CRHS), X);
- }
-
// FIXME: We already did a check for ConstantInt RHS above this.
// FIXME: Is this pattern covered by another fold? No regression tests fail on
// removal.
; CHECK-NEXT: ret i32 [[C]]
;
%B = xor i32 %A, -1
- ; == sub int 0, %A
%C = add i32 %B, 1
ret i32 %C
}
; CHECK-NEXT: ret i8 [[C]]
;
%B = xor i8 %A, -1
- ; == sub ubyte 16, %A
%C = add i8 %B, 17
ret i8 %C
}
+define <2 x i64> @test18vec(<2 x i64> %A) {
+; CHECK-LABEL: @test18vec(
+; CHECK-NEXT: [[ADD:%.*]] = sub <2 x i64> <i64 1, i64 2>, %A
+; CHECK-NEXT: ret <2 x i64> [[ADD]]
+;
+ %xor = xor <2 x i64> %A, <i64 -1, i64 -1>
+ %add = add <2 x i64> %xor, <i64 2, i64 3>
+ ret <2 x i64> %add
+}
+
define i32 @test19(i1 %C) {
; CHECK-LABEL: @test19(
; CHECK-NEXT: [[V:%.*]] = select i1 %C, i32 1123, i32 133
; CHECK-NEXT: ret <2 x i64> %add
}
-define <2 x i64> @test8(<2 x i64> %A) {
- %xor = xor <2 x i64> %A, <i64 -1, i64 -1>
- %add = add <2 x i64> %xor, <i64 2, i64 3>
- ret <2 x i64> %add
-; CHECK-LABEL: @test8(
-; CHECK-NEXT: %add = sub <2 x i64> <i64 1, i64 2>, %A
-; CHECK-NEXT: ret <2 x i64> %add
-}
-
define i16 @test9(i16 %a) {
%b = mul i16 %a, 2
%c = mul i16 %a, 32767