forked from OSchip/llvm-project
[ValueTracking] allow undef elements when matching vector abs
llvm-svn: 336111
This commit is contained in:
parent
d414c6c131
commit
284ba0c18f
|
@ -4605,39 +4605,34 @@ static SelectPatternResult matchSelectPattern(CmpInst::Predicate Pred,
|
|||
}
|
||||
}
|
||||
|
||||
const APInt *C1;
|
||||
if (match(CmpRHS, m_APInt(C1))) {
|
||||
// Sign-extending LHS does not change its sign, so TrueVal/FalseVal can
|
||||
// match against either LHS or sext(LHS).
|
||||
auto MaybeSExtLHS = m_CombineOr(m_Specific(CmpLHS),
|
||||
m_SExt(m_Specific(CmpLHS)));
|
||||
if ((match(TrueVal, MaybeSExtLHS) &&
|
||||
match(FalseVal, m_Neg(m_Specific(TrueVal)))) ||
|
||||
(match(FalseVal, MaybeSExtLHS) &&
|
||||
match(TrueVal, m_Neg(m_Specific(FalseVal))))) {
|
||||
// Set LHS and RHS so that RHS is the negated operand of the select
|
||||
if (match(TrueVal, MaybeSExtLHS)) {
|
||||
LHS = TrueVal;
|
||||
RHS = FalseVal;
|
||||
} else {
|
||||
LHS = FalseVal;
|
||||
RHS = TrueVal;
|
||||
}
|
||||
|
||||
// ABS(X) ==> (X >s 0) ? X : -X and (X >s -1) ? X : -X
|
||||
// NABS(X) ==> (X >s 0) ? -X : X and (X >s -1) ? -X : X
|
||||
if (Pred == ICmpInst::ICMP_SGT &&
|
||||
(C1->isNullValue() || C1->isAllOnesValue())) {
|
||||
return {(LHS == TrueVal) ? SPF_ABS : SPF_NABS, SPNB_NA, false};
|
||||
}
|
||||
|
||||
// ABS(X) ==> (X <s 0) ? -X : X and (X <s 1) ? -X : X
|
||||
// NABS(X) ==> (X <s 0) ? X : -X and (X <s 1) ? X : -X
|
||||
if (Pred == ICmpInst::ICMP_SLT &&
|
||||
(C1->isNullValue() || C1->isOneValue())) {
|
||||
return {(LHS == FalseVal) ? SPF_ABS : SPF_NABS, SPNB_NA, false};
|
||||
}
|
||||
// Sign-extending LHS does not change its sign, so TrueVal/FalseVal can
|
||||
// match against either LHS or sext(LHS).
|
||||
auto MaybeSExtLHS = m_CombineOr(m_Specific(CmpLHS),
|
||||
m_SExt(m_Specific(CmpLHS)));
|
||||
if ((match(TrueVal, MaybeSExtLHS) &&
|
||||
match(FalseVal, m_Neg(m_Specific(TrueVal)))) ||
|
||||
(match(FalseVal, MaybeSExtLHS) &&
|
||||
match(TrueVal, m_Neg(m_Specific(FalseVal))))) {
|
||||
// Set LHS and RHS so that RHS is the negated operand of the select
|
||||
if (match(TrueVal, MaybeSExtLHS)) {
|
||||
LHS = TrueVal;
|
||||
RHS = FalseVal;
|
||||
} else {
|
||||
LHS = FalseVal;
|
||||
RHS = TrueVal;
|
||||
}
|
||||
|
||||
// (X >s 0) ? X : -X or (X >s -1) ? X : -X --> ABS(X)
|
||||
// (X >s 0) ? -X : X or (X >s -1) ? -X : X --> NABS(X)
|
||||
if (Pred == ICmpInst::ICMP_SGT &&
|
||||
match(CmpRHS, m_CombineOr(m_ZeroInt(), m_AllOnes())))
|
||||
return {(LHS == TrueVal) ? SPF_ABS : SPF_NABS, SPNB_NA, false};
|
||||
|
||||
// (X <s 0) ? -X : X or (X <s 1) ? -X : X --> ABS(X)
|
||||
// (X <s 0) ? X : -X or (X <s 1) ? X : -X --> NABS(X)
|
||||
if (Pred == ICmpInst::ICMP_SLT &&
|
||||
match(CmpRHS, m_CombineOr(m_ZeroInt(), m_One())))
|
||||
return {(LHS == FalseVal) ? SPF_ABS : SPF_NABS, SPNB_NA, false};
|
||||
}
|
||||
|
||||
if (CmpInst::isIntPredicate(Pred))
|
||||
|
|
|
@ -77,9 +77,9 @@ define <2 x i8> @abs_canonical_2(<2 x i8> %x) {
|
|||
|
||||
define <2 x i8> @abs_canonical_2_vec_undef_elts(<2 x i8> %x) {
|
||||
; CHECK-LABEL: @abs_canonical_2_vec_undef_elts(
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i8> [[X:%.*]], <i8 undef, i8 -1>
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[X:%.*]], zeroinitializer
|
||||
; CHECK-NEXT: [[NEG:%.*]] = sub <2 x i8> zeroinitializer, [[X]]
|
||||
; CHECK-NEXT: [[ABS:%.*]] = select <2 x i1> [[CMP]], <2 x i8> [[X]], <2 x i8> [[NEG]]
|
||||
; CHECK-NEXT: [[ABS:%.*]] = select <2 x i1> [[CMP]], <2 x i8> [[NEG]], <2 x i8> [[X]]
|
||||
; CHECK-NEXT: ret <2 x i8> [[ABS]]
|
||||
;
|
||||
%cmp = icmp sgt <2 x i8> %x, <i8 undef, i8 -1>
|
||||
|
@ -165,9 +165,9 @@ define <2 x i8> @nabs_canonical_2(<2 x i8> %x) {
|
|||
|
||||
define <2 x i8> @nabs_canonical_2_vec_undef_elts(<2 x i8> %x) {
|
||||
; CHECK-LABEL: @nabs_canonical_2_vec_undef_elts(
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i8> [[X:%.*]], <i8 -1, i8 undef>
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[X:%.*]], zeroinitializer
|
||||
; CHECK-NEXT: [[NEG:%.*]] = sub <2 x i8> zeroinitializer, [[X]]
|
||||
; CHECK-NEXT: [[ABS:%.*]] = select <2 x i1> [[CMP]], <2 x i8> [[NEG]], <2 x i8> [[X]]
|
||||
; CHECK-NEXT: [[ABS:%.*]] = select <2 x i1> [[CMP]], <2 x i8> [[X]], <2 x i8> [[NEG]]
|
||||
; CHECK-NEXT: ret <2 x i8> [[ABS]]
|
||||
;
|
||||
%cmp = icmp sgt <2 x i8> %x, <i8 -1, i8 undef>
|
||||
|
|
Loading…
Reference in New Issue