[PATCH] D11306: Constant folding support for load from GlobalAlias

David Majnemer david.majnemer at gmail.com
Wed Jul 22 15:29:59 PDT 2015


This revision was automatically updated to reflect the committed changes.
Closed by commit rL242955: [ConstantFolding] Support folding loads from a GlobalAlias (authored by majnemer).

Changed prior to commit:
  http://reviews.llvm.org/D11306?vs=30050&id=30412#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D11306

Files:
  llvm/trunk/lib/Analysis/ConstantFolding.cpp
  llvm/trunk/test/Transforms/SCCP/global-alias-constprop.ll

Index: llvm/trunk/lib/Analysis/ConstantFolding.cpp
===================================================================
--- llvm/trunk/lib/Analysis/ConstantFolding.cpp
+++ llvm/trunk/lib/Analysis/ConstantFolding.cpp
@@ -532,6 +532,10 @@
     if (GV->isConstant() && GV->hasDefinitiveInitializer())
       return GV->getInitializer();
 
+  if (auto *GA = dyn_cast<GlobalAlias>(C))
+    if (GA->getAliasee() && !GA->mayBeOverridden())
+      return ConstantFoldLoadFromConstPtr(GA->getAliasee(), DL);
+
   // If the loaded value isn't a constant expr, we can't handle it.
   ConstantExpr *CE = dyn_cast<ConstantExpr>(C);
   if (!CE)
Index: llvm/trunk/test/Transforms/SCCP/global-alias-constprop.ll
===================================================================
--- llvm/trunk/test/Transforms/SCCP/global-alias-constprop.ll
+++ llvm/trunk/test/Transforms/SCCP/global-alias-constprop.ll
@@ -0,0 +1,11 @@
+; RUN: opt < %s -sccp -S | FileCheck %s
+
+ at 0 = private unnamed_addr constant [2 x i32] [i32 -1, i32 1]
+@"\01??_7A@@6B@" = unnamed_addr alias getelementptr inbounds ([2 x i32], [2 x i32]* @0, i32 0, i32 1)
+
+; CHECK: ret i32 1
+
+define i32 @main() {
+  %a = load i32, i32* @"\01??_7A@@6B@"
+  ret i32 %a
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11306.30412.patch
Type: text/x-patch
Size: 1215 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150722/c885abbd/attachment.bin>


More information about the llvm-commits mailing list