Skip to content

Commit e5ae09b

Browse files
committed
UseListOrder: Don't give constant IDs to GlobalValues
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
1 parent dc6c25c commit e5ae09b

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

lib/Bitcode/Writer/ValueEnumerator.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,15 @@ static OrderMap orderModule(const Module *M) {
8080
// implicitly.
8181
for (const GlobalVariable &G : M->globals())
8282
if (G.hasInitializer())
83-
orderValue(G.getInitializer(), OM);
83+
if (!isa<GlobalValue>(G.getInitializer()))
84+
orderValue(G.getInitializer(), OM);
8485
for (const GlobalAlias &A : M->aliases())
85-
orderValue(A.getAliasee(), OM);
86+
if (!isa<GlobalValue>(A.getAliasee()))
87+
orderValue(A.getAliasee(), OM);
8688
for (const Function &F : *M)
8789
if (F.hasPrefixData())
88-
orderValue(F.getPrefixData(), OM);
90+
if (!isa<GlobalValue>(F.getPrefixData()))
91+
orderValue(F.getPrefixData(), OM);
8992
OM.LastGlobalConstantID = OM.size();
9093

9194
// Initializers of GlobalValues are processed in

test/Assembler/ConstantExprFold.ll

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
; situations
33

44
; RUN: llvm-as < %s | llvm-dis | not grep "("
5+
; RUN: verify-uselistorder %s -preserve-bc-use-list-order -num-shuffles=5
56

67
@A = global i64 0
78

test/Assembler/ConstantExprFoldCast.ll

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
; This test checks to make sure that constant exprs fold in some simple situations
22

33
; RUN: llvm-as < %s | llvm-dis | not grep cast
4+
; RUN: verify-uselistorder %s -preserve-bc-use-list-order -num-shuffles=5
45

56
@A = global i32* bitcast (i8* null to i32*) ; Cast null -> fold
67
@B = global i32** bitcast (i32** @A to i32**) ; Cast to same type -> fold

test/Bitcode/use-list-order.ll

+13
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@
2222
@globalAndFunction = global i4 4
2323
@globalAndFunctionGlobalUser = global i4* @globalAndFunction
2424

25+
; Check use-list order for constants used by globals that are themselves used
26+
; as aliases. This confirms that this globals are recognized as GlobalValues
27+
; (not general constants).
28+
@const.global = global i63 0
29+
@const.global.ptr = global i63* @const.global
30+
@const.global.2 = global i63 0
31+
32+
; Same as above, but for aliases.
33+
@const.target = global i62 1
34+
@const.alias = alias i62* @const.target
35+
@const.alias.ptr = alias i62* @const.alias
36+
@const.alias.2 = alias i62* @const.target
37+
2538
define i64 @f(i64 %f) {
2639
entry:
2740
%sum = add i64 %f, 0

0 commit comments

Comments
 (0)