[llvm] a56f264 - Refine tls-load-hoista llvm option

Xiang1 Zhang via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 1 04:04:13 PDT 2022


Author: Xiang1 Zhang
Date: 2022-04-01T19:03:58+08:00
New Revision: a56f264958d16519be610b53f84084691c8c85ad

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

LOG: Refine tls-load-hoista llvm option

Reviewed By: LuoYuanke

Differential Revision: https://reviews.llvm.org/D122890

Added: 
    

Modified: 
    llvm/docs/LangRef.rst
    llvm/lib/Transforms/Scalar/TLSVariableHoist.cpp
    llvm/test/CodeGen/X86/tls-loads-control.ll
    llvm/test/CodeGen/X86/tls-loads-control2.ll
    llvm/test/CodeGen/X86/tls-loads-control3.ll

Removed: 
    


################################################################################
diff  --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 4ea7d20955ac8..1a218c0a5c756 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -2125,7 +2125,7 @@ example:
 
 ``"tls-load-hoist"``
     This attribute indicates that the function will try to reduce redundant
-    tls address caculation by hoisting tls variable.
+    tls address calculation by hoisting tls variable.
 
 ``uwtable[(sync|async)]``
     This attribute indicates that the ABI being targeted requires that

diff  --git a/llvm/lib/Transforms/Scalar/TLSVariableHoist.cpp b/llvm/lib/Transforms/Scalar/TLSVariableHoist.cpp
index fdd3953ee685c..2411344c69143 100644
--- a/llvm/lib/Transforms/Scalar/TLSVariableHoist.cpp
+++ b/llvm/lib/Transforms/Scalar/TLSVariableHoist.cpp
@@ -40,16 +40,10 @@ using namespace tlshoist;
 
 #define DEBUG_TYPE "tlshoist"
 
-// TODO: Support "strict" model if we need to strictly load TLS address,
-// because "non-optimize" may also do some optimization in other passes.
-static cl::opt<std::string> TLSLoadHoist(
-    "tls-load-hoist",
-    cl::desc(
-        "hoist the TLS loads in PIC model: "
-        "tls-load-hoist=optimize: Eleminate redundant TLS load(s)."
-        "tls-load-hoist=strict: Strictly load TLS address before every use."
-        "tls-load-hoist=non-optimize: Generally load TLS before use(s)."),
-    cl::init("non-optimize"), cl::Hidden);
+static cl::opt<bool> TLSLoadHoist(
+    "tls-load-hoist", cl::init(false), cl::Hidden,
+    cl::desc("hoist the TLS loads in PIC model to eleminate redundant "
+             "TLS address calculation."));
 
 namespace {
 
@@ -282,8 +276,7 @@ bool TLSVariableHoistPass::runImpl(Function &Fn, DominatorTree &DT,
   if (Fn.hasOptNone())
     return false;
 
-  if (TLSLoadHoist != "optimize" &&
-      !Fn.getAttributes().hasFnAttr("tls-load-hoist"))
+  if (!TLSLoadHoist && !Fn.getAttributes().hasFnAttr("tls-load-hoist"))
     return false;
 
   this->LI = &LI;

diff  --git a/llvm/test/CodeGen/X86/tls-loads-control.ll b/llvm/test/CodeGen/X86/tls-loads-control.ll
index 9090cc283cfec..16c1b86e76051 100644
--- a/llvm/test/CodeGen/X86/tls-loads-control.ll
+++ b/llvm/test/CodeGen/X86/tls-loads-control.ll
@@ -1,4 +1,4 @@
-; RUN: llc -mtriple=x86_64-unknown-unknown -O2 --relocation-model=pic --tls-load-hoist=optimize --stop-after=tlshoist -o - %s | FileCheck %s
+; RUN: llc -mtriple=x86_64-unknown-unknown -O2 --relocation-model=pic --tls-load-hoist=true --stop-after=tlshoist -o - %s | FileCheck %s
 ; RUN: llc -mtriple=x86_64-unknown-unknown -O2 --relocation-model=pic --stop-after=tlshoist -o - %s | FileCheck %s
 
 ; This test come from compiling clang/test/CodeGen/intel/tls_loads.cpp with:

diff  --git a/llvm/test/CodeGen/X86/tls-loads-control2.ll b/llvm/test/CodeGen/X86/tls-loads-control2.ll
index 9124eb737c733..9cb53206de9d8 100644
--- a/llvm/test/CodeGen/X86/tls-loads-control2.ll
+++ b/llvm/test/CodeGen/X86/tls-loads-control2.ll
@@ -1,5 +1,4 @@
-; RUN: opt -S -mtriple=x86_64-unknown-unknown -tlshoist --relocation-model=pic --tls-load-hoist=optimize -o - %s | FileCheck %s --check-prefix=HOIST0
-; RUN: opt -S -mtriple=x86_64-unknown-unknown -tlshoist --relocation-model=pic --tls-load-hoist=non-optimize -o - %s | FileCheck %s --check-prefix=HOIST2
+; RUN: opt -S -mtriple=x86_64-unknown-unknown -tlshoist --relocation-model=pic --tls-load-hoist=true -o - %s | FileCheck %s --check-prefix=HOIST0
 ; RUN: opt -S -mtriple=x86_64-unknown-unknown -tlshoist --relocation-model=pic -o - %s | FileCheck %s --check-prefix=HOIST2
 
 $_ZTW5thl_x = comdat any

diff  --git a/llvm/test/CodeGen/X86/tls-loads-control3.ll b/llvm/test/CodeGen/X86/tls-loads-control3.ll
index 4bf2b566a34ba..852c972ee161a 100644
--- a/llvm/test/CodeGen/X86/tls-loads-control3.ll
+++ b/llvm/test/CodeGen/X86/tls-loads-control3.ll
@@ -1,6 +1,5 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: llc -mtriple=x86_64-unknown-unknown -O2 --relocation-model=pic --tls-load-hoist=optimize -o - %s | FileCheck %s --check-prefix=HOIST0
-; RUN: llc -mtriple=x86_64-unknown-unknown -O2 --relocation-model=pic --tls-load-hoist=non-optimize -o - %s | FileCheck %s --check-prefix=HOIST2
+; RUN: llc -mtriple=x86_64-unknown-unknown -O2 --relocation-model=pic --tls-load-hoist=true -o - %s | FileCheck %s --check-prefix=HOIST0
 ; RUN: llc -mtriple=x86_64-unknown-unknown -O2 --relocation-model=pic -o - %s | FileCheck %s --check-prefix=HOIST2
 
 ; This test has no module flag {"tls-load-hoist", i32 0}, so use --tls-load-hoist=x


        


More information about the llvm-commits mailing list