[llvm-branch-commits] [llvm-branch] r348538 - Merging r348462:
Tom Stellard via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Dec 6 14:36:26 PST 2018
Author: tstellar
Date: Thu Dec 6 14:36:26 2018
New Revision: 348538
URL: http://llvm.org/viewvc/llvm-project?rev=348538&view=rev
Log:
Merging r348462:
------------------------------------------------------------------------
r348462 | lebedevri | 2018-12-06 00:14:24 -0800 (Thu, 06 Dec 2018) | 13 lines
[InstCombine] foldICmpWithLowBitMaskedVal(): don't miscompile -1 vector elts
I was finally able to quantify what i thought was missing in the fix,
it was vector constants. If we have a scalar (and %x, -1),
it will be instsimplified before we reach this code,
but if it is a vector, we may still have a -1 element.
Thus, we want to avoid the fold if *at least one* element is -1.
Or in other words, ignoring the undef elements, no sign bits
should be set. Thus, m_NonNegative().
A follow-up for rL348181
https://bugs.llvm.org/show_bug.cgi?id=39861
------------------------------------------------------------------------
Modified:
llvm/branches/release_70/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/branches/release_70/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-sge-to-icmp-sle.ll
llvm/branches/release_70/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-slt-to-icmp-sgt.ll
Modified: llvm/branches/release_70/lib/Transforms/InstCombine/InstCombineCompares.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_70/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=348538&r1=348537&r2=348538&view=diff
==============================================================================
--- llvm/branches/release_70/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/branches/release_70/lib/Transforms/InstCombine/InstCombineCompares.cpp Thu Dec 6 14:36:26 2018
@@ -2926,6 +2926,8 @@ static Value *foldICmpWithLowBitMaskedVa
return nullptr; // Ignore the other case.
if (!match(M, m_Constant())) // Can not do this fold with non-constant.
return nullptr;
+ if (!match(M, m_NonNegative())) // Must not have any -1 vector elements.
+ return nullptr;
DstPred = ICmpInst::Predicate::ICMP_SLE;
break;
case ICmpInst::Predicate::ICMP_SLT:
@@ -2934,6 +2936,8 @@ static Value *foldICmpWithLowBitMaskedVa
return nullptr; // Ignore the other case.
if (!match(M, m_Constant())) // Can not do this fold with non-constant.
return nullptr;
+ if (!match(M, m_NonNegative())) // Must not have any -1 vector elements.
+ return nullptr;
DstPred = ICmpInst::Predicate::ICMP_SGT;
break;
case ICmpInst::Predicate::ICMP_SLE:
Modified: llvm/branches/release_70/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-sge-to-icmp-sle.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_70/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-sge-to-icmp-sle.ll?rev=348538&r1=348537&r2=348538&view=diff
==============================================================================
--- llvm/branches/release_70/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-sge-to-icmp-sle.ll (original)
+++ llvm/branches/release_70/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-sge-to-icmp-sle.ll Thu Dec 6 14:36:26 2018
@@ -205,8 +205,9 @@ define i1 @nv(i8 %x, i8 %y) {
define <2 x i1> @n3_vec(<2 x i8> %x) {
; CHECK-LABEL: @n3_vec(
-; CHECK-NEXT: [[TMP1:%.*]] = icmp slt <2 x i8> [[X:%.*]], <i8 4, i8 0>
-; CHECK-NEXT: ret <2 x i1> [[TMP1]]
+; CHECK-NEXT: [[TMP0:%.*]] = and <2 x i8> [[X:%.*]], <i8 3, i8 -1>
+; CHECK-NEXT: [[RET:%.*]] = icmp sge <2 x i8> [[TMP0]], [[X]]
+; CHECK-NEXT: ret <2 x i1> [[RET]]
;
%tmp0 = and <2 x i8> %x, <i8 3, i8 -1>
%ret = icmp sge <2 x i8> %tmp0, %x
@@ -215,8 +216,9 @@ define <2 x i1> @n3_vec(<2 x i8> %x) {
define <3 x i1> @n4_vec(<3 x i8> %x) {
; CHECK-LABEL: @n4_vec(
-; CHECK-NEXT: [[TMP1:%.*]] = icmp slt <3 x i8> [[X:%.*]], <i8 4, i8 undef, i8 0>
-; CHECK-NEXT: ret <3 x i1> [[TMP1]]
+; CHECK-NEXT: [[TMP0:%.*]] = and <3 x i8> [[X:%.*]], <i8 3, i8 undef, i8 -1>
+; CHECK-NEXT: [[RET:%.*]] = icmp sge <3 x i8> [[TMP0]], [[X]]
+; CHECK-NEXT: ret <3 x i1> [[RET]]
;
%tmp0 = and <3 x i8> %x, <i8 3, i8 undef, i8 -1>
%ret = icmp sge <3 x i8> %tmp0, %x
Modified: llvm/branches/release_70/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-slt-to-icmp-sgt.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_70/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-slt-to-icmp-sgt.ll?rev=348538&r1=348537&r2=348538&view=diff
==============================================================================
--- llvm/branches/release_70/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-slt-to-icmp-sgt.ll (original)
+++ llvm/branches/release_70/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-slt-to-icmp-sgt.ll Thu Dec 6 14:36:26 2018
@@ -205,8 +205,9 @@ define i1 @nv(i8 %x, i8 %y) {
define <2 x i1> @n3(<2 x i8> %x) {
; CHECK-LABEL: @n3(
-; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt <2 x i8> [[X:%.*]], <i8 3, i8 -1>
-; CHECK-NEXT: ret <2 x i1> [[TMP1]]
+; CHECK-NEXT: [[TMP0:%.*]] = and <2 x i8> [[X:%.*]], <i8 3, i8 -1>
+; CHECK-NEXT: [[RET:%.*]] = icmp slt <2 x i8> [[TMP0]], [[X]]
+; CHECK-NEXT: ret <2 x i1> [[RET]]
;
%tmp0 = and <2 x i8> %x, <i8 3, i8 -1>
%ret = icmp slt <2 x i8> %tmp0, %x
@@ -215,8 +216,9 @@ define <2 x i1> @n3(<2 x i8> %x) {
define <3 x i1> @n4(<3 x i8> %x) {
; CHECK-LABEL: @n4(
-; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt <3 x i8> [[X:%.*]], <i8 3, i8 undef, i8 -1>
-; CHECK-NEXT: ret <3 x i1> [[TMP1]]
+; CHECK-NEXT: [[TMP0:%.*]] = and <3 x i8> [[X:%.*]], <i8 3, i8 undef, i8 -1>
+; CHECK-NEXT: [[RET:%.*]] = icmp slt <3 x i8> [[TMP0]], [[X]]
+; CHECK-NEXT: ret <3 x i1> [[RET]]
;
%tmp0 = and <3 x i8> %x, <i8 3, i8 undef, i8 -1>
%ret = icmp slt <3 x i8> %tmp0, %x
More information about the llvm-branch-commits
mailing list