[llvm] r309594 - [IPSCCP] Guard a user of getInitializer with hasDefinitiveInitializer

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 31 10:47:07 PDT 2017


Author: majnemer
Date: Mon Jul 31 10:47:07 2017
New Revision: 309594

URL: http://llvm.org/viewvc/llvm-project?rev=309594&view=rev
Log:
[IPSCCP] Guard a user of getInitializer with hasDefinitiveInitializer

We are not allowed to reason about an initializer value without first
consulting hasDefinitiveInitializer.

Added:
    llvm/trunk/test/Transforms/SCCP/definite-initializer.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/SCCP.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/SCCP.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SCCP.cpp?rev=309594&r1=309593&r2=309594&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SCCP.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SCCP.cpp Mon Jul 31 10:47:07 2017
@@ -1790,7 +1790,8 @@ static bool runIPSCCP(Module &M, const D
   // variables that do not have their 'addresses taken'.  If they don't have
   // their addresses taken, we can propagate constants through them.
   for (GlobalVariable &G : M.globals())
-    if (!G.isConstant() && G.hasLocalLinkage() && !AddressIsTaken(&G))
+    if (!G.isConstant() && G.hasLocalLinkage() &&
+        G.hasDefinitiveInitializer() && !AddressIsTaken(&G))
       Solver.TrackValueOfGlobalVariable(&G);
 
   // Solve for constants.

Added: llvm/trunk/test/Transforms/SCCP/definite-initializer.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SCCP/definite-initializer.ll?rev=309594&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/SCCP/definite-initializer.ll (added)
+++ llvm/trunk/test/Transforms/SCCP/definite-initializer.ll Mon Jul 31 10:47:07 2017
@@ -0,0 +1,11 @@
+; RUN: opt -S -ipsccp < %s | FileCheck %s
+ at d = internal externally_initialized global i32 0, section ".openbsd.randomdata", align 4
+
+; CHECK-LABEL: @test1(
+define i32 @test1() {
+entry:
+  %load = load i32, i32* @d, align 4
+  ret i32 %load
+; CHECK: %[[load:.*]] = load i32, i32* @d, align 4
+; CHECK: ret i32 %[[load]]
+}




More information about the llvm-commits mailing list