[llvm] 8351f9b - [ValueTracking] Fix assert on shufflevector of pointers

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 27 12:19:43 PST 2020


Author: Nikita Popov
Date: 2020-11-27T21:19:31+01:00
New Revision: 8351f9b5ce7e3e2af5773c83e618d68a21d93d7e

URL: https://github.com/llvm/llvm-project/commit/8351f9b5ce7e3e2af5773c83e618d68a21d93d7e
DIFF: https://github.com/llvm/llvm-project/commit/8351f9b5ce7e3e2af5773c83e618d68a21d93d7e.diff

LOG: [ValueTracking] Fix assert on shufflevector of pointers

In this case getScalarSizeInBits() is not well-defined. Use the
existing TyBits variable that handles vectors of pointers correctly.

Added: 
    

Modified: 
    llvm/lib/Analysis/ValueTracking.cpp
    llvm/unittests/Analysis/ValueTrackingTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 90f8dff87472..32e0ca321dec 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -2900,8 +2900,7 @@ static unsigned ComputeNumSignBitsImpl(const Value *V,
       // fall-back.
       if (Tmp == 1)
         break;
-      assert(Tmp <= Ty->getScalarSizeInBits() &&
-             "Failed to determine minimum sign bits");
+      assert(Tmp <= TyBits && "Failed to determine minimum sign bits");
       return Tmp;
     }
     case Instruction::Call: {

diff  --git a/llvm/unittests/Analysis/ValueTrackingTest.cpp b/llvm/unittests/Analysis/ValueTrackingTest.cpp
index 35ede6cb9319..721a342040ba 100644
--- a/llvm/unittests/Analysis/ValueTrackingTest.cpp
+++ b/llvm/unittests/Analysis/ValueTrackingTest.cpp
@@ -690,6 +690,15 @@ TEST_F(ValueTrackingTest, ComputeNumSignBits_Shuffle2) {
   EXPECT_EQ(ComputeNumSignBits(A, M->getDataLayout()), 1u);
 }
 
+TEST_F(ValueTrackingTest, ComputeNumSignBits_Shuffle_Pointers) {
+  parseAssembly(
+      "define <2 x i32*> @test(<2 x i32*> %x) {\n"
+      "  %A = shufflevector <2 x i32*> zeroinitializer, <2 x i32*> undef, <2 x i32> zeroinitializer\n"
+      "  ret <2 x i32*> %A\n"
+      "}\n");
+  EXPECT_EQ(ComputeNumSignBits(A, M->getDataLayout()), 64u);
+}
+
 TEST(ValueTracking, propagatesPoison) {
   std::string AsmHead = "declare i32 @g(i32)\n"
                         "define void @f(i32 %x, i32 %y, float %fx, float %fy, "


        


More information about the llvm-commits mailing list