From 4239e23ef8ec4d18c0fe271c0318870bcc85d7ec Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Sat, 4 Jun 2016 22:04:05 +0000 Subject: [PATCH] [InstCombine] allow vector constants for cast+icmp fold This is step 1 of unknown towards fixing PR28001: https://llvm.org/bugs/show_bug.cgi?id=28001 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271810 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/InstCombine/InstCombineCompares.cpp | 2 +- test/Transforms/InstCombine/cast.ll | 15 +++++++++++---- test/Transforms/InstCombine/signed-comparison.ll | 5 +---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/Transforms/InstCombine/InstCombineCompares.cpp b/lib/Transforms/InstCombine/InstCombineCompares.cpp index 0f119bfada8..e7f87d44aea 100644 --- a/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -2439,7 +2439,7 @@ Instruction *InstCombiner::visitICmpInstWithCastAndCast(ICmpInst &ICI) { } // If we aren't dealing with a constant on the RHS, exit early. - auto *CI = dyn_cast(ICI.getOperand(1)); + auto *CI = dyn_cast(ICI.getOperand(1)); if (!CI) return nullptr; diff --git a/test/Transforms/InstCombine/cast.ll b/test/Transforms/InstCombine/cast.ll index 91b1348f784..e062896e43e 100644 --- a/test/Transforms/InstCombine/cast.ll +++ b/test/Transforms/InstCombine/cast.ll @@ -214,12 +214,9 @@ define i1 @test19(i32 %X) { ret i1 %Z } -; FIXME: Vector should be the same as scalar. - define <2 x i1> @test19vec(<2 x i32> %X) { ; CHECK-LABEL: @test19vec( -; CHECK-NEXT: [[C:%.*]] = sext <2 x i32> %X to <2 x i64> -; CHECK-NEXT: [[Z:%.*]] = icmp slt <2 x i64> [[C]], +; CHECK-NEXT: [[Z:%.*]] = icmp slt <2 x i32> %X, ; CHECK-NEXT: ret <2 x i1> [[Z]] ; %c = sext <2 x i32> %X to <2 x i64> @@ -227,6 +224,16 @@ define <2 x i1> @test19vec(<2 x i32> %X) { ret <2 x i1> %Z } +define <3 x i1> @test19vec2(<3 x i1> %X) { +; CHECK-LABEL: @test19vec2( +; CHECK-NEXT: [[CMPEQ:%.*]] = icmp eq <3 x i1> %X, zeroinitializer +; CHECK-NEXT: ret <3 x i1> [[CMPEQ]] +; + %sext = sext <3 x i1> %X to <3 x i32> + %cmpeq = icmp eq <3 x i32> %sext, zeroinitializer + ret <3 x i1> %cmpeq +} + define i1 @test20(i1 %B) { ; CHECK-LABEL: @test20( ; CHECK-NEXT: ret i1 false diff --git a/test/Transforms/InstCombine/signed-comparison.ll b/test/Transforms/InstCombine/signed-comparison.ll index 5092ce713b7..1fbfc2d1463 100644 --- a/test/Transforms/InstCombine/signed-comparison.ll +++ b/test/Transforms/InstCombine/signed-comparison.ll @@ -13,12 +13,9 @@ define i1 @scalar_zext_slt(i16 %t4) { ret i1 %t6 } -; FIXME: Vector compare should work the same as scalar. - define <4 x i1> @vector_zext_slt(<4 x i16> %t4) { ; CHECK-LABEL: @vector_zext_slt( -; CHECK-NEXT: [[T5:%.*]] = zext <4 x i16> %t4 to <4 x i32> -; CHECK-NEXT: [[T6:%.*]] = icmp ult <4 x i32> [[T5]], +; CHECK-NEXT: [[T6:%.*]] = icmp ult <4 x i16> %t4, ; CHECK-NEXT: ret <4 x i1> [[T6]] ; %t5 = zext <4 x i16> %t4 to <4 x i32> -- 2.11.0