<div dir="ltr">Forward to the right mailing list.<br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">David Blaikie</b> <span dir="ltr"><<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>></span><br>Date: Fri, Sep 11, 2015 at 2:44 PM<br>Subject: Re: [llvm] r216023 - IR: Fix a missed case when threading OnlyIfReduced through ConstantExpr<br>To: "Duncan P. N. Exon Smith" <<a href="mailto:dexonsmith@apple.com">dexonsmith@apple.com</a>><br>Cc: "<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a>" <<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a>><br><br><br><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Tue, Aug 19, 2014 at 2:18 PM, Duncan P. N. Exon Smith <span dir="ltr"><<a href="mailto:dexonsmith@apple.com" target="_blank">dexonsmith@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: dexonsmith<br>
Date: Tue Aug 19 16:18:21 2014<br>
New Revision: 216023<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=216023&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=216023&view=rev</a><br>
Log:<br>
IR: Fix a missed case when threading OnlyIfReduced through ConstantExpr<br>
<br>
In r216015 I missed propagating `OnlyIfReduced` through the inline<br>
versions of `getGetElementPtr()` (I was relying on compile failures on<br>
mismatches between the header and source signatures to get them all).<br>
<br>
Modified:<br>
    llvm/trunk/include/llvm/IR/Constants.h<br>
    llvm/trunk/unittests/IR/ConstantsTest.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/IR/Constants.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Constants.h?rev=216023&r1=216022&r2=216023&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Constants.h?rev=216023&r1=216022&r2=216023&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/IR/Constants.h (original)<br>
+++ llvm/trunk/include/llvm/IR/Constants.h Tue Aug 19 16:18:21 2014<br>
@@ -1036,9 +1036,9 @@ public:<br>
   static Constant *getGetElementPtr(Constant *C, ArrayRef<Constant *> IdxList,<br>
                                     bool InBounds = false,<br>
                                     Type *OnlyIfReducedTy = nullptr) {<br>
-    return getGetElementPtr(C, makeArrayRef((Value * const *)IdxList.data(),<br>
-                                            IdxList.size()),<br>
-                            InBounds);<br>
+    return getGetElementPtr(<br>
+        C, makeArrayRef((Value * const *)IdxList.data(), IdxList.size()),<br>
+        InBounds, OnlyIfReducedTy);<br>
   }<br>
   static Constant *getGetElementPtr(Constant *C, Constant *Idx,<br>
                                     bool InBounds = false,<br>
@@ -1046,7 +1046,7 @@ public:<br>
     // This form of the function only exists to avoid ambiguous overload<br>
     // warnings about whether to convert Idx to ArrayRef<Constant *> or<br>
     // ArrayRef<Value *>.<br>
-    return getGetElementPtr(C, cast<Value>(Idx), InBounds);<br>
+    return getGetElementPtr(C, cast<Value>(Idx), InBounds, OnlyIfReducedTy);<br>
   }<br>
   static Constant *getGetElementPtr(Constant *C, ArrayRef<Value *> IdxList,<br>
                                     bool InBounds = false,<br>
<br>
Modified: llvm/trunk/unittests/IR/ConstantsTest.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/ConstantsTest.cpp?rev=216023&r1=216022&r2=216023&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/ConstantsTest.cpp?rev=216023&r1=216022&r2=216023&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/unittests/IR/ConstantsTest.cpp (original)<br>
+++ llvm/trunk/unittests/IR/ConstantsTest.cpp Tue Aug 19 16:18:21 2014<br>
@@ -322,5 +322,30 @@ TEST(ConstantsTest, ConstantExprReplaceW<br>
   ASSERT_EQ(Int2, Ref->getInitializer());<br>
 }<br>
<br>
+TEST(ConstantsTest, GEPReplaceWithConstant) {<br>
+  LLVMContext Context;<br>
+  std::unique_ptr<Module> M(new Module("MyModule", Context));<br>
+<br>
+  Type *IntTy = Type::getInt32Ty(Context);<br>
+  Type *PtrTy = PointerType::get(IntTy, 0);<br>
+  auto *C1 = ConstantInt::get(IntTy, 1);<br>
+  auto *Placeholder = new GlobalVariable(<br>
+      *M, IntTy, false, GlobalValue::ExternalWeakLinkage, nullptr);<br>
+  auto *GEP = ConstantExpr::getGetElementPtr(Placeholder, C1);<br>
+  ASSERT_EQ(GEP->getOperand(0), Placeholder);<br>
+<br>
+  auto *Ref =<br>
+      new GlobalVariable(*M, PtrTy, false, GlobalValue::ExternalLinkage, GEP);<br>
+  ASSERT_EQ(GEP, Ref->getInitializer());<br>
+<br>
+  auto *Global = new GlobalVariable(*M, PtrTy, false,<br>
+                                    GlobalValue::ExternalLinkage, nullptr);<br>
+  auto *Alias = GlobalAlias::create(IntTy, 0, GlobalValue::ExternalLinkage,<br>
+                                    "alias", Global, M.get());<br></blockquote><div><br></div></div></div><div>*casts Lesser Thread Necromancy*<br><br>So... this alias is bad. The Global is of type i32*, but the alias is of type i32 - types don't match. Unfortunately there's not (currently) any assertion in GlobalAlias's ctor/factory to ensure this, but it would fail the Verifier around Verifier.cpp:603<br><br>If I correct the GlobalAlias's type, then it doesn't match the Placeholder which it's RAUW'd with.<br><br>Any idea which parts of this need to remain in tact for the test to be valuable?<br>Should we change the Placeholder type to match the GlobalAlias and Globals type?<br>Should we add a bitcast of the Global when constructing the GlobalAlias?<br>Something else?<br><br>(this came up while trying to fix/migrate aliases to take explicit pointee types & using an assertion to ensure I didn't foul up the migration)</div><span class=""><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+  Placeholder->replaceAllUsesWith(Alias);<br>
+  ASSERT_EQ(GEP, Ref->getInitializer());<br>
+  ASSERT_EQ(GEP->getOperand(0), Alias);<br>
+}<br>
+<br>
 }  // end anonymous namespace<br>
 }  // end namespace llvm<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></span></div><br></div></div>
</div><br></div>