[llvm] e9afdf8 - [GlobalOpt] Enable evaluation of atomic loads
Alexander Shaposhnikov via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 21 14:38:33 PDT 2022
Author: Alexander Shaposhnikov
Date: 2022-07-21T21:36:11Z
New Revision: e9afdf838eb9bb0914f58c762b676aa31b9d41d1
URL: https://github.com/llvm/llvm-project/commit/e9afdf838eb9bb0914f58c762b676aa31b9d41d1
DIFF: https://github.com/llvm/llvm-project/commit/e9afdf838eb9bb0914f58c762b676aa31b9d41d1.diff
LOG: [GlobalOpt] Enable evaluation of atomic loads
Relax the check to allow evaluation of atomic loads
(but still skip volatile loads).
Test plan:
1/ ninja check-llvm check-clang
2/ Bootstrapped LLVM/Clang pass tests
Differential revision: https://reviews.llvm.org/D130211
Added:
Modified:
llvm/lib/Transforms/Utils/Evaluator.cpp
llvm/test/Transforms/GlobalOpt/ctor-list-opt.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/Evaluator.cpp b/llvm/lib/Transforms/Utils/Evaluator.cpp
index 3989fbc0da661..7509fde6df9d6 100644
--- a/llvm/lib/Transforms/Utils/Evaluator.cpp
+++ b/llvm/lib/Transforms/Utils/Evaluator.cpp
@@ -337,10 +337,10 @@ bool Evaluator::EvaluateBlock(BasicBlock::iterator CurInst, BasicBlock *&NextBB,
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));
diff --git a/llvm/test/Transforms/GlobalOpt/ctor-list-opt.ll b/llvm/test/Transforms/GlobalOpt/ctor-list-opt.ll
index d351be182cebb..68db618e1eef3 100644
--- a/llvm/test/Transforms/GlobalOpt/ctor-list-opt.ll
+++ b/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 @@ define internal void @CTOR13() {
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
+}
+
More information about the llvm-commits
mailing list