Skip to content

Commit

Permalink
Merge commit 'e95ff86a4064' from apple/master into swift/master-next
Browse files Browse the repository at this point in the history
  • Loading branch information
git apple-llvm automerger committed Oct 29, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 4718b66 + e95ff86 commit e6608f7
Showing 8 changed files with 21 additions and 9 deletions.
12 changes: 12 additions & 0 deletions llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
Original file line number Diff line number Diff line change
@@ -5167,6 +5167,7 @@ llvm::getFlippedStrictnessPredicateAndConstant(CmpInst::Predicate Pred,
return WillIncrement ? !C->isMaxValue(IsSigned) : !C->isMinValue(IsSigned);
};

Constant *SafeReplacementConstant = nullptr;
if (auto *CI = dyn_cast<ConstantInt>(C)) {
// Bail out if the constant can't be safely incremented/decremented.
if (!ConstantIsOk(CI))
@@ -5186,12 +5187,23 @@ llvm::getFlippedStrictnessPredicateAndConstant(CmpInst::Predicate Pred,
auto *CI = dyn_cast<ConstantInt>(Elt);
if (!CI || !ConstantIsOk(CI))
return llvm::None;

if (!SafeReplacementConstant)
SafeReplacementConstant = CI;
}
} else {
// ConstantExpr?
return llvm::None;
}

// It may not be safe to change a compare predicate in the presence of
// undefined elements, so replace those elements with the first safe constant
// that we found.
if (C->containsUndefElement()) {
assert(SafeReplacementConstant && "Replacement constant not set");
C = Constant::replaceUndefsWith(C, SafeReplacementConstant);
}

CmpInst::Predicate NewPred = CmpInst::getFlippedStrictnessPredicate(Pred);

// Increment or decrement the constant.
Original file line number Diff line number Diff line change
@@ -82,7 +82,7 @@ define <2 x i1> @p2_vec_nonsplat_edgecase1(<2 x i8> %x) {

define <3 x i1> @p3_vec_splat_undef(<3 x i8> %x) {
; CHECK-LABEL: @p3_vec_splat_undef(
; CHECK-NEXT: [[TMP1:%.*]] = icmp ult <3 x i8> [[X:%.*]], <i8 4, i8 undef, i8 4>
; CHECK-NEXT: [[TMP1:%.*]] = icmp ult <3 x i8> [[X:%.*]], <i8 4, i8 4, i8 4>
; CHECK-NEXT: ret <3 x i1> [[TMP1]]
;
%tmp0 = and <3 x i8> %x, <i8 3, i8 undef, i8 3>
Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@ define <2 x i1> @p2_vec_nonsplat_edgecase(<2 x i8> %x) {

define <3 x i1> @p3_vec_splat_undef(<3 x i8> %x) {
; CHECK-LABEL: @p3_vec_splat_undef(
; CHECK-NEXT: [[TMP1:%.*]] = icmp slt <3 x i8> [[X:%.*]], <i8 4, i8 undef, i8 4>
; CHECK-NEXT: [[TMP1:%.*]] = icmp slt <3 x i8> [[X:%.*]], <i8 4, i8 4, i8 4>
; CHECK-NEXT: ret <3 x i1> [[TMP1]]
;
%tmp0 = and <3 x i8> %x, <i8 3, i8 undef, i8 3>
Original file line number Diff line number Diff line change
@@ -76,7 +76,7 @@ define <2 x i1> @p2_vec_nonsplat_edgecase() {
define <3 x i1> @p3_vec_splat_undef() {
; CHECK-LABEL: @p3_vec_splat_undef(
; CHECK-NEXT: [[X:%.*]] = call <3 x i8> @gen3x8()
; CHECK-NEXT: [[TMP1:%.*]] = icmp slt <3 x i8> [[X]], <i8 4, i8 undef, i8 4>
; CHECK-NEXT: [[TMP1:%.*]] = icmp slt <3 x i8> [[X]], <i8 4, i8 4, i8 4>
; CHECK-NEXT: ret <3 x i1> [[TMP1]]
;
%x = call <3 x i8> @gen3x8()
Original file line number Diff line number Diff line change
@@ -82,7 +82,7 @@ define <2 x i1> @p2_vec_nonsplat_edgecase1(<2 x i8> %x) {

define <3 x i1> @p3_vec_splat_undef(<3 x i8> %x) {
; CHECK-LABEL: @p3_vec_splat_undef(
; CHECK-NEXT: [[TMP1:%.*]] = icmp ult <3 x i8> [[X:%.*]], <i8 4, i8 undef, i8 4>
; CHECK-NEXT: [[TMP1:%.*]] = icmp ult <3 x i8> [[X:%.*]], <i8 4, i8 4, i8 4>
; CHECK-NEXT: ret <3 x i1> [[TMP1]]
;
%tmp0 = and <3 x i8> %x, <i8 3, i8 undef, i8 3>
Original file line number Diff line number Diff line change
@@ -99,7 +99,7 @@ define <2 x i1> @p2_vec_nonsplat_edgecase1() {
define <3 x i1> @p3_vec_splat_undef() {
; CHECK-LABEL: @p3_vec_splat_undef(
; CHECK-NEXT: [[X:%.*]] = call <3 x i8> @gen3x8()
; CHECK-NEXT: [[TMP1:%.*]] = icmp ult <3 x i8> [[X]], <i8 4, i8 undef, i8 4>
; CHECK-NEXT: [[TMP1:%.*]] = icmp ult <3 x i8> [[X]], <i8 4, i8 4, i8 4>
; CHECK-NEXT: ret <3 x i1> [[TMP1]]
;
%x = call <3 x i8> @gen3x8()
4 changes: 2 additions & 2 deletions llvm/test/Transforms/InstCombine/icmp-vec.ll
Original file line number Diff line number Diff line change
@@ -181,7 +181,7 @@ define <2 x i1> @PR27756_1(<2 x i8> %a) {

define <3 x i1> @PR27756_2(<3 x i8> %a) {
; CHECK-LABEL: @PR27756_2(
; CHECK-NEXT: [[CMP:%.*]] = icmp slt <3 x i8> [[A:%.*]], <i8 43, i8 undef, i8 1>
; CHECK-NEXT: [[CMP:%.*]] = icmp slt <3 x i8> [[A:%.*]], <i8 43, i8 43, i8 1>
; CHECK-NEXT: ret <3 x i1> [[CMP]]
;
%cmp = icmp sle <3 x i8> %a, <i8 42, i8 undef, i8 0>
@@ -190,7 +190,7 @@ define <3 x i1> @PR27756_2(<3 x i8> %a) {

define <3 x i1> @PR27756_3(<3 x i8> %a) {
; CHECK-LABEL: @PR27756_3(
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <3 x i8> [[A:%.*]], <i8 undef, i8 0, i8 41>
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <3 x i8> [[A:%.*]], <i8 0, i8 0, i8 41>
; CHECK-NEXT: ret <3 x i1> [[CMP]]
;
%cmp = icmp sge <3 x i8> %a, <i8 undef, i8 1, i8 42>
Original file line number Diff line number Diff line change
@@ -106,7 +106,7 @@ define <2 x i32> @p7_vec_splat_sgt(<2 x i32> %x, <2 x i32> %y) {

define <2 x i32> @p8_vec_nonsplat_undef0(<2 x i32> %x, <2 x i32> %y) {
; CHECK-LABEL: @p8_vec_nonsplat_undef0(
; CHECK-NEXT: [[T_INV:%.*]] = icmp ugt <2 x i32> [[X:%.*]], <i32 65535, i32 undef>
; CHECK-NEXT: [[T_INV:%.*]] = icmp ugt <2 x i32> [[X:%.*]], <i32 65535, i32 65535>
; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[T_INV]], <2 x i32> <i32 65535, i32 65535>, <2 x i32> [[Y:%.*]]
; CHECK-NEXT: ret <2 x i32> [[R]]
;
@@ -126,7 +126,7 @@ define <2 x i32> @p9_vec_nonsplat_undef1(<2 x i32> %x, <2 x i32> %y) {
}
define <2 x i32> @p10_vec_nonsplat_undef2(<2 x i32> %x, <2 x i32> %y) {
; CHECK-LABEL: @p10_vec_nonsplat_undef2(
; CHECK-NEXT: [[T_INV:%.*]] = icmp ugt <2 x i32> [[X:%.*]], <i32 65535, i32 undef>
; CHECK-NEXT: [[T_INV:%.*]] = icmp ugt <2 x i32> [[X:%.*]], <i32 65535, i32 65535>
; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[T_INV]], <2 x i32> <i32 65535, i32 undef>, <2 x i32> [[Y:%.*]]
; CHECK-NEXT: ret <2 x i32> [[R]]
;

0 comments on commit e6608f7

Please sign in to comment.