From 96f4b128800cc567a4355025963ea64caa750904 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Tue, 15 Mar 2016 14:18:26 +0000 Subject: [PATCH] [GlobalOpt] Don't look through aliases when sorting names of globals. If both are different aliases to the same value the sorting becomes non-deterministic as array_pod_sort is not stable. llvm-svn: 263550 --- llvm/lib/Transforms/IPO/GlobalOpt.cpp | 5 +++-- llvm/test/Transforms/GlobalOpt/alias-used.ll | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp index b9cef720..f6458f5 100644 --- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp +++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp @@ -2199,8 +2199,9 @@ static bool EvaluateStaticConstructor(Function *F, const DataLayout &DL, } static int compareNames(Constant *const *A, Constant *const *B) { - return (*A)->stripPointerCasts()->getName().compare( - (*B)->stripPointerCasts()->getName()); + Value *AStripped = (*A)->stripPointerCastsNoFollowAliases(); + Value *BStripped = (*B)->stripPointerCastsNoFollowAliases(); + return AStripped->getName().compare(BStripped->getName()); } static void setUsedInitializer(GlobalVariable &V, diff --git a/llvm/test/Transforms/GlobalOpt/alias-used.ll b/llvm/test/Transforms/GlobalOpt/alias-used.ll index 02136a0..bb90587 100644 --- a/llvm/test/Transforms/GlobalOpt/alias-used.ll +++ b/llvm/test/Transforms/GlobalOpt/alias-used.ll @@ -7,7 +7,7 @@ @ia = internal alias i8, i8* @i @llvm.used = appending global [3 x i8*] [i8* bitcast (void ()* @fa to i8*), i8* bitcast (void ()* @f to i8*), i8* @ca], section "llvm.metadata" -; CHECK-DAG: @llvm.used = appending global [3 x i8*] [i8* @ca, i8* bitcast (void ()* @fa to i8*), i8* bitcast (void ()* @f to i8*)], section "llvm.metadata" +; CHECK-DAG: @llvm.used = appending global [3 x i8*] [i8* @ca, i8* bitcast (void ()* @f to i8*), i8* bitcast (void ()* @fa to i8*)], section "llvm.metadata" @llvm.compiler.used = appending global [4 x i8*] [i8* bitcast (void ()* @fa3 to i8*), i8* bitcast (void ()* @fa to i8*), i8* @ia, i8* @i], section "llvm.metadata" ; CHECK-DAG: @llvm.compiler.used = appending global [2 x i8*] [i8* bitcast (void ()* @fa3 to i8*), i8* @ia], section "llvm.metadata" -- 2.7.4