[llvm] 13ff7d6 - Revert "[GlobalOpt] Perform store->dominated load forwarding for stored once globals"

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 20 10:30:52 PDT 2022


Author: Arthur Eubanks
Date: 2022-06-20T10:26:47-07:00
New Revision: 13ff7d6f393da07c285c710beaa93b6ac3a276fb

URL: https://github.com/llvm/llvm-project/commit/13ff7d6f393da07c285c710beaa93b6ac3a276fb
DIFF: https://github.com/llvm/llvm-project/commit/13ff7d6f393da07c285c710beaa93b6ac3a276fb.diff

LOG: Revert "[GlobalOpt] Perform store->dominated load forwarding for stored once globals"

This reverts commit 6f348b146b69a50d5fb1b9fbfd14bc1d204e45c4.

Am seeing internal test failures plus a linux kernel breakage reported due to this.

Added: 
    

Modified: 
    llvm/lib/Transforms/IPO/GlobalOpt.cpp
    llvm/test/Transforms/GlobalOpt/malloc-promote-1-no-null-opt.ll
    llvm/test/Transforms/GlobalOpt/malloc-promote-2-no-null-opt.ll
    llvm/test/Transforms/GlobalOpt/malloc-promote-3.ll
    llvm/test/Transforms/GlobalOpt/shrink-global-to-bool-check-debug.ll
    llvm/test/Transforms/GlobalOpt/shrink-global-to-bool.ll
    llvm/test/Transforms/GlobalOpt/stored-once-forward-value.ll
    llvm/test/Transforms/PhaseOrdering/recompute-globalsaa.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
index 6ea2242a88cbc..a2b47166cdfc4 100644
--- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -1438,37 +1438,6 @@ static void makeAllConstantUsesInstructions(Constant *C) {
   }
 }
 
-// For a global variable with one store, if the store dominates any loads,
-// those loads will always load the stored value (as opposed to the
-// initializer), even in the presence of recursion.
-static bool forwardStoredOnceStore(
-    GlobalVariable *GV, const StoreInst *StoredOnceStore,
-    function_ref<DominatorTree &(Function &)> LookupDomTree) {
-  const Value *StoredOnceValue = StoredOnceStore->getValueOperand();
-  SmallVector<LoadInst *> Loads;
-  const Function *F = StoredOnceStore->getFunction();
-  for (User *U : GV->users()) {
-    if (auto *LI = dyn_cast<LoadInst>(U)) {
-      if (LI->getFunction() == F &&
-          LI->getType() == StoredOnceValue->getType() && LI->isSimple())
-        Loads.push_back(LI);
-    }
-  }
-  // Only compute DT if we have any loads to examine.
-  bool MadeChange = false;
-  if (!Loads.empty()) {
-    auto &DT = LookupDomTree(*const_cast<Function *>(F));
-    for (auto *LI : Loads) {
-      if (DT.dominates(StoredOnceStore, LI)) {
-        LI->replaceAllUsesWith(const_cast<Value *>(StoredOnceValue));
-        LI->eraseFromParent();
-        MadeChange = true;
-      }
-    }
-  }
-  return MadeChange;
-}
-
 /// Analyze the specified global variable and optimize
 /// it if possible.  If we make a change, return true.
 static bool
@@ -1628,10 +1597,6 @@ processInternalGlobal(GlobalVariable *GV, const GlobalStatus &GS,
     if (optimizeOnceStoredGlobal(GV, StoredOnceValue, DL, GetTLI))
       return true;
 
-    // Try to forward the store to any loads.
-    if (forwardStoredOnceStore(GV, GS.StoredOnceStore, LookupDomTree))
-      return true;
-
     // Otherwise, if the global was not a boolean, we can shrink it to be a
     // boolean. Skip this optimization for AS that doesn't allow an initializer.
     if (SOVConstant && GS.Ordering == AtomicOrdering::NotAtomic &&

diff  --git a/llvm/test/Transforms/GlobalOpt/malloc-promote-1-no-null-opt.ll b/llvm/test/Transforms/GlobalOpt/malloc-promote-1-no-null-opt.ll
index ccda0b8144d87..4cbe837669900 100644
--- a/llvm/test/Transforms/GlobalOpt/malloc-promote-1-no-null-opt.ll
+++ b/llvm/test/Transforms/GlobalOpt/malloc-promote-1-no-null-opt.ll
@@ -12,7 +12,8 @@ define void @init() #0 {
 ; CHECK-NEXT:    [[MALLOCCALL:%.*]] = tail call i8* @malloc(i64 4)
 ; CHECK-NEXT:    [[P:%.*]] = bitcast i8* [[MALLOCCALL]] to i32*
 ; CHECK-NEXT:    store i32* [[P]], i32** @G, align 8
-; CHECK-NEXT:    store i32 0, i32* [[P]], align 4
+; CHECK-NEXT:    [[GV:%.*]] = load i32*, i32** @G, align 8
+; CHECK-NEXT:    store i32 0, i32* [[GV]], align 4
 ; CHECK-NEXT:    ret void
 ;
   %malloccall = tail call i8* @malloc(i64 4)

diff  --git a/llvm/test/Transforms/GlobalOpt/malloc-promote-2-no-null-opt.ll b/llvm/test/Transforms/GlobalOpt/malloc-promote-2-no-null-opt.ll
index 9c17c833a8093..0b31aaf6a2825 100644
--- a/llvm/test/Transforms/GlobalOpt/malloc-promote-2-no-null-opt.ll
+++ b/llvm/test/Transforms/GlobalOpt/malloc-promote-2-no-null-opt.ll
@@ -12,7 +12,8 @@ define void @t() #0 {
 ; CHECK-NEXT:    [[MALLOCCALL:%.*]] = tail call i8* @malloc(i64 400)
 ; CHECK-NEXT:    [[P:%.*]] = bitcast i8* [[MALLOCCALL]] to i32*
 ; CHECK-NEXT:    store i32* [[P]], i32** @G, align 8
-; CHECK-NEXT:    [[GVE:%.*]] = getelementptr i32, i32* [[P]], i32 40
+; CHECK-NEXT:    [[GV:%.*]] = load i32*, i32** @G, align 8
+; CHECK-NEXT:    [[GVE:%.*]] = getelementptr i32, i32* [[GV]], i32 40
 ; CHECK-NEXT:    store i32 20, i32* [[GVE]], align 4
 ; CHECK-NEXT:    ret void
 ;

diff  --git a/llvm/test/Transforms/GlobalOpt/malloc-promote-3.ll b/llvm/test/Transforms/GlobalOpt/malloc-promote-3.ll
index 2a9940296c1cb..fe7b4753dd5cc 100644
--- a/llvm/test/Transforms/GlobalOpt/malloc-promote-3.ll
+++ b/llvm/test/Transforms/GlobalOpt/malloc-promote-3.ll
@@ -12,7 +12,8 @@ define void @t() {
 ; CHECK-NEXT:    [[MALLOCCALL:%.*]] = tail call i8* @malloc(i64 400) #[[ATTR0:[0-9]+]]
 ; CHECK-NEXT:    [[P:%.*]] = bitcast i8* [[MALLOCCALL]] to i32*
 ; CHECK-NEXT:    store i32* [[P]], i32** @G, align 8
-; CHECK-NEXT:    [[GVE:%.*]] = getelementptr i32, i32* [[P]], i32 40
+; CHECK-NEXT:    [[GV:%.*]] = load i32*, i32** @G, align 8
+; CHECK-NEXT:    [[GVE:%.*]] = getelementptr i32, i32* [[GV]], i32 40
 ; CHECK-NEXT:    store i32 20, i32* [[GVE]], align 4
 ; CHECK-NEXT:    ret void
 ;

diff  --git a/llvm/test/Transforms/GlobalOpt/shrink-global-to-bool-check-debug.ll b/llvm/test/Transforms/GlobalOpt/shrink-global-to-bool-check-debug.ll
index 1c917413c6f00..da396363547fd 100644
--- a/llvm/test/Transforms/GlobalOpt/shrink-global-to-bool-check-debug.ll
+++ b/llvm/test/Transforms/GlobalOpt/shrink-global-to-bool-check-debug.ll
@@ -2,24 +2,21 @@
 
 @foo = internal global i32 0, align 4
 
-define void @store() {
+define dso_local i32 @bar() {
 entry:
   store i32 5, i32* @foo, align 4
-  ret void
-}
-
-define i32 @bar() {
-entry:
   %0 = load i32, i32* @foo, align 4
   ret i32 %0
 }
 
 ;CHECK:      @bar
 ;CHECK-NEXT: entry:
+;CHECK-NEXT:   store i1 true, i1* @foo, align 1, !dbg ![[DbgLocStore:[0-9]+]]
 ;CHECK-NEXT:   %.b = load i1, i1* @foo, align 1, !dbg ![[DbgLocLoadSel:[0-9]+]]
 ;CHECK-NEXT:   %0 = select i1 %.b, i32 5, i32 0, !dbg ![[DbgLocLoadSel]]
 ;CHECK-NEXT:   call void @llvm.dbg.value({{.*}}), !dbg ![[DbgLocLoadSel]]
 ;CHECK-NEXT:   ret i32 %0, !dbg ![[DbgLocRet:[0-9]+]]
 
-;CHECK: ![[DbgLocLoadSel]] = !DILocation(line: 3,
-;CHECK: ![[DbgLocRet]] = !DILocation(line: 4,
+;CHECK: ![[DbgLocStore]] = !DILocation(line: 1,
+;CHECK: ![[DbgLocLoadSel]] = !DILocation(line: 2,
+;CHECK: ![[DbgLocRet]] = !DILocation(line: 3,

diff  --git a/llvm/test/Transforms/GlobalOpt/shrink-global-to-bool.ll b/llvm/test/Transforms/GlobalOpt/shrink-global-to-bool.ll
index bdd515bf2e557..74c35466992bf 100644
--- a/llvm/test/Transforms/GlobalOpt/shrink-global-to-bool.ll
+++ b/llvm/test/Transforms/GlobalOpt/shrink-global-to-bool.ll
@@ -10,13 +10,11 @@
 ; Negative test for AS(3). Skip shrink global to bool optimization.
 ; CHECK: @lvar = internal unnamed_addr addrspace(3) global i32 undef
 
-define void @test_global_var(i1 %i) {
+define void @test_global_var() {
 ; CHECK-LABEL: @test_global_var(
 ; CHECK:    store volatile i32 10, i32* undef, align 4
 ;
 entry:
-  br i1 %i, label %bb1, label %exit
-bb1:
   store i32 10, i32* @gvar
   br label %exit
 exit:
@@ -25,15 +23,13 @@ exit:
   ret void
 }
 
-define void @test_lds_var(i1 %i) {
+define void @test_lds_var() {
 ; CHECK-LABEL: @test_lds_var(
 ; CHECK:    store i32 10, i32 addrspace(3)* @lvar, align 4
 ; CHECK:    [[LD:%.*]] = load i32, i32 addrspace(3)* @lvar, align 4
 ; CHECK:    store volatile i32 [[LD]], i32* undef, align 4
 ;
 entry:
-  br i1 %i, label %bb1, label %exit
-bb1:
   store i32 10, i32 addrspace(3)* @lvar
   br label %exit
 exit:

diff  --git a/llvm/test/Transforms/GlobalOpt/stored-once-forward-value.ll b/llvm/test/Transforms/GlobalOpt/stored-once-forward-value.ll
index 33a389176d154..b043a03608a7c 100644
--- a/llvm/test/Transforms/GlobalOpt/stored-once-forward-value.ll
+++ b/llvm/test/Transforms/GlobalOpt/stored-once-forward-value.ll
@@ -12,8 +12,10 @@ declare void @b()
 
 define i1 @dom_const() {
 ; CHECK-LABEL: @dom_const(
+; CHECK-NEXT:    store i1 true, ptr @g1, align 1
 ; CHECK-NEXT:    call void @b()
-; CHECK-NEXT:    ret i1 true
+; CHECK-NEXT:    [[R:%.*]] = load i1, ptr @g1, align 1
+; CHECK-NEXT:    ret i1 [[R]]
 ;
   store i1 true, ptr @g1
   call void @b()
@@ -23,8 +25,10 @@ define i1 @dom_const() {
 
 define i32 @dom_arg(i32 %a) {
 ; CHECK-LABEL: @dom_arg(
+; CHECK-NEXT:    store i32 [[A:%.*]], ptr @g2, align 4
 ; CHECK-NEXT:    call void @b()
-; CHECK-NEXT:    ret i32 [[A:%.*]]
+; CHECK-NEXT:    [[R:%.*]] = load i32, ptr @g2, align 4
+; CHECK-NEXT:    ret i32 [[R]]
 ;
   store i32 %a, ptr @g2
   call void @b()
@@ -70,7 +74,8 @@ define i1 @dom_multiple_function_loads() {
 ; CHECK-LABEL: @dom_multiple_function_loads(
 ; CHECK-NEXT:    store i1 true, ptr @g5, align 1
 ; CHECK-NEXT:    call void @b()
-; CHECK-NEXT:    ret i1 true
+; CHECK-NEXT:    [[R:%.*]] = load i1, ptr @g5, align 1
+; CHECK-NEXT:    ret i1 [[R]]
 ;
   store i1 true, ptr @g5
   call void @b()

diff  --git a/llvm/test/Transforms/PhaseOrdering/recompute-globalsaa.ll b/llvm/test/Transforms/PhaseOrdering/recompute-globalsaa.ll
index f4290c64a773a..3dbddbdb96faa 100644
--- a/llvm/test/Transforms/PhaseOrdering/recompute-globalsaa.ll
+++ b/llvm/test/Transforms/PhaseOrdering/recompute-globalsaa.ll
@@ -9,6 +9,7 @@
 define i32 @main() {
 ; CHECK-LABEL: @main(
 ; CHECK-NEXT:  entry:
+; CHECK-NEXT:    store i1 true, i1* @a, align 4
 ; CHECK-NEXT:    [[TMP0:%.*]] = load i32*, i32** @e, align 8
 ; CHECK-NEXT:    store i32 0, i32* [[TMP0]], align 4
 ; CHECK-NEXT:    store i32* null, i32** @e, align 8


        


More information about the llvm-commits mailing list