UseListOrder: Don't give constant IDs to GlobalValues
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Thu, 31 Jul 2014 00:13:28 +0000 (00:13 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Thu, 31 Jul 2014 00:13:28 +0000 (00:13 +0000)
Since initializers of GlobalValues are being assigned IDs before
GlobalValues themselves, explicitly exclude GlobalValues from the
constant pool.  Added targeted test in `test/Bitcode/use-list-order.ll`
and added two more RUN lines in `test/Assembly`.

This is part of PR5680.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@214368 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Bitcode/Writer/ValueEnumerator.cpp
test/Assembler/ConstantExprFold.ll
test/Assembler/ConstantExprFoldCast.ll
test/Bitcode/use-list-order.ll

index fa1c8b3c57d6be6e7a32823300c416a0d65d4c4e..2ac53fea8a98bc9ad1e9a6266ac59e6488ff1c3c 100644 (file)
@@ -80,12 +80,15 @@ static OrderMap orderModule(const Module *M) {
   // implicitly.
   for (const GlobalVariable &G : M->globals())
     if (G.hasInitializer())
-      orderValue(G.getInitializer(), OM);
+      if (!isa<GlobalValue>(G.getInitializer()))
+        orderValue(G.getInitializer(), OM);
   for (const GlobalAlias &A : M->aliases())
-    orderValue(A.getAliasee(), OM);
+    if (!isa<GlobalValue>(A.getAliasee()))
+      orderValue(A.getAliasee(), OM);
   for (const Function &F : *M)
     if (F.hasPrefixData())
-      orderValue(F.getPrefixData(), OM);
+      if (!isa<GlobalValue>(F.getPrefixData()))
+        orderValue(F.getPrefixData(), OM);
   OM.LastGlobalConstantID = OM.size();
 
   // Initializers of GlobalValues are processed in
index fc18ce708edceb521650c90f9e52342ecadc22bb..f3da4e089b43a63313f582078856edf00556ff8d 100644 (file)
@@ -2,6 +2,7 @@
 ; situations
 
 ; RUN: llvm-as < %s | llvm-dis | not grep "("
+; RUN: verify-uselistorder %s -preserve-bc-use-list-order -num-shuffles=5
 
 @A = global i64 0
 
index 161a4ca3575776579629413ea9b8acef26ea0104..825ca573d94e2f2f98fed07aefbee6f19bfa029a 100644 (file)
@@ -1,6 +1,7 @@
 ; This test checks to make sure that constant exprs fold in some simple situations
 
 ; RUN: llvm-as < %s | llvm-dis | not grep cast
+; RUN: verify-uselistorder %s -preserve-bc-use-list-order -num-shuffles=5
 
 @A = global i32* bitcast (i8* null to i32*)  ; Cast null -> fold
 @B = global i32** bitcast (i32** @A to i32**)   ; Cast to same type -> fold
index fb18b462da51fe959a3c6e028ee79c4b0dbe596e..3d3a06ca9de3e3fb6177a5dc021745ca5400a37f 100644 (file)
 @globalAndFunction = global i4 4
 @globalAndFunctionGlobalUser = global i4* @globalAndFunction
 
+; Check use-list order for constants used by globals that are themselves used
+; as aliases.  This confirms that this globals are recognized as GlobalValues
+; (not general constants).
+@const.global = global i63 0
+@const.global.ptr = global i63* @const.global
+@const.global.2 = global i63 0
+
+; Same as above, but for aliases.
+@const.target = global i62 1
+@const.alias = alias i62* @const.target
+@const.alias.ptr = alias i62* @const.alias
+@const.alias.2 = alias i62* @const.target
+
 define i64 @f(i64 %f) {
 entry:
   %sum = add i64 %f, 0