[GlobalOpt] Enable evaluation of atomic stores
authorAlexander Shaposhnikov <ashaposhnikov@google.com>
Wed, 20 Jul 2022 22:29:03 +0000 (22:29 +0000)
committerAlexander Shaposhnikov <ashaposhnikov@google.com>
Wed, 20 Jul 2022 22:33:58 +0000 (22:33 +0000)
Relax the check to allow evaluation of atomic stores
(but still skip volatile stores).

Test plan:
1/ ninja check-llvm check-clang
2/ Bootstrapped LLVM/Clang pass tests

Differential revision: https://reviews.llvm.org/D129841

llvm/lib/Transforms/Utils/Evaluator.cpp
llvm/test/Transforms/GlobalOpt/ctor-list-opt.ll

index 7b8d855..3989fbc 100644 (file)
@@ -301,9 +301,9 @@ bool Evaluator::EvaluateBlock(BasicBlock::iterator CurInst, BasicBlock *&NextBB,
     LLVM_DEBUG(dbgs() << "Evaluating Instruction: " << *CurInst << "\n");
 
     if (StoreInst *SI = dyn_cast<StoreInst>(CurInst)) {
-      if (!SI->isSimple()) {
-        LLVM_DEBUG(dbgs() << "Store is not simple! Can not evaluate.\n");
-        return false;  // no volatile/atomic accesses.
+      if (SI->isVolatile()) {
+        LLVM_DEBUG(dbgs() << "Store is volatile! Can not evaluate.\n");
+        return false;  // no volatile accesses.
       }
       Constant *Ptr = getVal(SI->getOperand(1));
       Constant *FoldedPtr = ConstantFoldConstant(Ptr, DL, TLI);
index d039941..d351be1 100644 (file)
@@ -27,6 +27,7 @@
 @Z = global i32 123            ; <i32*> [#uses=1]
 @D = global double 0.000000e+00                ; <double*> [#uses=1]
 @CTORGV = internal global i1 false             ; <i1*> [#uses=2]
+@GA = global i32 0             ; <i32*> [#uses=1]
 
 define internal void @CTOR1() {
        ret void
@@ -130,3 +131,9 @@ define internal void @CTOR11() {
 define internal void @CTOR12() {
        ret void
 }
+
+; CHECK-NOT: CTOR13
+define internal void @CTOR13() {
+  store atomic i32 123, i32* @GA seq_cst, align 4
+  ret void
+}