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

Andrew Zhogin andrew.zhogin at gmail.com
Fri Jul 17 16:41:31 PDT 2015


andrew.zhogin updated this revision to Diff 30050.
andrew.zhogin added a comment.

Addressed the review comments.


http://reviews.llvm.org/D11306

Files:
  lib/Analysis/ConstantFolding.cpp
  test/Analysis/ConstantFolding/global-alias-constprop.ll

Index: test/Analysis/ConstantFolding/global-alias-constprop.ll
===================================================================
--- test/Analysis/ConstantFolding/global-alias-constprop.ll
+++ test/Analysis/ConstantFolding/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
+}
Index: lib/Analysis/ConstantFolding.cpp
===================================================================
--- lib/Analysis/ConstantFolding.cpp
+++ 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)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11306.30050.patch
Type: text/x-patch
Size: 1199 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150717/4ac36d3f/attachment.bin>


More information about the llvm-commits mailing list