From 4f864166ddda1be2c0d715a84c237c3449883b41 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Fri, 13 May 2016 17:28:12 +0000 Subject: [PATCH] [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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269439 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/InstCombine/InstCombineCompares.cpp | 5 +-- test/Transforms/InstCombine/icmp-vec.ll | 37 ++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/lib/Transforms/InstCombine/InstCombineCompares.cpp b/lib/Transforms/InstCombine/InstCombineCompares.cpp index acc03e722f0..e06ec3945e3 100644 --- a/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -3130,8 +3130,9 @@ static ICmpInst *canonicalizeCmpWithConstant(ICmpInst &I, } // The usual vector types are ConstantDataVector. Exotic vector types are - // ConstantVector. They both derive from Constant. - if (isa(Op1) || isa(Op1)) { + // ConstantVector. Zeros are special. They all derive from Constant. + if (isa(Op1) || isa(Op1) || + isa(Op1)) { Constant *Op1C = cast(Op1); Type *Op1Type = Op1->getType(); unsigned NumElts = Op1Type->getVectorNumElements(); diff --git a/test/Transforms/InstCombine/icmp-vec.ll b/test/Transforms/InstCombine/icmp-vec.ll index f8416cc6e95..df653caa56d 100644 --- a/test/Transforms/InstCombine/icmp-vec.ll +++ b/test/Transforms/InstCombine/icmp-vec.ll @@ -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, +; CHECK-NEXT: ret <2 x i1> [[CMP]] +; + %cmp = icmp sge <2 x i8> %x, + 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> +; + %cmp = icmp uge <2 x i8> %x, + 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, +; CHECK-NEXT: ret <2 x i1> [[CMP]] +; + %cmp = icmp sle <2 x i8> %x, + 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, +; CHECK-NEXT: ret <2 x i1> [[CMP]] +; + %cmp = icmp ule <2 x i8> %x, + ret <2 x i1> %cmp +} + ; Weird types are ConstantVectors, not ConstantDataVectors. For an i3 type: ; Signed min = -4 ; Unsigned min = 0 -- 2.11.0