diff options
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 5 | ||||
-rw-r--r-- | llvm/test/Transforms/InstCombine/icmp-vec.ll | 37 |
2 files changed, 40 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index acc03e722f0..e06ec3945e3 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/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<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(); diff --git a/llvm/test/Transforms/InstCombine/icmp-vec.ll b/llvm/test/Transforms/InstCombine/icmp-vec.ll index f8416cc6e95..df653caa56d 100644 --- a/llvm/test/Transforms/InstCombine/icmp-vec.ll +++ b/llvm/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, <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 |