]> granicus.if.org Git - llvm/commitdiff
[ConstantFolding] Fix constant folding for vector cttz and ctlz intrinsics to underst...
authorCraig Topper <craig.topper@gmail.com>
Sat, 3 Jun 2017 18:50:29 +0000 (18:50 +0000)
committerCraig Topper <craig.topper@gmail.com>
Sat, 3 Jun 2017 18:50:29 +0000 (18:50 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@304668 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/ConstantFolding.cpp
test/Transforms/InstCombine/intrinsics.ll
test/Transforms/InstSimplify/call.ll

index a906770dbb341ba466a58d72949cd0f29e304d22..d33fe4a009429ba45f65c0f24109918b0af15e0f 100644 (file)
@@ -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;
index 04b9088e36296e0edcdbb0219978c6310a58664d..abe0c7847542969f26b6a389340c2491431b7606 100644 (file)
@@ -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
index ee8f35aa7cda442fdf025533a834966e030fa678..994ff6b8c0d9f555a7ce600068eb22752db88621 100644 (file)
@@ -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