[PATCH] D130211: [GlobalOpt] Enable evaluation of atomic loads
Alexander Shaposhnikov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 20 16:11:59 PDT 2022
alexander-shaposhnikov created this revision.
alexander-shaposhnikov added reviewers: rnk, aeubanks, nikic.
alexander-shaposhnikov created this object with visibility "All Users".
Herald added a subscriber: hiraditya.
Herald added a project: All.
alexander-shaposhnikov requested review of this revision.
Herald added a project: LLVM.
Relax the check to allow evaluation of atomic loads (but still skip volatile loads).
Test plan:
1/ ninja check-llvm check-clang
2/ Bootstrapped Clang/LLVM tests
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D130211
Files:
llvm/lib/Transforms/Utils/Evaluator.cpp
llvm/test/Transforms/GlobalOpt/ctor-list-opt.ll
Index: llvm/test/Transforms/GlobalOpt/ctor-list-opt.ll
===================================================================
--- llvm/test/Transforms/GlobalOpt/ctor-list-opt.ll
+++ llvm/test/Transforms/GlobalOpt/ctor-list-opt.ll
@@ -1,7 +1,7 @@
; RUN: opt < %s -passes=globalopt -S | FileCheck %s
; CHECK-NOT: CTOR
%ini = type { i32, void()*, i8* }
- at llvm.global_ctors = appending global [15 x %ini] [
+ at llvm.global_ctors = appending global [16 x %ini] [
%ini { i32 65534, void ()* @CTOR1, i8* null },
%ini { i32 65535, void ()* @CTOR1, i8* null },
%ini { i32 65535, void ()* @CTOR1, i8* null },
@@ -13,6 +13,7 @@
%ini { i32 65535, void ()* @CTOR7, i8* null },
%ini { i32 65535, void ()* @CTOR8, i8* null },
%ini { i32 65535, void ()* @CTOR9, i8* null },
+ %ini { i32 65535, void ()* @CTOR14,i8* null },
%ini { i32 65536, void ()* @CTOR10_EXTERNAL, i8* null },
%ini { i32 65536, void ()* @CTOR11, i8* null },
%ini { i32 65537, void ()* @CTOR12, i8* null },
@@ -28,6 +29,7 @@
@D = global double 0.000000e+00 ; <double*> [#uses=1]
@CTORGV = internal global i1 false ; <i1*> [#uses=2]
@GA = global i32 0 ; <i32*> [#uses=1]
+ at GA14 = global i32 0 ; <i32*> [#uses=1]
define internal void @CTOR1() {
ret void
@@ -137,3 +139,12 @@
store atomic i32 123, i32* @GA seq_cst, align 4
ret void
}
+
+; CHECK-NOT: CTOR14
+define internal void @CTOR14() {
+ %X = load atomic i32, i32* @GA14 seq_cst, align 4
+ %Y = add i32 %X, 124
+ store i32 %Y, i32* @GA14
+ ret void
+}
+
Index: llvm/lib/Transforms/Utils/Evaluator.cpp
===================================================================
--- llvm/lib/Transforms/Utils/Evaluator.cpp
+++ llvm/lib/Transforms/Utils/Evaluator.cpp
@@ -337,10 +337,10 @@
if (!Res.first->second.write(Val, Offset, DL))
return false;
} else if (LoadInst *LI = dyn_cast<LoadInst>(CurInst)) {
- if (!LI->isSimple()) {
+ if (LI->isVolatile()) {
LLVM_DEBUG(
- dbgs() << "Found a Load! Not a simple load, can not evaluate.\n");
- return false; // no volatile/atomic accesses.
+ dbgs() << "Found a Load! Volatile load, can not evaluate.\n");
+ return false; // no volatile accesses.
}
Constant *Ptr = getVal(LI->getOperand(0));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130211.446292.patch
Type: text/x-patch
Size: 2267 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220720/e5e9693f/attachment.bin>
More information about the llvm-commits
mailing list