[llvm-branch-commits] [clang] 56dcb10 - Add Cortex-X1C to Clang LLVM 14 release notes

2022-02-08 Thread Ties Stuij via llvm-branch-commits

Author: Ties Stuij
Date: 2022-02-08T17:49:28Z
New Revision: 56dcb10a9942c206d53a59abd66c2207a01b39fa

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

LOG: Add Cortex-X1C to Clang LLVM 14 release notes

Reviewed By: amilendra

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a58e3fcd4f42c..caa2349f9d860 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -101,6 +101,10 @@ Modified Compiler Flags
   - RISC-V SiFive S51 (``sifive-s51``).
   - RISC-V SiFive S54 (``sifive-s54``).
   - RISC-V SiFive S76 (``sifive-s76``).
+  - Arm Cortex-X1C (``cortex-x1c``)
+  - Arm Cortex-X2 (``cortex-x2``)
+  - Arm Cortex-A510 (``cortex-a510``)
+  - Arm Cortex-A710 (``cortex-a710``)
 
 - Support has been added for the following architectures (``-march`` 
identifiers in parentheses):
 
@@ -283,11 +287,6 @@ DWARF Support in Clang
 Arm and AArch64 Support in Clang
 
 
-- Support has been added for the following processors (command-line 
identifiers in parentheses):
-  - Arm Cortex-A510 (``cortex-a510``)
-  - Arm Cortex-X2 (``cortex-x2``)
-  - Arm Cortex-A710 (``cortex-A710``)
-
 - The -mtune flag is no longer ignored for AArch64. It is now possible to
   tune code generation for a particular CPU with -mtune without setting any
   architectural features. For example, compiling with



___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 54a8365 - Follow up to 6e03a68b776dc, squelch another leak

2022-02-08 Thread Tom Stellard via llvm-branch-commits

Author: Jeremy Morse
Date: 2022-02-08T10:29:17-08:00
New Revision: 54a83652eebad6508fb861847fbb84606f37b502

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

LOG: Follow up to 6e03a68b776dc, squelch another leak

This patch is a sticking-paster until D118774 solves the situation with
unique_ptrs. I'm certainly wishing I'd focused on that first X_X.

(cherry picked from commit 4654fa89eacca375ff860203697982b873bbd7c8)

Added: 


Modified: 
llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp

Removed: 




diff  --git a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp 
b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
index 3b4d717c9ab4a..6af5f07d801ac 100644
--- a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
+++ b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
@@ -2929,8 +2929,15 @@ bool InstrRefBasedLDV::depthFirstVLocAndEmit(
   VTracker = nullptr;
 
   // No scopes? No variable locations.
-  if (!LS.getCurrentFunctionScope())
+  if (!LS.getCurrentFunctionScope()) {
+// FIXME: this is a sticking plaster to prevent a memory leak, these
+// pointers will be automagically freed by being unique pointers, shortly.
+for (unsigned int I = 0; I < MaxNumBlocks; ++I) {
+  delete[] MInLocs[I];
+  delete[] MOutLocs[I];
+}
 return false;
+  }
 
   // Build map from block number to the last scope that uses the block.
   SmallVector EjectionMap;



___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] bf60bae - Revert "[x86] try harder to scalarize a vector load with extracted integer op uses"

2022-02-08 Thread Tom Stellard via llvm-branch-commits

Author: Sanjay Patel
Date: 2022-02-08T10:29:18-08:00
New Revision: bf60baea583e624ca02766e605018e3be9680a42

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

LOG: Revert "[x86] try harder to scalarize a vector load with extracted integer 
op uses"

This reverts commit b4b97ec813a02585000f30ac7d532dda74e8bfda.

As discussed in post-commit feedback at:
https://reviews.llvm.org/D118376
...there's a stage 2 failure on a Mac running a clang-refactor tool test.

(cherry picked from commit 7b03725097872fbd3369a7213c1d98b372aa2d78)

Added: 


Modified: 
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/2011-12-26-extractelement-duplicate-load.ll
llvm/test/CodeGen/X86/avx512-cvt.ll
llvm/test/CodeGen/X86/bitcast-vector-bool.ll
llvm/test/CodeGen/X86/extractelement-load.ll
llvm/test/CodeGen/X86/oddsubvector.ll
llvm/test/CodeGen/X86/pr45378.ll
llvm/test/CodeGen/X86/scalar_widen_div.ll
llvm/test/CodeGen/X86/shrink_vmul.ll
llvm/test/CodeGen/X86/vec_cast.ll
llvm/test/CodeGen/X86/vec_int_to_fp.ll

Removed: 




diff  --git a/llvm/lib/Target/X86/X86ISelLowering.cpp 
b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 90753b5b4d33c..9afb885f582aa 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -43108,38 +43108,6 @@ static SDValue combineExtractVectorElt(SDNode *N, 
SelectionDAG &DAG,
 }
   }
 
-  // If this extract is from a loaded vector value and will be used as an
-  // integer, that requires a potentially expensive XMM -> GPR transfer.
-  // Additionally, if we can convert to a scalar integer load, that will likely
-  // be folded into a subsequent integer op.
-  // Note: Unlike the related fold for this in DAGCombiner, this is not limited
-  //   to a single-use of the loaded vector. For the reasons above, we
-  //   expect this to be profitable even if it creates an extra load.
-  bool LikelyUsedAsVector = any_of(N->uses(), [](SDNode *Use) {
-return Use->getOpcode() == ISD::STORE ||
-   Use->getOpcode() == ISD::INSERT_VECTOR_ELT ||
-   Use->getOpcode() == ISD::SCALAR_TO_VECTOR;
-  });
-  auto *LoadVec = dyn_cast(InputVector);
-  if (LoadVec && CIdx && ISD::isNormalLoad(LoadVec) && VT.isInteger() &&
-  SrcVT.getVectorElementType() == VT && DCI.isAfterLegalizeDAG() &&
-  !LikelyUsedAsVector) {
-const TargetLowering &TLI = DAG.getTargetLoweringInfo();
-SDValue NewPtr =
-TLI.getVectorElementPointer(DAG, LoadVec->getBasePtr(), SrcVT, EltIdx);
-unsigned PtrOff = VT.getSizeInBits() * CIdx->getZExtValue() / 8;
-MachinePointerInfo MPI = LoadVec->getPointerInfo().getWithOffset(PtrOff);
-Align Alignment = commonAlignment(LoadVec->getAlign(), PtrOff);
-SDValue Load =
-DAG.getLoad(VT, dl, LoadVec->getChain(), NewPtr, MPI, Alignment,
-LoadVec->getMemOperand()->getFlags(), 
LoadVec->getAAInfo());
-SDValue Chain = Load.getValue(1);
-SDValue From[] = {SDValue(N, 0), SDValue(LoadVec, 1)};
-SDValue To[] = {Load, Chain};
-DAG.ReplaceAllUsesOfValuesWith(From, To, 2);
-return SDValue(N, 0);
-  }
-
   return SDValue();
 }
 

diff  --git a/llvm/test/CodeGen/X86/2011-12-26-extractelement-duplicate-load.ll 
b/llvm/test/CodeGen/X86/2011-12-26-extractelement-duplicate-load.ll
index 5fb01b8c1b992..ad52d58bde1c6 100644
--- a/llvm/test/CodeGen/X86/2011-12-26-extractelement-duplicate-load.ll
+++ b/llvm/test/CodeGen/X86/2011-12-26-extractelement-duplicate-load.ll
@@ -10,13 +10,13 @@
 define <4 x i32> @test(<4 x i32>* %p) {
 ; CHECK-LABEL: test:
 ; CHECK:   # %bb.0:
-; CHECK-NEXT:cmpl $3, 8(%rdi)
-; CHECK-NEXT:je .LBB0_1
-; CHECK-NEXT:  # %bb.2:
-; CHECK-NEXT:xorps %xmm0, %xmm0
-; CHECK-NEXT:retq
-; CHECK-NEXT:  .LBB0_1:
 ; CHECK-NEXT:movaps (%rdi), %xmm0
+; CHECK-NEXT:extractps $2, %xmm0, %eax
+; CHECK-NEXT:cmpl $3, %eax
+; CHECK-NEXT:je .LBB0_2
+; CHECK-NEXT:  # %bb.1:
+; CHECK-NEXT:xorps %xmm0, %xmm0
+; CHECK-NEXT:  .LBB0_2:
 ; CHECK-NEXT:retq
   %v = load <4 x i32>, <4 x i32>* %p
   %e = extractelement <4 x i32> %v, i32 2

diff  --git a/llvm/test/CodeGen/X86/avx512-cvt.ll 
b/llvm/test/CodeGen/X86/avx512-cvt.ll
index f632db7160e60..5d7940b2fa7ce 100644
--- a/llvm/test/CodeGen/X86/avx512-cvt.ll
+++ b/llvm/test/CodeGen/X86/avx512-cvt.ll
@@ -148,12 +148,18 @@ define <2 x float> @sltof2f32(<2 x i64> %a) {
 define <4 x float> @slto4f32_mem(<4 x i64>* %a) {
 ; NODQ-LABEL: slto4f32_mem:
 ; NODQ:   # %bb.0:
-; NODQ-NEXT:vcvtsi2ssq 8(%rdi), %xmm0, %xmm0
-; NODQ-NEXT:vcvtsi2ssq (%rdi), %xmm1, %xmm1
-; NODQ-NEXT:vinsertps {{.*#+}} xmm0 = xmm1[0],xmm0[0],xmm1[2,3]
-; NODQ-NEXT:vcvtsi2ssq 16(%rdi), %xmm2, %xmm1
-; NODQ-NEXT:vinsertps {{.*#+}} xmm0 =

[llvm-branch-commits] [lldb] dbf2f56 - [lldb] Improve RichManglingContext ergonomics (NFC)

2022-02-08 Thread Tom Stellard via llvm-branch-commits

Author: Jonas Devlieghere
Date: 2022-02-08T10:29:18-08:00
New Revision: dbf2f560947fcf8e7460fea3bfde443fef0eddf7

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

LOG: [lldb] Improve RichManglingContext ergonomics (NFC)

Have the different ::Parse.* methods return the demangled string
directly instead of having to go through ::GetBufferRef.

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

(cherry picked from commit fa52788b7a6da1eab9fec0f2db5f74a8db555196)

Added: 


Modified: 
lldb/include/lldb/Core/RichManglingContext.h
lldb/source/Core/Mangled.cpp
lldb/source/Core/RichManglingContext.cpp
lldb/source/Symbol/Symtab.cpp
lldb/unittests/Core/RichManglingContextTest.cpp

Removed: 




diff  --git a/lldb/include/lldb/Core/RichManglingContext.h 
b/lldb/include/lldb/Core/RichManglingContext.h
index a6b7af8d8d7ec..ecd11e93f044d 100644
--- a/lldb/include/lldb/Core/RichManglingContext.h
+++ b/lldb/include/lldb/Core/RichManglingContext.h
@@ -43,25 +43,15 @@ class RichManglingContext {
   bool IsCtorOrDtor() const;
 
   /// Get the base name of a function. This doesn't include trailing template
-  /// arguments, ie "a::b" gives "b". The result will overwrite the
-  /// internal buffer. It can be obtained via GetBufferRef().
-  void ParseFunctionBaseName();
+  /// arguments, ie "a::b" gives "b".
+  llvm::StringRef ParseFunctionBaseName();
 
   /// Get the context name for a function. For "a::b::c", this function returns
-  /// "a::b". The result will overwrite the internal buffer. It can be obtained
-  /// via GetBufferRef().
-  void ParseFunctionDeclContextName();
-
-  /// Get the entire demangled name. The result will overwrite the internal
-  /// buffer. It can be obtained via GetBufferRef().
-  void ParseFullName();
-
-  /// Obtain a StringRef to the internal buffer that holds the result of the
-  /// most recent ParseXy() operation. The next ParseXy() call invalidates it.
-  llvm::StringRef GetBufferRef() const {
-assert(m_provider != None && "Initialize a provider first");
-return m_buffer;
-  }
+  /// "a::b".
+  llvm::StringRef ParseFunctionDeclContextName();
+
+  /// Get the entire demangled name.
+  llvm::StringRef ParseFullName();
 
 private:
   enum InfoProvider { None, ItaniumPartialDemangler, PluginCxxLanguage };
@@ -69,9 +59,6 @@ class RichManglingContext {
   /// Selects the rich mangling info provider.
   InfoProvider m_provider = None;
 
-  /// Reference to the buffer used for results of ParseXy() operations.
-  llvm::StringRef m_buffer;
-
   /// Members for ItaniumPartialDemangler
   llvm::ItaniumPartialDemangler m_ipd;
   /// Note: m_ipd_buf is a raw pointer due to being resized by realloc via
@@ -93,7 +80,7 @@ class RichManglingContext {
   void ResetProvider(InfoProvider new_provider);
 
   /// Uniform handling of string buffers for ItaniumPartialDemangler.
-  void processIPDStrResult(char *ipd_res, size_t res_len);
+  llvm::StringRef processIPDStrResult(char *ipd_res, size_t res_len);
 
   /// Cast the given parser to the given type. Ideally we would have a type
   /// trait to deduce \a ParserT from a given InfoProvider, but unfortunately 
we

diff  --git a/lldb/source/Core/Mangled.cpp b/lldb/source/Core/Mangled.cpp
index 4e10324401dc0..7af1ad66f5b5a 100644
--- a/lldb/source/Core/Mangled.cpp
+++ b/lldb/source/Core/Mangled.cpp
@@ -217,8 +217,7 @@ bool Mangled::DemangleWithRichManglingInfo(
 if (context.FromItaniumName(m_mangled)) {
   // If we got an info, we have a name. Copy to string pool and connect the
   // counterparts to accelerate later access in GetDemangledName().
-  context.ParseFullName();
-  m_demangled.SetStringWithMangledCounterpart(context.GetBufferRef(),
+  m_demangled.SetStringWithMangledCounterpart(context.ParseFullName(),
   m_mangled);
   return true;
 } else {

diff  --git a/lldb/source/Core/RichManglingContext.cpp 
b/lldb/source/Core/RichManglingContext.cpp
index 63170feb6231c..cecb5c6a2e548 100644
--- a/lldb/source/Core/RichManglingContext.cpp
+++ b/lldb/source/Core/RichManglingContext.cpp
@@ -83,15 +83,15 @@ bool RichManglingContext::IsCtorOrDtor() const {
   llvm_unreachable("Fully covered switch above!");
 }
 
-void RichManglingContext::processIPDStrResult(char *ipd_res, size_t res_size) {
+llvm::StringRef RichManglingContext::processIPDStrResult(char *ipd_res,
+ size_t res_size) {
   // Error case: Clear the buffer.
   if (LLVM_UNLIKELY(ipd_res == nullptr)) {
 assert(res_size == m_ipd_buf_size &&
"Failed IPD queries keep the original size in the N parameter");
 
 m_ipd_buf[0] = '\0';
-m_buffer = llvm::StringRef(m_ipd_buf, 0);
-return;
+return

[llvm-branch-commits] [lldb] bee0279 - [lldb] Don't construct the demangled strings while indexing the symbol table

2022-02-08 Thread Tom Stellard via llvm-branch-commits

Author: Jonas Devlieghere
Date: 2022-02-08T10:29:18-08:00
New Revision: bee0279abedae908e344d740d5e95f4bc5e5557e

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

LOG: [lldb] Don't construct the demangled strings while indexing the symbol 
table

The symbol table needs to demangle all symbol names when building its
index. However, this doesn't require the full mangled name: we only need
the base name and the function declaration context. Currently, we always
construct the demangled string during indexing and cache it in the
string pool as a way to speed up future lookups.

Constructing the demangled string is by far the most expensive step of
the demangling process, because the output string can be exponentially
larger than the input and unless you're dumping the symbol table, many
of those demangled names will not be needed again.

This patch avoids constructing the full demangled string when we can
partially demangle. This speeds up indexing and reduces memory usage.

I gathered some numbers by attaching to Slack:

Before
--

  Memory usage: 280MB
  Benchmark 1: ./bin/lldb -n Slack -o quit
Time (mean ± σ):  4.829 s ±  0.518 s[User: 4.012 s, System: 0.208 s]
Range (min … max):4.624 s …  6.294 s10 runs

After
-

  Memory usage: 189MB
  Benchmark 1: ./bin/lldb -n Slack -o quit
Time (mean ± σ):  4.182 s ±  0.025 s[User: 3.536 s, System: 0.192 s]
Range (min … max):4.152 s …  4.233 s10 runs

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

(cherry picked from commit aed965d55d460ebcc2b442b9d799b4c1ab929157)

Added: 


Modified: 
lldb/source/Core/Mangled.cpp
lldb/source/Symbol/Symtab.cpp
lldb/test/API/macosx/dyld-trie-symbols/TestDyldTrieSymbols.py

Removed: 




diff  --git a/lldb/source/Core/Mangled.cpp b/lldb/source/Core/Mangled.cpp
index 7af1ad66f5b5a..14d170b61366e 100644
--- a/lldb/source/Core/Mangled.cpp
+++ b/lldb/source/Core/Mangled.cpp
@@ -214,24 +214,16 @@ bool Mangled::DemangleWithRichManglingInfo(
   case eManglingSchemeItanium:
 // We want the rich mangling info here, so we don't care whether or not
 // there is a demangled string in the pool already.
-if (context.FromItaniumName(m_mangled)) {
-  // If we got an info, we have a name. Copy to string pool and connect the
-  // counterparts to accelerate later access in GetDemangledName().
-  m_demangled.SetStringWithMangledCounterpart(context.ParseFullName(),
-  m_mangled);
-  return true;
-} else {
-  m_demangled.SetCString("");
-  return false;
-}
+return context.FromItaniumName(m_mangled);
 
   case eManglingSchemeMSVC: {
 // We have no rich mangling for MSVC-mangled names yet, so first try to
 // demangle it if necessary.
 if (!m_demangled && !m_mangled.GetMangledCounterpart(m_demangled)) {
   if (char *d = GetMSVCDemangledStr(m_mangled.GetCString())) {
-// If we got an info, we have a name. Copy to string pool and connect
-// the counterparts to accelerate later access in GetDemangledName().
+// Without the rich mangling info we have to demangle the full name.
+// Copy it to string pool and connect the counterparts to accelerate
+// later access in GetDemangledName().
 m_demangled.SetStringWithMangledCounterpart(llvm::StringRef(d),
 m_mangled);
 ::free(d);

diff  --git a/lldb/source/Symbol/Symtab.cpp b/lldb/source/Symbol/Symtab.cpp
index 765e7bc9520fd..436f97e623819 100644
--- a/lldb/source/Symbol/Symtab.cpp
+++ b/lldb/source/Symbol/Symtab.cpp
@@ -328,8 +328,10 @@ void Symtab::InitNameIndexes() {
 
 const SymbolType type = symbol->GetType();
 if (type == eSymbolTypeCode || type == eSymbolTypeResolver) {
-  if (mangled.DemangleWithRichManglingInfo(rmc, lldb_skip_name))
+  if (mangled.DemangleWithRichManglingInfo(rmc, lldb_skip_name)) {
 RegisterMangledNameEntry(value, class_contexts, backlog, rmc);
+continue;
+  }
 }
   }
 

diff  --git a/lldb/test/API/macosx/dyld-trie-symbols/TestDyldTrieSymbols.py 
b/lldb/test/API/macosx/dyld-trie-symbols/TestDyldTrieSymbols.py
index 3455f21392dc4..6f2f1c5b7cee4 100644
--- a/lldb/test/API/macosx/dyld-trie-symbols/TestDyldTrieSymbols.py
+++ b/lldb/test/API/macosx/dyld-trie-symbols/TestDyldTrieSymbols.py
@@ -43,8 +43,6 @@ def test_dyld_trie_symbols(self):
 self.assertEqual(unstripped_Z3pat_symbols.GetSize(), 1)
 unstripped_pat_symbols = unstripped_target.FindSymbols("pat")
 self.assertEqual(unstripped_pat_symbols.GetSize(), 1)
-unstripped_patint_symbols = unstripped_target.FindSymbols("pat(i

[llvm-branch-commits] [lldb] 39b1d3d - [lldb] Rename DemangleWithRichManglingInfo to GetRichManglingInfo (NFC)

2022-02-08 Thread Tom Stellard via llvm-branch-commits

Author: Jonas Devlieghere
Date: 2022-02-08T10:29:18-08:00
New Revision: 39b1d3d27ae3d0355e3b10789d63bf1e645b3d1d

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

LOG: [lldb] Rename DemangleWithRichManglingInfo to GetRichManglingInfo (NFC)

This addresses Pavel's comment from D118814.

(cherry picked from commit edbb0f6df76b04100357c7c9438f3b5b978e0200)

Added: 


Modified: 
lldb/include/lldb/Core/Mangled.h
lldb/source/Core/Mangled.cpp
lldb/source/Symbol/Symtab.cpp

Removed: 




diff  --git a/lldb/include/lldb/Core/Mangled.h 
b/lldb/include/lldb/Core/Mangled.h
index 4e4f75e18e34d..aaefb69f017bc 100644
--- a/lldb/include/lldb/Core/Mangled.h
+++ b/lldb/include/lldb/Core/Mangled.h
@@ -226,10 +226,9 @@ class Mangled {
   /// Function signature for filtering mangled names.
   using SkipMangledNameFn = bool(llvm::StringRef, ManglingScheme);
 
-  /// Trigger explicit demangling to obtain rich mangling information. This is
-  /// optimized for batch processing while populating a name index. To get the
-  /// pure demangled name string for a single entity, use GetDemangledName()
-  /// instead.
+  /// Get rich mangling information. This is optimized for batch processing
+  /// while populating a name index. To get the pure demangled name string for
+  /// a single entity, use GetDemangledName() instead.
   ///
   /// For names that match the Itanium mangling scheme, this uses LLVM's
   /// ItaniumPartialDemangler. All other names fall back to LLDB's builtin
@@ -248,8 +247,8 @@ class Mangled {
   ///
   /// \return
   /// True on success, false otherwise.
-  bool DemangleWithRichManglingInfo(RichManglingContext &context,
-SkipMangledNameFn *skip_mangled_name);
+  bool GetRichManglingInfo(RichManglingContext &context,
+   SkipMangledNameFn *skip_mangled_name);
 
   /// Try to identify the mangling scheme used.
   /// \param[in] name

diff  --git a/lldb/source/Core/Mangled.cpp b/lldb/source/Core/Mangled.cpp
index 14d170b61366e..b8e405544b332 100644
--- a/lldb/source/Core/Mangled.cpp
+++ b/lldb/source/Core/Mangled.cpp
@@ -195,8 +195,8 @@ static char *GetDLangDemangledStr(const char *M) {
 
 // Explicit demangling for scheduled requests during batch processing. This
 // makes use of ItaniumPartialDemangler's rich demangle info
-bool Mangled::DemangleWithRichManglingInfo(
-RichManglingContext &context, SkipMangledNameFn *skip_mangled_name) {
+bool Mangled::GetRichManglingInfo(RichManglingContext &context,
+  SkipMangledNameFn *skip_mangled_name) {
   // Others are not meant to arrive here. ObjC names or C's main() for example
   // have their names stored in m_demangled, while m_mangled is empty.
   assert(m_mangled);

diff  --git a/lldb/source/Symbol/Symtab.cpp b/lldb/source/Symbol/Symtab.cpp
index 436f97e623819..d148706003adf 100644
--- a/lldb/source/Symbol/Symtab.cpp
+++ b/lldb/source/Symbol/Symtab.cpp
@@ -328,7 +328,7 @@ void Symtab::InitNameIndexes() {
 
 const SymbolType type = symbol->GetType();
 if (type == eSymbolTypeCode || type == eSymbolTypeResolver) {
-  if (mangled.DemangleWithRichManglingInfo(rmc, lldb_skip_name)) {
+  if (mangled.GetRichManglingInfo(rmc, lldb_skip_name)) {
 RegisterMangledNameEntry(value, class_contexts, backlog, rmc);
 continue;
   }



___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lldb] 47ea1e1 - [lldb] Use mangled symbol name to look for __asan::AsanDie()

2022-02-08 Thread Tom Stellard via llvm-branch-commits

Author: Jonas Devlieghere
Date: 2022-02-08T10:29:18-08:00
New Revision: 47ea1e198cec19da30fd3e63b4452147696fb388

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

LOG: [lldb] Use mangled symbol name to look for __asan::AsanDie()

After aed965d we no longer demangle full symbol names while indexing the
symbol table which means we have to use the mangled name instead of the
demangled name to find the symbol for __asan::AsanDie().

This fixes the following two tests:

  lldb-api :: functionalities/asan/TestMemoryHistory.py
  lldb-api :: functionalities/asan/TestReportData.py

(cherry picked from commit ef3fade14b32c20e0a35b8fca30e7d2f20e0c983)

Added: 


Modified: 

lldb/source/Plugins/InstrumentationRuntime/ASan/InstrumentationRuntimeASan.cpp

Removed: 




diff  --git 
a/lldb/source/Plugins/InstrumentationRuntime/ASan/InstrumentationRuntimeASan.cpp
 
b/lldb/source/Plugins/InstrumentationRuntime/ASan/InstrumentationRuntimeASan.cpp
index 8d8b5c68e41b3..33b2b5dd51559 100644
--- 
a/lldb/source/Plugins/InstrumentationRuntime/ASan/InstrumentationRuntimeASan.cpp
+++ 
b/lldb/source/Plugins/InstrumentationRuntime/ASan/InstrumentationRuntimeASan.cpp
@@ -281,7 +281,7 @@ void InstrumentationRuntimeASan::Activate() {
   if (!process_sp)
 return;
 
-  ConstString symbol_name("__asan::AsanDie()");
+  ConstString symbol_name("_ZN6__asanL7AsanDieEv");
   const Symbol *symbol = GetRuntimeModuleSP()->FindFirstSymbolWithNameAndType(
   symbol_name, eSymbolTypeCode);
 



___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] 39e9a64 - [clang-format] Fix DefSeparator empty line issues

2022-02-08 Thread Tom Stellard via llvm-branch-commits

Author: ksyx
Date: 2022-02-08T10:29:18-08:00
New Revision: 39e9a64cf5847935c2ba0099f4bf39945d8ee19b

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

LOG: [clang-format] Fix DefSeparator empty line issues

- Add or remove empty lines surrounding union blocks.
- Fixes https://github.com/llvm/llvm-project/issues/53229, in which
  keywords like class and struct in a line ending with left brace or
  whose next line is left brace only, will be falsely recognized as
  definition line, causing extra empty lines inserted surrounding blocks
  with no need to be formatted.

Reviewed By: MyDeveloperDay, curdeius, HazardyKnusperkeks, owenpan
Differential Revision: https://reviews.llvm.org/D119067

(cherry picked from commit a70549ae43dfa551f3eacdfa7a7f2c0df073be8e)

Added: 


Modified: 
clang/lib/Format/DefinitionBlockSeparator.cpp
clang/unittests/Format/DefinitionBlockSeparatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/DefinitionBlockSeparator.cpp 
b/clang/lib/Format/DefinitionBlockSeparator.cpp
index 827564357f788..cfb019a471dce 100644
--- a/clang/lib/Format/DefinitionBlockSeparator.cpp
+++ b/clang/lib/Format/DefinitionBlockSeparator.cpp
@@ -35,19 +35,31 @@ void DefinitionBlockSeparator::separateBlocks(
   const bool IsNeverStyle =
   Style.SeparateDefinitionBlocks == FormatStyle::SDS_Never;
   const AdditionalKeywords &ExtraKeywords = Tokens.getKeywords();
-  auto LikelyDefinition = [this, ExtraKeywords](const AnnotatedLine *Line,
-bool ExcludeEnum = false) {
+  auto GetBracketLevelChange = [](const FormatToken *Tok) {
+if (Tok->isOneOf(tok::l_brace, tok::l_paren, tok::l_square))
+  return 1;
+if (Tok->isOneOf(tok::r_brace, tok::r_paren, tok::r_square))
+  return -1;
+return 0;
+  };
+  auto LikelyDefinition = [&](const AnnotatedLine *Line,
+  bool ExcludeEnum = false) {
 if ((Line->MightBeFunctionDecl && Line->mightBeFunctionDefinition()) ||
 Line->startsWithNamespace())
   return true;
-FormatToken *CurrentToken = Line->First;
-while (CurrentToken) {
-  if (CurrentToken->isOneOf(tok::kw_class, tok::kw_struct) ||
-  (Style.isJavaScript() && 
CurrentToken->is(ExtraKeywords.kw_function)))
-return true;
-  if (!ExcludeEnum && CurrentToken->is(tok::kw_enum))
-return true;
-  CurrentToken = CurrentToken->Next;
+int BracketLevel = 0;
+for (const FormatToken *CurrentToken = Line->First; CurrentToken;
+ CurrentToken = CurrentToken->Next) {
+  if (BracketLevel == 0) {
+if ((CurrentToken->isOneOf(tok::kw_class, tok::kw_struct,
+   tok::kw_union) ||
+ (Style.isJavaScript() &&
+  CurrentToken->is(ExtraKeywords.kw_function
+  return true;
+if (!ExcludeEnum && CurrentToken->is(tok::kw_enum))
+  return true;
+  }
+  BracketLevel += GetBracketLevelChange(CurrentToken);
 }
 return false;
   };
@@ -102,14 +114,17 @@ void DefinitionBlockSeparator::separateBlocks(
  IsPPConditional(OpeningLineIndex - 1);
 };
 const auto HasEnumOnLine = [&]() {
-  FormatToken *CurrentToken = CurrentLine->First;
   bool FoundEnumKeyword = false;
-  while (CurrentToken) {
-if (CurrentToken->is(tok::kw_enum))
-  FoundEnumKeyword = true;
-else if (FoundEnumKeyword && CurrentToken->is(tok::l_brace))
-  return true;
-CurrentToken = CurrentToken->Next;
+  int BracketLevel = 0;
+  for (const FormatToken *CurrentToken = CurrentLine->First; CurrentToken;
+   CurrentToken = CurrentToken->Next) {
+if (BracketLevel == 0) {
+  if (CurrentToken->is(tok::kw_enum))
+FoundEnumKeyword = true;
+  else if (FoundEnumKeyword && CurrentToken->is(tok::l_brace))
+return true;
+}
+BracketLevel += GetBracketLevelChange(CurrentToken);
   }
   return FoundEnumKeyword && I + 1 < Lines.size() &&
  Lines[I + 1]->First->is(tok::l_brace);

diff  --git a/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp 
b/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
index 4cbae0f55b036..582b62e445df9 100644
--- a/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
+++ b/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
@@ -109,6 +109,15 @@ TEST_F(DefinitionBlockSeparatorTest, Basic) {
"};",
Style);
 
+  verifyFormat("union foo {\n"
+   "  int i, j;\n"
+   "};\n"
+   "\n"
+   "union bar {\n"
+   "  int j, k;\n"
+   "};",
+   Style);
+
   verifyFormat("class foo {\n"
 

[llvm-branch-commits] [openmp] 3e2d79e - [Libomptarget] Replace Value RAII with default value

2022-02-08 Thread via llvm-branch-commits

Author: Joseph Huber
Date: 2022-02-08T21:40:03+03:00
New Revision: 3e2d79e2a27dce5f8ba1d33bbc1344b9d24f2b5a

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

LOG: [Libomptarget] Replace Value RAII with default value

This patch replaces the ValueRAII pointer with a default 'nullptr'
value. Previously this was initialized as a reference to an existing
variable. The use of this variable caused overhead as the compiler could
not look through the uses and determine that it was unused if 'Active'
was not set. Because of this accesses to the variable would be left in
the runtime once compiled.

Fixes #53641

Reviewed By: jdoerfert

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

(cherry picked from commit d28051c4ab44141d7c52902de500dfe1293d3de2)

Added: 


Modified: 
openmp/libomptarget/DeviceRTL/include/State.h

Removed: 




diff  --git a/openmp/libomptarget/DeviceRTL/include/State.h 
b/openmp/libomptarget/DeviceRTL/include/State.h
index 3365b054b4720..2f9cbd4c9ca6e 100644
--- a/openmp/libomptarget/DeviceRTL/include/State.h
+++ b/openmp/libomptarget/DeviceRTL/include/State.h
@@ -124,20 +124,21 @@ template  struct PtrValue {
 
 template  struct ValueRAII {
   ValueRAII(VTy &V, Ty NewValue, Ty OldValue, bool Active, IdentTy *Ident)
-  : Ptr(Active ? V.lookup(/* IsReadonly */ false, Ident) : Val),
+  : Ptr(Active ? &V.lookup(/* IsReadonly */ false, Ident) : nullptr),
 Val(OldValue), Active(Active) {
 if (!Active)
   return;
-ASSERT(Ptr == OldValue && "ValueRAII initialization with wrong old 
value!");
-Ptr = NewValue;
+ASSERT(*Ptr == OldValue &&
+   "ValueRAII initialization with wrong old value!");
+*Ptr = NewValue;
   }
   ~ValueRAII() {
 if (Active)
-  Ptr = Val;
+  *Ptr = Val;
   }
 
 private:
-  Ty &Ptr;
+  Ty *Ptr;
   Ty Val;
   bool Active;
 };



___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] 26cc50a - [OpenMP] Add Cuda path to linker wrapper tool

2022-02-08 Thread via llvm-branch-commits

Author: Joseph Huber
Date: 2022-02-08T21:39:11+03:00
New Revision: 26cc50aba7176996d50780a5f7957d7822065ae9

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

LOG: [OpenMP] Add Cuda path to linker wrapper tool

The linker wrapper tool uses the 'nvlink' and 'ptxas' binaries to link
and assemble device files. Previously we searched for this using the
binaries in the user's path. This didn't work in cases where the user
passed in a specific Cuda path to Clang. This patch changes the linker
wrapper to accept an argument for the Cuda path we can get from Clang.
This should fix #53573.

Reviewed By: tianshilei1992

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

(cherry picked from commit 8cc4ca95b02bc5b5b668b3d537b45a6585575cba)

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 7aac977209eba..5b2984ea2496f 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -8148,11 +8148,25 @@ void LinkerWrapper::ConstructJob(Compilation &C, const 
JobAction &JA,
  const InputInfoList &Inputs,
  const ArgList &Args,
  const char *LinkingOutput) const {
+  const Driver &D = getToolChain().getDriver();
+  const llvm::Triple TheTriple = getToolChain().getTriple();
+  auto OpenMPTCRange = C.getOffloadToolChains();
   ArgStringList CmdArgs;
 
-  if (getToolChain().getDriver().isUsingLTO(/* IsOffload */ true)) {
+  // Pass the CUDA path to the linker wrapper tool.
+  for (auto &I : llvm::make_range(OpenMPTCRange.first, OpenMPTCRange.second)) {
+const ToolChain *TC = I.second;
+if (TC->getTriple().isNVPTX()) {
+  CudaInstallationDetector CudaInstallation(D, TheTriple, Args);
+  if (CudaInstallation.isValid())
+CmdArgs.push_back(Args.MakeArgString(
+"--cuda-path=" + CudaInstallation.getInstallPath()));
+  break;
+}
+  }
+
+  if (D.isUsingLTO(/* IsOffload */ true)) {
 // Pass in target features for each toolchain.
-auto OpenMPTCRange = C.getOffloadToolChains();
 for (auto &I :
  llvm::make_range(OpenMPTCRange.first, OpenMPTCRange.second)) {
   const ToolChain *TC = I.second;
@@ -8165,9 +8179,10 @@ void LinkerWrapper::ConstructJob(Compilation &C, const 
JobAction &JA,
 }
 
 // Pass in the bitcode library to be linked during LTO.
-for (auto &I : llvm::make_range(OpenMPTCRange.first, 
OpenMPTCRange.second)) {
+for (auto &I :
+ llvm::make_range(OpenMPTCRange.first, OpenMPTCRange.second)) {
   const ToolChain *TC = I.second;
-  const Driver &D = TC->getDriver();
+  const Driver &TCDriver = TC->getDriver();
   const ArgList &TCArgs = C.getArgsForToolChain(TC, "", 
Action::OFK_OpenMP);
   StringRef Arch = TCArgs.getLastArgValue(options::OPT_march_EQ);
 
@@ -8182,7 +8197,7 @@ void LinkerWrapper::ConstructJob(Compilation &C, const 
JobAction &JA,
   BitcodeSuffix += Arch;
 
   ArgStringList BitcodeLibrary;
-  addOpenMPDeviceRTL(D, TCArgs, BitcodeLibrary, BitcodeSuffix,
+  addOpenMPDeviceRTL(TCDriver, TCArgs, BitcodeLibrary, BitcodeSuffix,
  TC->getTriple());
 
   if (!BitcodeLibrary.empty())
@@ -8210,12 +8225,8 @@ void LinkerWrapper::ConstructJob(Compilation &C, const 
JobAction &JA,
 }
   }
 
-  // Construct the link job so we can wrap around it.
-  Linker->ConstructJob(C, JA, Output, Inputs, Args, LinkingOutput);
-  const auto &LinkCommand = C.getJobs().getJobs().back();
-
   CmdArgs.push_back("-host-triple");
-  CmdArgs.push_back(Args.MakeArgString(getToolChain().getTripleString()));
+  CmdArgs.push_back(Args.MakeArgString(TheTriple.getTriple()));
   if (Args.hasArg(options::OPT_v))
 CmdArgs.push_back("-v");
 
@@ -8246,6 +8257,10 @@ void LinkerWrapper::ConstructJob(Compilation &C, const 
JobAction &JA,
   if (Args.getLastArg(options::OPT_save_temps_EQ))
 CmdArgs.push_back("-save-temps");
 
+  // Construct the link job so we can wrap around it.
+  Linker->ConstructJob(C, JA, Output, Inputs, Args, LinkingOutput);
+  const auto &LinkCommand = C.getJobs().getJobs().back();
+
   // Add the linker arguments to be forwarded by the wrapper.
   CmdArgs.push_back("-linker-path");
   CmdArgs.push_back(LinkCommand->getExecutable());

diff  --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 4ec4d6b134049..de0af187731d3 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -99,8 

[llvm-branch-commits] [compiler-rt] 7cfe202 - [sanitizer] Use _thread_db_sizeof_pthread to obtain struct pthread size

2022-02-08 Thread Fangrui Song via llvm-branch-commits

Author: Florian Weimer
Date: 2022-02-08T14:03:40-08:00
New Revision: 7cfe202a679a0c3cd5aa71ec2497885ef596ea7b

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

LOG: [sanitizer] Use _thread_db_sizeof_pthread to obtain struct pthread size

This symbol has been exported (as an internal GLIBC_PRIVATE symbol) from 
libc.so.6 starting with glibc 2.34. glibc uses it internally for its 
libthread_db implementation to enable thread debugging on GDB, so it is 
unlikely to go away for now.

Fixes #52989.

Reviewed By: #sanitizers, MaskRay, vitalybuka

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

(cherry picked from commit ef14b78d9a144ba81ba02083fe21eb286a88732b)

Added: 


Modified: 
compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp

Removed: 




diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp 
b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
index b025a5e4fb644..eeb157d1c4280 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
@@ -220,10 +220,8 @@ void InitTlsSize() { }
 // sizeof(struct pthread) from glibc.
 static atomic_uintptr_t thread_descriptor_size;
 
-uptr ThreadDescriptorSize() {
-  uptr val = atomic_load_relaxed(&thread_descriptor_size);
-  if (val)
-return val;
+static uptr ThreadDescriptorSizeFallback() {
+  uptr val = 0;
 #if defined(__x86_64__) || defined(__i386__) || defined(__arm__)
   int major;
   int minor;
@@ -285,8 +283,21 @@ uptr ThreadDescriptorSize() {
 #elif defined(__powerpc64__)
   val = 1776; // from glibc.ppc64le 2.20-8.fc21
 #endif
+  return val;
+}
+
+uptr ThreadDescriptorSize() {
+  uptr val = atomic_load_relaxed(&thread_descriptor_size);
   if (val)
-atomic_store_relaxed(&thread_descriptor_size, val);
+return val;
+  // _thread_db_sizeof_pthread is a GLIBC_PRIVATE symbol that is exported in
+  // glibc 2.34 and later.
+  if (unsigned *psizeof = static_cast(
+  dlsym(RTLD_DEFAULT, "_thread_db_sizeof_pthread")))
+val = *psizeof;
+  if (!val)
+val = ThreadDescriptorSizeFallback();
+  atomic_store_relaxed(&thread_descriptor_size, val);
   return val;
 }
 



___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [compiler-rt] 0ad6c09 - [sanitizer] Guard the whole ThreadDescriptorSize block with #if !SANITIZER_GO after D119007

2022-02-08 Thread Fangrui Song via llvm-branch-commits

Author: Fangrui Song
Date: 2022-02-08T14:50:13-08:00
New Revision: 0ad6c094176e3978b3042b2f0860f273b87e7a85

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

LOG: [sanitizer] Guard the whole ThreadDescriptorSize block with #if 
!SANITIZER_GO after D119007

The SANITIZER_GO code path reports an undefined symbol error for dlsym.

```
FAILED: projects/compiler-rt/lib/tsan/rtl/CMakeFiles/GotsanRuntimeCheck 
/tmp/RelA/projects/compiler-rt/lib/tsan/rtl/CMakeFiles/GotsanRuntimeCheck
```

(cherry picked from commit f0cdacd99bd41dbd778099dfe303ba92660826b3)

Added: 


Modified: 
compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp

Removed: 




diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp 
b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
index eeb157d1c428..4ccd2e828108 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
@@ -216,7 +216,7 @@ void InitTlsSize() { }
 // On glibc x86_64, ThreadDescriptorSize() needs to be precise due to the usage
 // of g_tls_size. On other targets, ThreadDescriptorSize() is only used by lsan
 // to get the pointer to thread-specific data keys in the thread control block.
-#if (SANITIZER_FREEBSD || SANITIZER_LINUX) && !SANITIZER_ANDROID
+#if (SANITIZER_FREEBSD || SANITIZER_LINUX) && !SANITIZER_ANDROID && 
!SANITIZER_GO
 // sizeof(struct pthread) from glibc.
 static atomic_uintptr_t thread_descriptor_size;
 
@@ -319,7 +319,6 @@ static uptr TlsPreTcbSize() {
 }
 #endif
 
-#if !SANITIZER_GO
 namespace {
 struct TlsBlock {
   uptr begin, end, align;
@@ -407,9 +406,8 @@ __attribute__((unused)) static void 
GetStaticTlsBoundary(uptr *addr, uptr *size,
   *addr = ranges[l].begin;
   *size = ranges[r - 1].end - ranges[l].begin;
 }
-#endif  // !SANITIZER_GO
 #endif  // (x86_64 || i386 || mips || ...) && (SANITIZER_FREEBSD ||
-// SANITIZER_LINUX) && !SANITIZER_ANDROID
+// SANITIZER_LINUX) && !SANITIZER_ANDROID && !SANITIZER_GO
 
 #if SANITIZER_NETBSD
 static struct tls_tcb * ThreadSelfTlsTcb() {



___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] 241275a - Revert "[Clang] Propagate guaranteed alignment for malloc and others"

2022-02-08 Thread James Y Knight via llvm-branch-commits

Author: James Y Knight
Date: 2022-02-08T17:16:19-05:00
New Revision: 241275a01ed88cd59d503449a8c74a3b7cfedbb2

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

LOG: Revert "[Clang] Propagate guaranteed alignment for malloc and others"

The above change assumed that malloc (and friends) would always
allocate memory to getNewAlign(), even for allocations which have a
smaller size. This is not actually required by spec (a 1-byte
allocation may validly have 1-byte alignment).

Some real-world malloc implementations do not provide this guarantee,
and thus this optimization is breaking programs.

Fixes #53540

This reverts commit c2297544c04764237cedc523083c7be2fb3833d4.

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

(cherry picked from commit 9545976ff160e19805a84a06a7e59d446f9994d9)

Added: 


Modified: 
clang/include/clang/Basic/TargetInfo.h
clang/lib/Sema/SemaDecl.cpp
clang/test/CodeGen/alloc-fns-alignment.c

Removed: 




diff  --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index a49342a34f3e8..e7db877f4e2bc 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -644,8 +644,8 @@ class TargetInfo : public virtual TransferrableTargetInfo,
   }
 
   /// Return the largest alignment for which a suitably-sized allocation with
-  /// '::operator new(size_t)' or 'malloc' is guaranteed to produce a
-  /// correctly-aligned pointer.
+  /// '::operator new(size_t)' is guaranteed to produce a correctly-aligned
+  /// pointer.
   unsigned getNewAlign() const {
 return NewAlign ? NewAlign : std::max(LongDoubleAlign, LongLongAlign);
   }

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index cbd9df4d6a7b7..bcadf4139046c 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -15319,24 +15319,7 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl 
*FD) {
   if (!FD->hasAttr())
 FD->addAttr(AllocAlignAttr::CreateImplicit(Context, ParamIdx(1, FD),
FD->getLocation()));
-  LLVM_FALLTHROUGH;
-case Builtin::BIcalloc:
-case Builtin::BImalloc:
-case Builtin::BImemalign:
-case Builtin::BIrealloc:
-case Builtin::BIstrdup:
-case Builtin::BIstrndup: {
-  if (!FD->hasAttr()) {
-unsigned NewAlign = Context.getTargetInfo().getNewAlign() /
-Context.getTargetInfo().getCharWidth();
-IntegerLiteral *Alignment = IntegerLiteral::Create(
-Context, Context.MakeIntValue(NewAlign, Context.UnsignedIntTy),
-Context.UnsignedIntTy, FD->getLocation());
-FD->addAttr(AssumeAlignedAttr::CreateImplicit(
-Context, Alignment, /*Offset=*/nullptr, FD->getLocation()));
-  }
   break;
-}
 default:
   break;
 }

diff  --git a/clang/test/CodeGen/alloc-fns-alignment.c 
b/clang/test/CodeGen/alloc-fns-alignment.c
index 8ab0610accf03..31dc9bb2d759d 100644
--- a/clang/test/CodeGen/alloc-fns-alignment.c
+++ b/clang/test/CodeGen/alloc-fns-alignment.c
@@ -1,11 +1,9 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm < %s | 
FileCheck %s --check-prefix=ALIGN16
-// RUN: %clang_cc1 -triple x86_64-windows-msvc  -emit-llvm < %s | 
FileCheck %s --check-prefix=ALIGN16
-// RUN: %clang_cc1 -triple i386-apple-darwin-emit-llvm < %s | 
FileCheck %s --check-prefix=ALIGN16
-// RUN: %clang_cc1 -triple i386-unknown-linux-gnu   -emit-llvm < %s | 
FileCheck %s --check-prefix=ALIGN8
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-malloc  
-emit-llvm < %s  | FileCheck %s --check-prefix=NOBUILTIN-MALLOC
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-calloc  
-emit-llvm < %s  | FileCheck %s --check-prefix=NOBUILTIN-CALLOC
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-realloc 
-emit-llvm < %s  | FileCheck %s --check-prefix=NOBUILTIN-REALLOC
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-aligned_alloc 
-emit-llvm < %s  | FileCheck %s --check-prefix=NOBUILTIN-ALIGNED_ALLOC
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm < %s | 
FileCheck %s
+
+// Note: this test originally asserted that malloc/calloc/realloc got alignment
+// attributes on their return pointer. However, that was reverted in
+// https://reviews.llvm.org/D118804 and it now asserts that they do _NOT_ get
+// align attributes.
 
 typedef __SIZE_TYPE__ size_t;
 
@@ -39,43 +37,29 @@ void *aligned_alloc_large_constant_test(size_t n) {
 }
 
 // CHECK-LABEL: @malloc_test
-// ALIGN16: align 16 i8* @malloc
-
-// CHECK-LABEL: @calloc_test
-// ALIGN16: align 16 i8* @calloc
-
-// CHECK-LABEL: @realloc_test
-// ALIGN16: align 16 i8* @reallo

[llvm-branch-commits] [llvm] 61c8cf9 - [Attributor][FIX] Do not use assumed information for UB detection

2022-02-08 Thread Tom Stellard via llvm-branch-commits

Author: Johannes Doerfert
Date: 2022-02-08T21:27:13-08:00
New Revision: 61c8cf97479f37c63724f63fd4c727cd2b433ae9

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

LOG: [Attributor][FIX] Do not use assumed information for UB detection

The helper `Attributor::checkForAllReturnedValuesAndReturnInsts`
simplifies the returned value optimistically. In `AAUndefinedBehavior`
we cannot use such optimistic values when deducing UB. As a result, we
assumed UB for the return value of a function because we initially
(=optimistically) thought the function return is `undef`. While we later
adjusted this properly, the `AAUndefinedBehavior` was under the
impression the return value is "known" (=fix) and could never change.

To correct this we use `Attributor::checkForAllInstructions` and then
manually to perform simplification of the return value, only allowing
known values to be used. This actually matches the other UB deductions.

Fixes #53647

(cherry picked from commit dd101c808b85aad8edb48ab6d5f754cc6527fcff)

Added: 


Modified: 
llvm/lib/Transforms/IPO/AttributorAttributes.cpp
llvm/test/Transforms/Attributor/undefined_behavior.ll

Removed: 




diff  --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp 
b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index 2d88e329e093..db2ba91bea58 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -2691,40 +2691,38 @@ struct AAUndefinedBehaviorImpl : public 
AAUndefinedBehavior {
   return true;
 };
 
-auto InspectReturnInstForUB =
-[&](Value &V, const SmallSetVector RetInsts) {
-  // Check if a return instruction always cause UB or not
-  // Note: It is guaranteed that the returned position of the anchor
-  //   scope has noundef attribute when this is called.
-  //   We also ensure the return position is not "assumed dead"
-  //   because the returned value was then potentially simplified 
to
-  //   `undef` in AAReturnedValues without removing the `noundef`
-  //   attribute yet.
-
-  // When the returned position has noundef attriubte, UB occur in the
-  // following cases.
-  //   (1) Returned value is known to be undef.
-  //   (2) The value is known to be a null pointer and the returned
-  //   position has nonnull attribute (because the returned value 
is
-  //   poison).
-  bool FoundUB = false;
-  if (isa(V)) {
-FoundUB = true;
-  } else {
-if (isa(V)) {
-  auto &NonNullAA = A.getAAFor(
-  *this, IRPosition::returned(*getAnchorScope()),
-  DepClassTy::NONE);
-  if (NonNullAA.isKnownNonNull())
-FoundUB = true;
-}
-  }
+auto InspectReturnInstForUB = [&](Instruction &I) {
+  auto &RI = cast(I);
+  // Either we stopped and the appropriate action was taken,
+  // or we got back a simplified return value to continue.
+  Optional SimplifiedRetValue =
+  stopOnUndefOrAssumed(A, RI.getReturnValue(), &I);
+  if (!SimplifiedRetValue.hasValue() || !SimplifiedRetValue.getValue())
+return true;
 
-  if (FoundUB)
-for (ReturnInst *RI : RetInsts)
-  KnownUBInsts.insert(RI);
-  return true;
-};
+  // Check if a return instruction always cause UB or not
+  // Note: It is guaranteed that the returned position of the anchor
+  //   scope has noundef attribute when this is called.
+  //   We also ensure the return position is not "assumed dead"
+  //   because the returned value was then potentially simplified to
+  //   `undef` in AAReturnedValues without removing the `noundef`
+  //   attribute yet.
+
+  // When the returned position has noundef attriubte, UB occurs in the
+  // following cases.
+  //   (1) Returned value is known to be undef.
+  //   (2) The value is known to be a null pointer and the returned
+  //   position has nonnull attribute (because the returned value is
+  //   poison).
+  if (isa(*SimplifiedRetValue)) {
+auto &NonNullAA = A.getAAFor(
+*this, IRPosition::returned(*getAnchorScope()), DepClassTy::NONE);
+if (NonNullAA.isKnownNonNull())
+  KnownUBInsts.insert(&I);
+  }
+
+  return true;
+};
 
 bool UsedAssumedInformation = false;
 A.checkForAllInstructions(InspectMemAccessInstForUB, *this,
@@ -2747,8 +2745,9 @@ struct AAUndefinedBehaviorImpl : public 
AAUndefinedBehavior {
 auto &RetPosNoUndefAA =
 A.getAAFor(*this, ReturnIRP, De

[llvm-branch-commits] [clang] f01051d - [Hexagon] Alter meaning of versionless -mhvx

2022-02-08 Thread Tom Stellard via llvm-branch-commits

Author: Krzysztof Parzyszek
Date: 2022-02-08T21:27:13-08:00
New Revision: f01051dd4edfa27cae33ea46648d9fea8536657b

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

LOG: [Hexagon] Alter meaning of versionless -mhvx

The documentation for the official (downstream) Qualcomm Hexagon Clang
states that -mhvx sets the HVX version to be the same as the CPU version.
The current implementation upstream would use the most recent versioned
-mhvx= flag first (if present), then the CPU version. Change the upstream
behavior to match the documented behavior of the downstream compiler.

(cherry picked from commit 2ecda9ec9cc89b87ce2e56452229c9444beabf21)

Added: 


Modified: 
clang/lib/Driver/ToolChains/Hexagon.cpp
clang/test/Driver/hexagon-hvx.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Hexagon.cpp 
b/clang/lib/Driver/ToolChains/Hexagon.cpp
index ba3040636604..e772122f5ff5 100644
--- a/clang/lib/Driver/ToolChains/Hexagon.cpp
+++ b/clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -72,23 +72,25 @@ static void handleHVXTargetFeatures(const Driver &D, const 
ArgList &Args,
   (Cpu.back() == 'T' || Cpu.back() == 't' ? Cpu.drop_back(1) : Cpu).str();
   HasHVX = false;
 
-  // Handle -mhvx, -mhvx=, -mno-hvx. If both present, -mhvx= wins over -mhvx.
-  auto argOrNull = [&Args](auto FlagOn, auto FlagOff) -> Arg* {
-if (Arg *A = Args.getLastArg(FlagOn, FlagOff)) {
-  if (A->getOption().matches(FlagOn))
-return A;
-}
-return nullptr;
-  };
-
-  Arg *HvxBareA =
-  argOrNull(options::OPT_mhexagon_hvx, options::OPT_mno_hexagon_hvx);
-  Arg *HvxVerA =
-  argOrNull(options::OPT_mhexagon_hvx_EQ, options::OPT_mno_hexagon_hvx);
+  // Handle -mhvx, -mhvx=, -mno-hvx. If versioned and versionless flags
+  // are both present, the last one wins.
+  Arg *HvxEnablingArg =
+  Args.getLastArg(options::OPT_mhexagon_hvx, options::OPT_mhexagon_hvx_EQ,
+  options::OPT_mno_hexagon_hvx);
+  if (HvxEnablingArg) {
+if (HvxEnablingArg->getOption().matches(options::OPT_mno_hexagon_hvx))
+  HvxEnablingArg = nullptr;
+  }
 
-  if (Arg *A = HvxVerA ? HvxVerA : HvxBareA) {
-if (A->getOption().matches(options::OPT_mhexagon_hvx_EQ))
-  HvxVer = StringRef(A->getValue()).lower(); // lower produces std:string
+  if (HvxEnablingArg) {
+// If -mhvx[=] was given, it takes precedence.
+if (Arg *A = Args.getLastArg(options::OPT_mhexagon_hvx,
+ options::OPT_mhexagon_hvx_EQ)) {
+  // If the version was given, set HvxVer. Otherwise HvxVer
+  // will remain equal to the CPU version.
+  if (A->getOption().matches(options::OPT_mhexagon_hvx_EQ))
+HvxVer = StringRef(A->getValue()).lower();
+}
 HasHVX = true;
 Features.push_back(makeFeature(Twine("hvx") + HvxVer, true));
   } else if (Arg *A = Args.getLastArg(options::OPT_mno_hexagon_hvx)) {

diff  --git a/clang/test/Driver/hexagon-hvx.c b/clang/test/Driver/hexagon-hvx.c
index 10bb8fe9327f..385774824cb0 100644
--- a/clang/test/Driver/hexagon-hvx.c
+++ b/clang/test/Driver/hexagon-hvx.c
@@ -54,6 +54,23 @@
 // RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V68 %s
 // RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v69 \
 // RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V69 %s
+// Infer HVX version from CPU version:
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv60 -mhvx \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V60 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv62 -mhvx \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V62 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv65 -mhvx \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V65 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv66 -mhvx \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V66 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv67 -mhvx \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V67 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv67t -mhvx \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V67 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv68 -mhvx \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V68 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv69 -mhvx \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V69 %s
 
 // Direct version flag with 
diff erent CPU version:
 // RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v60 -mv62 \
@@ -73,19 +90,19 @@
 
 // Direct version flag with 
diff erent CPU version and versionless -mhvx:
 // RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v60 -mv62 -mhvx \
-// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V60 %s
-// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v62 -mv

[llvm-branch-commits] [clang] 4f624dd - [PowerPC] Fix SSE translation on FreeBSD

2022-02-08 Thread Tom Stellard via llvm-branch-commits

Author: Piotr Kubaj
Date: 2022-02-08T21:27:13-08:00
New Revision: 4f624dd81687dcad957421ca6803e81a2262c4f4

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

LOG: [PowerPC] Fix SSE translation on FreeBSD

This patch drops throws specifier in posix_memalign declaration because
that's different between glibc and other libc, and Clang has a hack.

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

(cherry picked from commit f2f4080c10f4319adf75c660425911cd4e0e1843)

Added: 


Modified: 
clang/lib/Headers/ppc_wrappers/mm_malloc.h

Removed: 




diff  --git a/clang/lib/Headers/ppc_wrappers/mm_malloc.h 
b/clang/lib/Headers/ppc_wrappers/mm_malloc.h
index 86cf1a0f7618..b6bf22f92887 100644
--- a/clang/lib/Headers/ppc_wrappers/mm_malloc.h
+++ b/clang/lib/Headers/ppc_wrappers/mm_malloc.h
@@ -19,7 +19,7 @@
 #ifndef __cplusplus
 extern int posix_memalign (void **, size_t, size_t);
 #else
-extern "C" int posix_memalign (void **, size_t, size_t) throw ();
+extern "C" int posix_memalign (void **, size_t, size_t);
 #endif
 
 static __inline void *



___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] a2f5832 - [x86] invert a vector select IR canonicalization with a binop identity constant

2022-02-08 Thread Tom Stellard via llvm-branch-commits

Author: Sanjay Patel
Date: 2022-02-08T21:27:13-08:00
New Revision: a2f583280e48d8673de63c2a9f208f7b534fad02

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

LOG: [x86] invert a vector select IR canonicalization with a binop identity 
constant

This is an intentionally limited/different form of D90113.
That patch bravely tries to generalize folds where we pull
a binop into the arms of a select:
N0 + (Cond ? 0 : FVal) --> Cond ? N0 : (N0 + FVal)
...but it is not universally profitable.

This is the inverse of IR canonicalization as discussed in
D113442.

We know that this transform is not entirely profitable even
within x86, so we only handle x86 vector fadd/fsub as a 1st
step. The intent is to prevent AVX512 regressions as mentioned
in D113442.

The plan is to port this to DAGCombiner (so it will eventually
look more like D90113) and add more types/cases in pieces with
many more tests to verify that we are seeing improvements.

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

(cherry picked from commit 6592bcecd4ffc03f72d23f81bcb8d51f8ebeb07d)

Added: 


Modified: 
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/avx512fp16-arith-intrinsics.ll
llvm/test/CodeGen/X86/vector-bo-select.ll

Removed: 




diff  --git a/llvm/lib/Target/X86/X86ISelLowering.cpp 
b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 9afb885f582a..6f1fe8195595 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -48920,6 +48920,83 @@ static SDValue combineFaddCFmul(SDNode *N, 
SelectionDAG &DAG,
   return DAG.getBitcast(VT, CFmul);
 }
 
+/// This inverts a canonicalization in IR that replaces a variable select arm
+/// with an identity constant. Codegen improves if we re-use the variable
+/// operand rather than load a constant. This can also be converted into a
+/// masked vector operation if the target supports it.
+static SDValue foldSelectWithIdentityConstant(SDNode *N, SelectionDAG &DAG,
+  bool ShouldCommuteOperands) {
+  // Match a select as operand 1. The identity constant that we are looking for
+  // is only valid as operand 1 of a non-commutative binop.
+  SDValue N0 = N->getOperand(0);
+  SDValue N1 = N->getOperand(1);
+  if (ShouldCommuteOperands)
+std::swap(N0, N1);
+
+  // TODO: Should this apply to scalar select too?
+  if (!N1.hasOneUse() || N1.getOpcode() != ISD::VSELECT)
+return SDValue();
+
+  unsigned Opcode = N->getOpcode();
+  EVT VT = N->getValueType(0);
+  SDValue Cond = N1.getOperand(0);
+  SDValue TVal = N1.getOperand(1);
+  SDValue FVal = N1.getOperand(2);
+
+  // TODO: This (and possibly the entire function) belongs in a
+  //   target-independent location with target hooks.
+  // TODO: The cases should match with IR's ConstantExpr::getBinOpIdentity().
+  // TODO: With fast-math (NSZ), allow the opposite-sign form of zero?
+  auto isIdentityConstantForOpcode = [](unsigned Opcode, SDValue V) {
+if (ConstantFPSDNode *C = isConstOrConstSplatFP(V)) {
+  switch (Opcode) {
+  case ISD::FADD: // X + -0.0 --> X
+return C->isZero() && C->isNegative();
+  case ISD::FSUB: // X - 0.0 --> X
+return C->isZero() && !C->isNegative();
+  }
+}
+return false;
+  };
+
+  // This transform increases uses of N0, so freeze it to be safe.
+  // binop N0, (vselect Cond, IDC, FVal) --> vselect Cond, N0, (binop N0, FVal)
+  if (isIdentityConstantForOpcode(Opcode, TVal)) {
+SDValue F0 = DAG.getFreeze(N0);
+SDValue NewBO = DAG.getNode(Opcode, SDLoc(N), VT, F0, FVal, N->getFlags());
+return DAG.getSelect(SDLoc(N), VT, Cond, F0, NewBO);
+  }
+  // binop N0, (vselect Cond, TVal, IDC) --> vselect Cond, (binop N0, TVal), N0
+  if (isIdentityConstantForOpcode(Opcode, FVal)) {
+SDValue F0 = DAG.getFreeze(N0);
+SDValue NewBO = DAG.getNode(Opcode, SDLoc(N), VT, F0, TVal, N->getFlags());
+return DAG.getSelect(SDLoc(N), VT, Cond, NewBO, F0);
+  }
+
+  return SDValue();
+}
+
+static SDValue combineBinopWithSelect(SDNode *N, SelectionDAG &DAG,
+  const X86Subtarget &Subtarget) {
+  // TODO: This is too general. There are cases where pre-AVX512 codegen would
+  //   benefit. The transform may also be profitable for scalar code.
+  if (!Subtarget.hasAVX512())
+return SDValue();
+
+  if (!Subtarget.hasVLX() && !N->getValueType(0).is512BitVector())
+return SDValue();
+
+  if (SDValue Sel = foldSelectWithIdentityConstant(N, DAG, false))
+return Sel;
+
+  const TargetLowering &TLI = DAG.getTargetLoweringInfo();
+  if (TLI.isCommutativeBinOp(N->getOpcode()))
+if (SDValue Sel = foldSelectWithIdentityConstant(N, DAG, true))
+  return Sel;
+
+  return SDValue();
+}
+
 /// Do t

[llvm-branch-commits] [lld] 7607a39 - [ELF] --warn-backrefs: suppress warnings for backward references within the archive

2022-02-08 Thread Fangrui Song via llvm-branch-commits

Author: Fangrui Song
Date: 2022-02-08T21:48:52-08:00
New Revision: 7607a39e9388b32ca90414ada56ce687b2272be4

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

LOG: [ELF] --warn-backrefs: suppress warnings for backward references within 
the archive

(cherry picked from commit 99580e29d821beeaf75345deb3e4cc2c6808bfc0)

Added: 


Modified: 
lld/ELF/Driver.cpp
lld/test/ELF/warn-backrefs.s

Removed: 




diff  --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 406571e4e9fd5..ca56f5ee0f10f 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -235,22 +235,28 @@ void LinkerDriver::addFile(StringRef path, bool 
withLOption) {
 // user is attempting LTO and using a default ar command that doesn't
 // understand the LLVM bitcode file. Treat the archive as a group of lazy
 // object files.
-if (!file->isEmpty() && !file->hasSymbolTable()) {
-  for (const std::pair &p :
-   getArchiveMembers(mbref)) {
-auto magic = identify_magic(p.first.getBuffer());
-if (magic == file_magic::bitcode ||
-magic == file_magic::elf_relocatable)
-  files.push_back(createLazyFile(p.first, path, p.second));
-else
-  error(path + ": archive member '" + p.first.getBufferIdentifier() +
-"' is neither ET_REL nor LLVM bitcode");
-  }
+if (file->isEmpty() || file->hasSymbolTable()) {
+  // Handle the regular case.
+  files.push_back(make(std::move(file)));
   return;
 }
 
-// Handle the regular case.
-files.push_back(make(std::move(file)));
+// All files within the archive get the same group ID to allow mutual
+// references for --warn-backrefs.
+bool saved = InputFile::isInGroup;
+InputFile::isInGroup = true;
+for (const std::pair &p :
+ getArchiveMembers(mbref)) {
+  auto magic = identify_magic(p.first.getBuffer());
+  if (magic == file_magic::bitcode || magic == file_magic::elf_relocatable)
+files.push_back(createLazyFile(p.first, path, p.second));
+  else
+error(path + ": archive member '" + p.first.getBufferIdentifier() +
+  "' is neither ET_REL nor LLVM bitcode");
+}
+InputFile::isInGroup = saved;
+if (!saved)
+  ++InputFile::nextGroupId;
 return;
   }
   case file_magic::elf_shared_object:

diff  --git a/lld/test/ELF/warn-backrefs.s b/lld/test/ELF/warn-backrefs.s
index a6866869054a4..907f042c0e818 100644
--- a/lld/test/ELF/warn-backrefs.s
+++ b/lld/test/ELF/warn-backrefs.s
@@ -63,6 +63,8 @@
 # RUN: echo '.globl bar; bar:' | llvm-mc -filetype=obj -triple=x86_64 - -o 
%t3.o
 # RUN: echo '.globl foo; foo: call bar' | llvm-mc -filetype=obj -triple=x86_64 
- -o %t4.o
 # RUN: ld.lld --fatal-warnings --warn-backrefs %t1.o --start-lib %t3.o %t4.o 
--end-lib -o /dev/null
+# RUN: rm -f %t34.a && llvm-ar rcS %t34.a %t3.o %t4.o
+# RUN: ld.lld --fatal-warnings --warn-backrefs %t1.o %t34.a -o /dev/null
 
 ## We don't report backward references to weak symbols as they can be 
overridden later.
 # RUN: echo '.weak foo; foo:' | llvm-mc -filetype=obj -triple=x86_64 - -o 
%tweak.o



___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] 7246d58 - [clang][ARM] Re-word PACBTI warning.

2022-02-08 Thread Tom Stellard via llvm-branch-commits

Author: Amilendra Kodithuwakku
Date: 2022-02-08T23:15:52-08:00
New Revision: 7246d583d6017dbea8baa453e78f26e145448d6e

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

LOG: [clang][ARM] Re-word PACBTI warning.

The original warning added in D115501 when pacbti is used with an
incompatible architecture was not exactly correct because it was
not really ignored and can affect codegen.

Therefore reword to say that the pacbti option is incompatible with
the given architecture.

Reviewed By: chill

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

(cherry picked from commit 424e850f1ebc3e7011cb4af44cb2d62c02a58fbe)

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticCommonKinds.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/arm-security-options.c

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index 5ea55b0fd31ba..421527827a4bd 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -145,8 +145,8 @@ def 
warn_conflicting_nullability_attr_overriding_param_types : Warning<
 def err_nullability_conflicting : Error<
   "nullability specifier %0 conflicts with existing specifier %1">;
 
-def warn_target_unsupported_branch_protection_option: Warning <
-  "ignoring '-mbranch-protection=' option because the '%0' architecture does 
not support it">,
+def warn_incompatible_branch_protection_option: Warning <
+  "'-mbranch-protection=' option is incompatible with the '%0' architecture">,
   InGroup;
 
 def warn_target_unsupported_branch_protection_attribute: Warning <

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 5b2984ea2496f..f2f18e901ab01 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1639,7 +1639,7 @@ static void CollectARMPACBTIOptions(const ToolChain &TC, 
const ArgList &Args,
   const Driver &D = TC.getDriver();
   const llvm::Triple &Triple = TC.getEffectiveTriple();
   if (!(isAArch64 || (Triple.isArmT32() && Triple.isArmMClass(
-D.Diag(diag::warn_target_unsupported_branch_protection_option)
+D.Diag(diag::warn_incompatible_branch_protection_option)
 << Triple.getArchName();
 
   StringRef Scope, Key;

diff  --git a/clang/test/Driver/arm-security-options.c 
b/clang/test/Driver/arm-security-options.c
index 79367d7bbb965..fc1b5da78d2cf 100644
--- a/clang/test/Driver/arm-security-options.c
+++ b/clang/test/Driver/arm-security-options.c
@@ -90,4 +90,4 @@
 // BAD-B-KEY-COMBINATION: invalid branch protection option 'b-key' in 
'-mbranch-protection={{.*}}'
 // BAD-LEAF-COMBINATION: invalid branch protection option 'leaf' in 
'-mbranch-protection={{.*}}'
 
-// INCOMPATIBLE-ARCH: ignoring '-mbranch-protection=' option because the 
'{{.*}}' architecture does not support it
+// INCOMPATIBLE-ARCH: '-mbranch-protection=' option is incompatible with the 
'{{.*}}' architecture



___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] be308cf - [clang][Sparc] Fix __builtin_extract_return_addr etc.

2022-02-08 Thread Tom Stellard via llvm-branch-commits

Author: Rainer Orth
Date: 2022-02-08T23:15:52-08:00
New Revision: be308cf4cda010ca04e064f77bd5df307903314f

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

LOG: [clang][Sparc] Fix __builtin_extract_return_addr etc.

While investigating the failures of `symbolize_pc.cpp` and
`symbolize_pc_inline.cpp` on SPARC (both Solaris and Linux), I noticed that
`__builtin_extract_return_addr` is a no-op in `clang` on all targets, while
`gcc` has non-default implementations for arm, mips, s390, and sparc.

This patch provides the SPARC implementation.  For background see
`SparcISelLowering.cpp` (`SparcTargetLowering::LowerReturn_32`), the SPARC
psABI p.3-12, `%i7` and p.3-16/17, and SCD 2.4.1, p.3P-10, `%i7` and
p.3P-15.

Tested (after enabling the `sanitizer_common` tests on SPARC) on
`sparcv9-sun-solaris2.11`.

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

(cherry picked from commit efdd0a29b7eb6f3b6ca3fe9182a6c1085806c73a)

Added: 


Modified: 
clang/lib/CodeGen/TargetInfo.cpp
clang/test/CodeGen/builtins-sparc.c

Removed: 




diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index 8a0150218a7a9..9af3004ebcc5b 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -9474,6 +9474,28 @@ class SparcV8TargetCodeGenInfo : public 
TargetCodeGenInfo {
 public:
   SparcV8TargetCodeGenInfo(CodeGenTypes &CGT)
   : TargetCodeGenInfo(std::make_unique(CGT)) {}
+
+  llvm::Value *decodeReturnAddress(CodeGen::CodeGenFunction &CGF,
+   llvm::Value *Address) const override {
+int Offset;
+if (isAggregateTypeForABI(CGF.CurFnInfo->getReturnType()))
+  Offset = 12;
+else
+  Offset = 8;
+return CGF.Builder.CreateGEP(CGF.Int8Ty, Address,
+ llvm::ConstantInt::get(CGF.Int32Ty, Offset));
+  }
+
+  llvm::Value *encodeReturnAddress(CodeGen::CodeGenFunction &CGF,
+   llvm::Value *Address) const override {
+int Offset;
+if (isAggregateTypeForABI(CGF.CurFnInfo->getReturnType()))
+  Offset = -12;
+else
+  Offset = -8;
+return CGF.Builder.CreateGEP(CGF.Int8Ty, Address,
+ llvm::ConstantInt::get(CGF.Int32Ty, Offset));
+  }
 };
 } // end anonymous namespace
 
@@ -9748,6 +9770,18 @@ class SparcV9TargetCodeGenInfo : public 
TargetCodeGenInfo {
 
   bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
llvm::Value *Address) const override;
+
+  llvm::Value *decodeReturnAddress(CodeGen::CodeGenFunction &CGF,
+   llvm::Value *Address) const override {
+return CGF.Builder.CreateGEP(CGF.Int8Ty, Address,
+ llvm::ConstantInt::get(CGF.Int32Ty, 8));
+  }
+
+  llvm::Value *encodeReturnAddress(CodeGen::CodeGenFunction &CGF,
+   llvm::Value *Address) const override {
+return CGF.Builder.CreateGEP(CGF.Int8Ty, Address,
+ llvm::ConstantInt::get(CGF.Int32Ty, -8));
+  }
 };
 } // end anonymous namespace
 

diff  --git a/clang/test/CodeGen/builtins-sparc.c 
b/clang/test/CodeGen/builtins-sparc.c
index 92cc7677e21f7..343a1c521526c 100644
--- a/clang/test/CodeGen/builtins-sparc.c
+++ b/clang/test/CodeGen/builtins-sparc.c
@@ -1,10 +1,29 @@
 // REQUIRES: sparc-registered-target
 // RUN: %clang_cc1 -triple sparc-unknown-unknown -emit-llvm %s -o - | 
FileCheck %s
-// RUN: %clang_cc1 -triple sparc64-unknown-unknown -emit-llvm %s -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple sparc64-unknown-unknown -emit-llvm %s -o - | 
FileCheck -check-prefix CHECK-V9 %s
 
 void test_eh_return_data_regno(void)
 {
   volatile int res;
-  res = __builtin_eh_return_data_regno(0);  // CHECK: store volatile i32 24
-  res = __builtin_eh_return_data_regno(1);  // CHECK: store volatile i32 25
+  res = __builtin_eh_return_data_regno(0);  // CHECK,CHECKV9: store volatile 
i32 24
+  res = __builtin_eh_return_data_regno(1);  // CHECK,CHECKV9: store volatile 
i32 25
+}
+
+void *test_extract_return_address(void)
+{
+  // CHECK,CHECKV9: getelementptr i8, i8* %0, i32 8
+  return __builtin_extract_return_addr(__builtin_return_address(0));
+}
+
+struct s {
+  void *p;
+};
+
+struct s test_extract_struct_return_address(void)
+{
+  struct s s;
+  // CHECK:getelementptr i8, i8* %0, i32 12
+  // CHECK-V9: getelementptr i8, i8* %0, i32 8
+  s.p = __builtin_extract_return_addr(__builtin_return_address(0));
+  return s;
 }



___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] f5f0bd8 - Revert "[Clang] Propagate guaranteed alignment for malloc and others"

2022-02-08 Thread Tom Stellard via llvm-branch-commits

Author: James Y Knight
Date: 2022-02-08T23:15:52-08:00
New Revision: f5f0bd8e3d972d040827c88adf1a9880ebcb821e

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

LOG: Revert "[Clang] Propagate guaranteed alignment for malloc and others"

The above change assumed that malloc (and friends) would always
allocate memory to getNewAlign(), even for allocations which have a
smaller size. This is not actually required by spec (a 1-byte
allocation may validly have 1-byte alignment).

Some real-world malloc implementations do not provide this guarantee,
and thus this optimization is breaking programs.

Fixes #53540

This reverts commit c2297544c04764237cedc523083c7be2fb3833d4.

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

(cherry picked from commit 9545976ff160e19805a84a06a7e59d446f9994d9)

Added: 


Modified: 
clang/include/clang/Basic/TargetInfo.h
clang/lib/Sema/SemaDecl.cpp
clang/test/CodeGen/alloc-fns-alignment.c

Removed: 




diff  --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index a49342a34f3e8..e7db877f4e2bc 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -644,8 +644,8 @@ class TargetInfo : public virtual TransferrableTargetInfo,
   }
 
   /// Return the largest alignment for which a suitably-sized allocation with
-  /// '::operator new(size_t)' or 'malloc' is guaranteed to produce a
-  /// correctly-aligned pointer.
+  /// '::operator new(size_t)' is guaranteed to produce a correctly-aligned
+  /// pointer.
   unsigned getNewAlign() const {
 return NewAlign ? NewAlign : std::max(LongDoubleAlign, LongLongAlign);
   }

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index cbd9df4d6a7b7..bcadf4139046c 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -15319,24 +15319,7 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl 
*FD) {
   if (!FD->hasAttr())
 FD->addAttr(AllocAlignAttr::CreateImplicit(Context, ParamIdx(1, FD),
FD->getLocation()));
-  LLVM_FALLTHROUGH;
-case Builtin::BIcalloc:
-case Builtin::BImalloc:
-case Builtin::BImemalign:
-case Builtin::BIrealloc:
-case Builtin::BIstrdup:
-case Builtin::BIstrndup: {
-  if (!FD->hasAttr()) {
-unsigned NewAlign = Context.getTargetInfo().getNewAlign() /
-Context.getTargetInfo().getCharWidth();
-IntegerLiteral *Alignment = IntegerLiteral::Create(
-Context, Context.MakeIntValue(NewAlign, Context.UnsignedIntTy),
-Context.UnsignedIntTy, FD->getLocation());
-FD->addAttr(AssumeAlignedAttr::CreateImplicit(
-Context, Alignment, /*Offset=*/nullptr, FD->getLocation()));
-  }
   break;
-}
 default:
   break;
 }

diff  --git a/clang/test/CodeGen/alloc-fns-alignment.c 
b/clang/test/CodeGen/alloc-fns-alignment.c
index 8ab0610accf03..31dc9bb2d759d 100644
--- a/clang/test/CodeGen/alloc-fns-alignment.c
+++ b/clang/test/CodeGen/alloc-fns-alignment.c
@@ -1,11 +1,9 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm < %s | 
FileCheck %s --check-prefix=ALIGN16
-// RUN: %clang_cc1 -triple x86_64-windows-msvc  -emit-llvm < %s | 
FileCheck %s --check-prefix=ALIGN16
-// RUN: %clang_cc1 -triple i386-apple-darwin-emit-llvm < %s | 
FileCheck %s --check-prefix=ALIGN16
-// RUN: %clang_cc1 -triple i386-unknown-linux-gnu   -emit-llvm < %s | 
FileCheck %s --check-prefix=ALIGN8
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-malloc  
-emit-llvm < %s  | FileCheck %s --check-prefix=NOBUILTIN-MALLOC
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-calloc  
-emit-llvm < %s  | FileCheck %s --check-prefix=NOBUILTIN-CALLOC
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-realloc 
-emit-llvm < %s  | FileCheck %s --check-prefix=NOBUILTIN-REALLOC
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-aligned_alloc 
-emit-llvm < %s  | FileCheck %s --check-prefix=NOBUILTIN-ALIGNED_ALLOC
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm < %s | 
FileCheck %s
+
+// Note: this test originally asserted that malloc/calloc/realloc got alignment
+// attributes on their return pointer. However, that was reverted in
+// https://reviews.llvm.org/D118804 and it now asserts that they do _NOT_ get
+// align attributes.
 
 typedef __SIZE_TYPE__ size_t;
 
@@ -39,43 +37,29 @@ void *aligned_alloc_large_constant_test(size_t n) {
 }
 
 // CHECK-LABEL: @malloc_test
-// ALIGN16: align 16 i8* @malloc
-
-// CHECK-LABEL: @calloc_test
-// ALIGN16: align 16 i8* @calloc
-
-// CHECK-LABEL: @realloc_test
-// ALIGN16: align 16 i8* @reallo