[llvm] b07aab8 - [GlobalOpt] Iterate over replaced values deterministically to constprop
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Mon May 2 09:44:18 PDT 2022
Author: Arthur Eubanks
Date: 2022-05-02T09:43:20-07:00
New Revision: b07aab8fc1088ef66ecbe2befc3ef7e3936a390e
URL: https://github.com/llvm/llvm-project/commit/b07aab8fc1088ef66ecbe2befc3ef7e3936a390e
DIFF: https://github.com/llvm/llvm-project/commit/b07aab8fc1088ef66ecbe2befc3ef7e3936a390e.diff
LOG: [GlobalOpt] Iterate over replaced values deterministically to constprop
If there are pre-existing dead instructions, the order we visit replaced
values can cause us sometimes to not delete dead instructions.
The added test non-deterministically failed without the change.
Added:
llvm/test/Transforms/GlobalOpt/malloc-promote-6.ll
Modified:
llvm/lib/Transforms/IPO/GlobalOpt.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
index 72b94cda01bf4..157cb27ec96f5 100644
--- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -17,6 +17,7 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/Twine.h"
#include "llvm/ADT/iterator_range.h"
@@ -904,7 +905,7 @@ OptimizeGlobalAddressOfAllocation(GlobalVariable *GV, CallInst *CI,
}
}
- SmallPtrSet<Constant *, 1> RepValues;
+ SmallSetVector<Constant *, 1> RepValues;
RepValues.insert(NewGV);
// If there is a comparison against null, we will insert a global bool to
diff --git a/llvm/test/Transforms/GlobalOpt/malloc-promote-6.ll b/llvm/test/Transforms/GlobalOpt/malloc-promote-6.ll
new file mode 100644
index 0000000000000..f35e1aea60158
--- /dev/null
+++ b/llvm/test/Transforms/GlobalOpt/malloc-promote-6.ll
@@ -0,0 +1,30 @@
+; RUN: opt -passes=globalopt -S < %s | FileCheck %s
+
+; CHECK-NOT: @global
+
+ at global = internal global i8* null
+ at llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @zot, i8* null }]
+
+declare i8* @_Znwm(i64)
+
+define internal void @widget() {
+ %tmp = tail call i8* @_Znwm(i64 0)
+ %tmp2 = getelementptr inbounds i8, i8* %tmp, i64 0
+ store i8* %tmp, i8** @global, align 8
+ call void @baz(void ()* @spam)
+ ret void
+}
+
+define internal void @spam() {
+ %tmp = load i8*, i8** @global, align 8
+ %tmp2 = getelementptr inbounds i8, i8* %tmp, i64 0
+ ret void
+}
+
+define internal void @zot() {
+ call void @baz(void ()* @widget)
+ ret void
+}
+
+declare void @baz(void ()*)
+
More information about the llvm-commits
mailing list