summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@gmail.com>2017-06-03 18:50:29 +0000
committerCraig Topper <craig.topper@gmail.com>2017-06-03 18:50:29 +0000
commit7c553edcedca1c085af33906eb4549114da21f34 (patch)
tree8b3c021013b0c0380142c57d8bdef46dd992189c
parent36fa2f0dee480b4fcc3de67ee881faac7709a2a9 (diff)
downloadbcm5719-llvm-7c553edcedca1c085af33906eb4549114da21f34.tar.gz
bcm5719-llvm-7c553edcedca1c085af33906eb4549114da21f34.zip
[ConstantFolding] Fix constant folding for vector cttz and ctlz intrinsics to understand that the second argument is still a scalar.
llvm-svn: 304668
-rw-r--r--llvm/lib/Analysis/ConstantFolding.cpp7
-rw-r--r--llvm/test/Transforms/InstCombine/intrinsics.ll6
-rw-r--r--llvm/test/Transforms/InstSimplify/call.ll3
3 files changed, 10 insertions, 6 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index a906770dbb3..d33fe4a0094 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/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/llvm/test/Transforms/InstCombine/intrinsics.ll b/llvm/test/Transforms/InstCombine/intrinsics.ll
index 04b9088e362..abe0c784754 100644
--- a/llvm/test/Transforms/InstCombine/intrinsics.ll
+++ b/llvm/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/llvm/test/Transforms/InstSimplify/call.ll b/llvm/test/Transforms/InstSimplify/call.ll
index ee8f35aa7cd..994ff6b8c0d 100644
--- a/llvm/test/Transforms/InstSimplify/call.ll
+++ b/llvm/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> <i256 10, i256 10>, i1 false)
-; CHECK-NEXT: ret <2 x i256> [[X]]
+; CHECK-NEXT: ret <2 x i256> <i256 1, i256 1>
;
%x = call <2 x i256> @llvm.cttz.v2i256(<2 x i256> <i256 10, i256 10>, i1 false)
ret <2 x i256> %x
OpenPOWER on IntegriCloud