[llvm] r269439 - [InstCombine] handle zero constant vectors for LE/GE comparisons too

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Fri May 13 10:28:12 PDT 2016


Author: spatel
Date: Fri May 13 12:28:12 2016
New Revision: 269439

URL: http://llvm.org/viewvc/llvm-project?rev=269439&view=rev
Log:
[InstCombine] handle zero constant vectors for LE/GE comparisons too

Enhancement to: http://reviews.llvm.org/rL269426
With discussion in: http://reviews.llvm.org/D17859

This should complete the fixes for: PR26701, PR26819:
https://llvm.org/bugs/show_bug.cgi?id=26701
https://llvm.org/bugs/show_bug.cgi?id=26819
 

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
    llvm/trunk/test/Transforms/InstCombine/icmp-vec.ll

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=269439&r1=269438&r2=269439&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Fri May 13 12:28:12 2016
@@ -3130,8 +3130,9 @@ static ICmpInst *canonicalizeCmpWithCons
   }
 
   // The usual vector types are ConstantDataVector. Exotic vector types are
-  // ConstantVector. They both derive from Constant.
-  if (isa<ConstantDataVector>(Op1) || isa<ConstantVector>(Op1)) {
+  // ConstantVector. Zeros are special. They all derive from Constant.
+  if (isa<ConstantDataVector>(Op1) || isa<ConstantVector>(Op1) ||
+      isa<ConstantAggregateZero>(Op1)) {
     Constant *Op1C = cast<Constant>(Op1);
     Type *Op1Type = Op1->getType();
     unsigned NumElts = Op1Type->getVectorNumElements();

Modified: llvm/trunk/test/Transforms/InstCombine/icmp-vec.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/icmp-vec.ll?rev=269439&r1=269438&r2=269439&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/icmp-vec.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/icmp-vec.ll Fri May 13 12:28:12 2016
@@ -42,6 +42,43 @@ define <2 x i1> @ule(<2 x i8> %x) {
   ret <2 x i1> %cmp
 }
 
+; Zeros are special: they're ConstantAggregateZero.
+
+define <2 x i1> @sge_zero(<2 x i8> %x) {
+; CHECK-LABEL: @sge_zero(
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sgt <2 x i8> %x, <i8 -1, i8 -1>
+; CHECK-NEXT:    ret <2 x i1> [[CMP]]
+;
+  %cmp = icmp sge <2 x i8> %x, <i8 0, i8 0>
+  ret <2 x i1> %cmp
+}
+
+define <2 x i1> @uge_zero(<2 x i8> %x) {
+; CHECK-LABEL: @uge_zero(
+; CHECK-NEXT:    ret <2 x i1> <i1 true, i1 true>
+;
+  %cmp = icmp uge <2 x i8> %x, <i8 0, i8 0>
+  ret <2 x i1> %cmp
+}
+
+define <2 x i1> @sle_zero(<2 x i8> %x) {
+; CHECK-LABEL: @sle_zero(
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt <2 x i8> %x, <i8 1, i8 1>
+; CHECK-NEXT:    ret <2 x i1> [[CMP]]
+;
+  %cmp = icmp sle <2 x i8> %x, <i8 0, i8 0>
+  ret <2 x i1> %cmp
+}
+
+define <2 x i1> @ule_zero(<2 x i8> %x) {
+; CHECK-LABEL: @ule_zero(
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ult <2 x i8> %x, <i8 1, i8 1>
+; CHECK-NEXT:    ret <2 x i1> [[CMP]]
+;
+  %cmp = icmp ule <2 x i8> %x, <i8 0, i8 0>
+  ret <2 x i1> %cmp
+}
+
 ; Weird types are ConstantVectors, not ConstantDataVectors. For an i3 type:
 ; Signed min = -4
 ; Unsigned min = 0




More information about the llvm-commits mailing list