Skip to content

Commit 6be6c3a

Browse files
committed
[InstCombine] Use disjoint flag for alternate binops
Check the or disjoint flag instead of the weaker MaskedValueIsZero query.
1 parent 1623866 commit 6be6c3a

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,9 +2072,8 @@ static BinopElts getAlternateBinop(BinaryOperator *BO, const DataLayout &DL) {
20722072
break;
20732073
}
20742074
case Instruction::Or: {
2075-
// or X, C --> add X, C (when X and C have no common bits set)
2076-
const APInt *C;
2077-
if (match(BO1, m_APInt(C)) && MaskedValueIsZero(BO0, *C, DL))
2075+
// or disjoin X, C --> add X, C
2076+
if (cast<PossiblyDisjointInst>(BO)->isDisjoint())
20782077
return {Instruction::Add, BO0, BO1};
20792078
break;
20802079
}

llvm/test/Transforms/InstCombine/shuffle_select.ll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,6 +1466,17 @@ define <4 x i32> @add_or(<4 x i32> %v) {
14661466
ret <4 x i32> %t3
14671467
}
14681468

1469+
define <4 x i32> @add_or_disjoint(<4 x i32> %v) {
1470+
; CHECK-LABEL: @add_or_disjoint(
1471+
; CHECK-NEXT: [[T3:%.*]] = add <4 x i32> [[V:%.*]], <i32 31, i32 31, i32 65536, i32 65537>
1472+
; CHECK-NEXT: ret <4 x i32> [[T3]]
1473+
;
1474+
%t1 = add <4 x i32> %v, <i32 65534, i32 65535, i32 65536, i32 65537>
1475+
%t2 = or disjoint <4 x i32> %v, <i32 31, i32 31, i32 31, i32 31>
1476+
%t3 = shufflevector <4 x i32> %t1, <4 x i32> %t2, <4 x i32> <i32 4, i32 5, i32 2, i32 3>
1477+
ret <4 x i32> %t3
1478+
}
1479+
14691480
; Try with 'or' as operand 0 of the shuffle.
14701481

14711482
define <4 x i8> @or_add(<4 x i8> %v) {

0 commit comments

Comments
 (0)