From: Craig Topper Date: Sat, 3 Jun 2017 18:50:29 +0000 (+0000) Subject: [ConstantFolding] Fix constant folding for vector cttz and ctlz intrinsics to underst... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=02c1af0c1534d11bab661cedb3af9e443b8075c6;p=llvm [ConstantFolding] Fix constant folding for vector cttz and ctlz intrinsics to understand that the second argument is still a scalar. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@304668 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp index a906770dbb3..d33fe4a0094 100644 --- a/lib/Analysis/ConstantFolding.cpp +++ b/lib/Analysis/ConstantFolding.cpp @@ -2034,6 +2034,13 @@ Constant *ConstantFoldVectorCall(StringRef Name, unsigned IntrinsicID, for (unsigned I = 0, E = VTy->getNumElements(); I != E; ++I) { // Gather a column of constants. for (unsigned J = 0, JE = Operands.size(); J != JE; ++J) { + // These intrinsics use a scalar type for their second argument. + if (J == 1 && + (IntrinsicID == Intrinsic::cttz || IntrinsicID == Intrinsic::ctlz)) { + Lane[J] = Operands[J]; + continue; + } + Constant *Agg = Operands[J]->getAggregateElement(I); if (!Agg) return nullptr; diff --git a/test/Transforms/InstCombine/intrinsics.ll b/test/Transforms/InstCombine/intrinsics.ll index 04b9088e362..abe0c784754 100644 --- a/test/Transforms/InstCombine/intrinsics.ll +++ b/test/Transforms/InstCombine/intrinsics.ll @@ -537,8 +537,7 @@ define i32 @ctlz_undef(i32 %Value) { define <2 x i32> @ctlz_undef_vec(<2 x i32> %Value) { ; CHECK-LABEL: @ctlz_undef_vec( -; CHECK-NEXT: [[CTLZ:%.*]] = call <2 x i32> @llvm.ctlz.v2i32(<2 x i32> zeroinitializer, i1 true) -; CHECK-NEXT: ret <2 x i32> [[CTLZ]] +; CHECK-NEXT: ret <2 x i32> undef ; %ctlz = call <2 x i32> @llvm.ctlz.v2i32(<2 x i32> zeroinitializer, i1 true) ret <2 x i32> %ctlz @@ -575,8 +574,7 @@ define i32 @cttz_undef(i32 %Value) nounwind { define <2 x i32> @cttz_undef_vec(<2 x i32> %Value) nounwind { ; CHECK-LABEL: @cttz_undef_vec( -; CHECK-NEXT: [[CTTZ:%.*]] = call <2 x i32> @llvm.cttz.v2i32(<2 x i32> zeroinitializer, i1 true) -; CHECK-NEXT: ret <2 x i32> [[CTTZ]] +; CHECK-NEXT: ret <2 x i32> undef ; %cttz = call <2 x i32> @llvm.cttz.v2i32(<2 x i32> zeroinitializer, i1 true) ret <2 x i32> %cttz diff --git a/test/Transforms/InstSimplify/call.ll b/test/Transforms/InstSimplify/call.ll index ee8f35aa7cd..994ff6b8c0d 100644 --- a/test/Transforms/InstSimplify/call.ll +++ b/test/Transforms/InstSimplify/call.ll @@ -203,8 +203,7 @@ declare <2 x i256> @llvm.cttz.v2i256(<2 x i256> %src, i1 %is_zero_undef) define <2 x i256> @test_cttz_vec() { ; CHECK-LABEL: @test_cttz_vec( -; CHECK-NEXT: [[X:%.*]] = call <2 x i256> @llvm.cttz.v2i256(<2 x i256> , i1 false) -; CHECK-NEXT: ret <2 x i256> [[X]] +; CHECK-NEXT: ret <2 x i256> ; %x = call <2 x i256> @llvm.cttz.v2i256(<2 x i256> , i1 false) ret <2 x i256> %x