File tree Expand file tree Collapse file tree 2 files changed +10
-3
lines changed
lib/Transforms/InstCombine
test/Transforms/InstCombine/X86 Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -2280,6 +2280,15 @@ Instruction *InstCombinerImpl::visitSub(BinaryOperator &I) {
2280
2280
if (match (Op0, m_OneUse (m_Add (m_Value (X), m_AllOnes ()))))
2281
2281
return BinaryOperator::CreateAdd (Builder.CreateNot (Op1), X);
2282
2282
2283
+ const APInt *C1, *C2;
2284
+ // if (C1 & C2) == C2 then (X & C1) - (X & C2) -> X & (C1 ^ C2)
2285
+ if (match (Op0, m_And (m_Value (X), m_APInt (C1))) &&
2286
+ match (Op1, m_And (m_Specific (X), m_APInt (C2)))) {
2287
+ if (C2->eq (*C1 & *C2))
2288
+ return BinaryOperator::CreateAnd (
2289
+ X, ConstantInt::get (I.getType (), *C1 ^ *C2));
2290
+ }
2291
+
2283
2292
// Reassociate sub/add sequences to create more add instructions and
2284
2293
// reduce dependency chains:
2285
2294
// ((X - Y) + Z) - Op1 --> (X + Z) - (Y + Op1)
Original file line number Diff line number Diff line change 3
3
4
4
define i8 @and_sub (i8 %a ) {
5
5
; CHECK-LABEL: @and_sub(
6
- ; CHECK-NEXT: [[AND1:%.*]] = and i8 [[A:%.*]], 15
7
- ; CHECK-NEXT: [[AND2:%.*]] = and i8 [[A]], 3
8
- ; CHECK-NEXT: [[RET:%.*]] = sub nsw i8 [[AND1]], [[AND2]]
6
+ ; CHECK-NEXT: [[RET:%.*]] = and i8 [[A:%.*]], 12
9
7
; CHECK-NEXT: ret i8 [[RET]]
10
8
;
11
9
%and1 = and i8 %a , 15
You can’t perform that action at this time.
0 commit comments