[PATCH] D50554: [ValueTracking] Accept vectors of pointer in GetUnderlyingObject utility

Serguei Katkov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 10 03:22:04 PDT 2018


skatkov updated this revision to Diff 160083.
skatkov added a comment.

Thank you! I've added two unit tests.


https://reviews.llvm.org/D50554

Files:
  lib/Analysis/ValueTracking.cpp
  unittests/Analysis/ValueTrackingTest.cpp


Index: unittests/Analysis/ValueTrackingTest.cpp
===================================================================
--- unittests/Analysis/ValueTrackingTest.cpp
+++ unittests/Analysis/ValueTrackingTest.cpp
@@ -313,3 +313,51 @@
   EXPECT_EQ(Known.One.getZExtValue(), 32u);
   EXPECT_EQ(Known.Zero.getZExtValue(), 95u);
 }
+
+TEST(ValueTracking, GetUnderlyingObjectForBitcastVector) {
+  StringRef Assembly = "define <2 x i32*> @f() { "
+                       "  %a = alloca i64 "
+                       "  %b = bitcast i64* %a to <2 x i32*>"
+                       "  ret <2 x i32*> %b "
+                       "} ";
+
+  LLVMContext Context;
+  SMDiagnostic Error;
+  auto M = parseAssemblyString(Assembly, Error, Context);
+  assert(M && "Bad assembly?");
+
+  const DataLayout &DL = M->getDataLayout();
+
+  auto *F = M->getFunction("f");
+  assert(F && "Bad assembly?");
+
+  auto &BB = F->getEntryBlock();
+
+  auto *RVal = cast<ReturnInst>(BB.getTerminator())->getOperand(0);
+  auto *Alloc = GetUnderlyingObject(RVal, DL);
+  EXPECT_EQ(Alloc, &*BB.begin());
+}
+
+TEST(ValueTracking, GetUnderlyingObjectForGepVector) {
+  StringRef Assembly = "define <2 x i64*> @f() { "
+                       "  %a = alloca i64 "
+                       "  %g = getelementptr inbounds i64, i64* %a, <2 x i64> <i64 0, i64 4> "
+                       "  ret <2 x i64*> %g"
+                       "} ";
+
+  LLVMContext Context;
+  SMDiagnostic Error;
+  auto M = parseAssemblyString(Assembly, Error, Context);
+  assert(M && "Bad assembly?");
+
+  const DataLayout &DL = M->getDataLayout();
+
+  auto *F = M->getFunction("f");
+  assert(F && "Bad assembly?");
+
+  auto &BB = F->getEntryBlock();
+
+  auto *RVal = cast<ReturnInst>(BB.getTerminator())->getOperand(0);
+  auto *Alloc = GetUnderlyingObject(RVal, DL);
+  EXPECT_EQ(Alloc, &*BB.begin());
+}
Index: lib/Analysis/ValueTracking.cpp
===================================================================
--- lib/Analysis/ValueTracking.cpp
+++ lib/Analysis/ValueTracking.cpp
@@ -3488,7 +3488,7 @@
 
 Value *llvm::GetUnderlyingObject(Value *V, const DataLayout &DL,
                                  unsigned MaxLookup) {
-  if (!V->getType()->isPointerTy())
+  if (!V->getType()->isPtrOrPtrVectorTy())
     return V;
   for (unsigned Count = 0; MaxLookup == 0 || Count < MaxLookup; ++Count) {
     if (GEPOperator *GEP = dyn_cast<GEPOperator>(V)) {
@@ -3530,7 +3530,7 @@
 
       return V;
     }
-    assert(V->getType()->isPointerTy() && "Unexpected operand type!");
+    assert(V->getType()->isPtrOrPtrVectorTy() && "Unexpected operand type!");
   }
   return V;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50554.160083.patch
Type: text/x-patch
Size: 2619 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180810/f98ad821/attachment.bin>


More information about the llvm-commits mailing list