1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-25 04:02:41 +01:00

[InstSimplify] allow vector splats for icmp-of-neg folds

This commit is contained in:
Sanjay Patel 2020-10-20 09:04:19 -04:00
parent 37b52be0fc
commit d0cd8409eb
2 changed files with 16 additions and 37 deletions

View File

@ -2936,22 +2936,19 @@ static Value *simplifyICmpWithBinOp(CmpInst::Predicate Pred, Value *LHS,
// 0 - (zext X) pred C
if (!CmpInst::isUnsigned(Pred) && match(LHS, m_Neg(m_ZExt(m_Value())))) {
if (ConstantInt *RHSC = dyn_cast<ConstantInt>(RHS)) {
if (RHSC->getValue().isStrictlyPositive()) {
if (Pred == ICmpInst::ICMP_SLT)
return ConstantInt::getTrue(RHSC->getContext());
if (Pred == ICmpInst::ICMP_SGE)
return ConstantInt::getFalse(RHSC->getContext());
if (Pred == ICmpInst::ICMP_EQ)
return ConstantInt::getFalse(RHSC->getContext());
if (Pred == ICmpInst::ICMP_NE)
return ConstantInt::getTrue(RHSC->getContext());
const APInt *C;
if (match(RHS, m_APInt(C))) {
if (C->isStrictlyPositive()) {
if (Pred == ICmpInst::ICMP_SLT || Pred == ICmpInst::ICMP_NE)
return ConstantInt::getTrue(GetCompareTy(RHS));
if (Pred == ICmpInst::ICMP_SGE || Pred == ICmpInst::ICMP_EQ)
return ConstantInt::getFalse(GetCompareTy(RHS));
}
if (RHSC->getValue().isNonNegative()) {
if (C->isNonNegative()) {
if (Pred == ICmpInst::ICMP_SLE)
return ConstantInt::getTrue(RHSC->getContext());
return ConstantInt::getTrue(GetCompareTy(RHS));
if (Pred == ICmpInst::ICMP_SGT)
return ConstantInt::getFalse(RHSC->getContext());
return ConstantInt::getFalse(GetCompareTy(RHS));
}
}
}

View File

@ -1129,10 +1129,7 @@ define i1 @compare_always_true_slt(i16 %a) {
define <2 x i1> @compare_always_true_slt_splat(<2 x i16> %a) {
; CHECK-LABEL: @compare_always_true_slt_splat(
; CHECK-NEXT: [[T1:%.*]] = zext <2 x i16> [[A:%.*]] to <2 x i32>
; CHECK-NEXT: [[T2:%.*]] = sub <2 x i32> zeroinitializer, [[T1]]
; CHECK-NEXT: [[T3:%.*]] = icmp slt <2 x i32> [[T2]], <i32 1, i32 1>
; CHECK-NEXT: ret <2 x i1> [[T3]]
; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
;
%t1 = zext <2 x i16> %a to <2 x i32>
%t2 = sub <2 x i32> zeroinitializer, %t1
@ -1152,10 +1149,7 @@ define i1 @compare_always_true_sle(i16 %a) {
define <2 x i1> @compare_always_true_sle_splat(<2 x i16> %a) {
; CHECK-LABEL: @compare_always_true_sle_splat(
; CHECK-NEXT: [[T1:%.*]] = zext <2 x i16> [[A:%.*]] to <2 x i32>
; CHECK-NEXT: [[T2:%.*]] = sub <2 x i32> zeroinitializer, [[T1]]
; CHECK-NEXT: [[T3:%.*]] = icmp sle <2 x i32> [[T2]], zeroinitializer
; CHECK-NEXT: ret <2 x i1> [[T3]]
; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
;
%t1 = zext <2 x i16> %a to <2 x i32>
%t2 = sub <2 x i32> zeroinitializer, %t1
@ -1175,10 +1169,7 @@ define i1 @compare_always_false_sgt(i16 %a) {
define <2 x i1> @compare_always_false_sgt_splat(<2 x i16> %a) {
; CHECK-LABEL: @compare_always_false_sgt_splat(
; CHECK-NEXT: [[T1:%.*]] = zext <2 x i16> [[A:%.*]] to <2 x i32>
; CHECK-NEXT: [[T2:%.*]] = sub <2 x i32> zeroinitializer, [[T1]]
; CHECK-NEXT: [[T3:%.*]] = icmp sgt <2 x i32> [[T2]], zeroinitializer
; CHECK-NEXT: ret <2 x i1> [[T3]]
; CHECK-NEXT: ret <2 x i1> zeroinitializer
;
%t1 = zext <2 x i16> %a to <2 x i32>
%t2 = sub <2 x i32> zeroinitializer, %t1
@ -1198,10 +1189,7 @@ define i1 @compare_always_false_sge(i16 %a) {
define <2 x i1> @compare_always_false_sge_splat(<2 x i16> %a) {
; CHECK-LABEL: @compare_always_false_sge_splat(
; CHECK-NEXT: [[T1:%.*]] = zext <2 x i16> [[A:%.*]] to <2 x i32>
; CHECK-NEXT: [[T2:%.*]] = sub <2 x i32> zeroinitializer, [[T1]]
; CHECK-NEXT: [[T3:%.*]] = icmp sge <2 x i32> [[T2]], <i32 1, i32 1>
; CHECK-NEXT: ret <2 x i1> [[T3]]
; CHECK-NEXT: ret <2 x i1> zeroinitializer
;
%t1 = zext <2 x i16> %a to <2 x i32>
%t2 = sub <2 x i32> zeroinitializer, %t1
@ -1221,10 +1209,7 @@ define i1 @compare_always_false_eq(i16 %a) {
define <2 x i1> @compare_always_false_eq_splat(<2 x i16> %a) {
; CHECK-LABEL: @compare_always_false_eq_splat(
; CHECK-NEXT: [[T1:%.*]] = zext <2 x i16> [[A:%.*]] to <2 x i32>
; CHECK-NEXT: [[T2:%.*]] = sub <2 x i32> zeroinitializer, [[T1]]
; CHECK-NEXT: [[T3:%.*]] = icmp eq <2 x i32> [[T2]], <i32 1, i32 1>
; CHECK-NEXT: ret <2 x i1> [[T3]]
; CHECK-NEXT: ret <2 x i1> zeroinitializer
;
%t1 = zext <2 x i16> %a to <2 x i32>
%t2 = sub <2 x i32> zeroinitializer, %t1
@ -1244,10 +1229,7 @@ define i1 @compare_always_true_ne(i16 %a) {
define <2 x i1> @compare_always_true_ne_splat(<2 x i16> %a) {
; CHECK-LABEL: @compare_always_true_ne_splat(
; CHECK-NEXT: [[T1:%.*]] = zext <2 x i16> [[A:%.*]] to <2 x i32>
; CHECK-NEXT: [[T2:%.*]] = sub <2 x i32> zeroinitializer, [[T1]]
; CHECK-NEXT: [[T3:%.*]] = icmp ne <2 x i32> [[T2]], <i32 1, i32 1>
; CHECK-NEXT: ret <2 x i1> [[T3]]
; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
;
%t1 = zext <2 x i16> %a to <2 x i32>
%t2 = sub <2 x i32> zeroinitializer, %t1