[llvm-branch-commits] [clang] [openmp] [Clang][OpenMP] Fix tile/unroll on iterator- and foreach-loops. (PR #91459)

2024-05-13 Thread Michael Kruse via llvm-branch-commits

https://github.com/Meinersbur ready_for_review 
https://github.com/llvm/llvm-project/pull/91459
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [openmp] [Clang][OpenMP] Fix tile/unroll on iterator- and foreach-loops. (PR #91459)

2024-05-13 Thread via llvm-branch-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-codegen

Author: Michael Kruse (Meinersbur)


Changes

OpenMP loop transformation did not work on a for-loop using an iterator or 
range-based for-loops. The first reason is that it combined the iterator's type 
for generated loops with the type of `NumIterations` as generated for any 
`OMPLoopBasedDirective` which is an integer. Fixed by basing all generated loop 
variables on `NumIterations`.

Second, C++11 range-based for-loops include syntactic sugar that needs to be 
executed before the loop. This additional code is now added to the construct's 
Pre-Init lists. 

Third, C++20 added an initializer statement to range-based for-loops which is 
also added to the pre-init statement. PreInits used to be a `DeclStmt` which 
made it difficult to add arbitrary statements from `CXXRangeForStmt`'s 
syntactic sugar, especially the for-loops init statement which does not need to 
be a declaration. Change it to be a general `Stmt` that can be a `CompoundStmt` 
to hold arbitrary Stmts, including DeclStmts. This also avoids the 
`PointerUnion` workaround used by `checkTransformableLoopNest`.

End-to-end tests are added to verify the expected number and order of loop 
execution and evaluations of expressions (such as iterator dereference). The 
order and number of evaluations of expressions in canonical loops is explicitly 
undefined by OpenMP but checked here for clarification and for changes to be 
noticed.

---

Patch is 170.36 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/91459.diff


18 Files Affected:

- (modified) clang/include/clang/Sema/SemaOpenMP.h (+1-3) 
- (modified) clang/lib/CodeGen/CGStmtOpenMP.cpp (+23-6) 
- (modified) clang/lib/Sema/SemaOpenMP.cpp (+135-55) 
- (modified) clang/test/OpenMP/tile_codegen.cpp (+678-209) 
- (modified) clang/test/OpenMP/tile_codegen_for_dependent.cpp (+65-65) 
- (modified) clang/test/OpenMP/tile_codegen_tile_for.cpp (+111-107) 
- (modified) openmp/runtime/test/lit.cfg (+4) 
- (added) openmp/runtime/test/transform/tile/foreach.cpp (+228) 
- (added) openmp/runtime/test/transform/tile/iterfor.cpp (+233) 
- (added) 
openmp/runtime/test/transform/tile/parallel-wsloop-collapse-foreach.cpp (+366) 
- (added) openmp/runtime/test/transform/unroll/factor_foreach.cpp (+162) 
- (added) openmp/runtime/test/transform/unroll/factor_intfor.c (+25) 
- (added) openmp/runtime/test/transform/unroll/factor_iterfor.cpp (+169) 
- (added) 
openmp/runtime/test/transform/unroll/factor_parallel-wsloop-collapse-foreach.cpp
 (+199) 
- (added) 
openmp/runtime/test/transform/unroll/factor_parallel-wsloop-collapse-intfor.cpp 
(+32) 
- (added) openmp/runtime/test/transform/unroll/full_intfor.c (+25) 
- (added) openmp/runtime/test/transform/unroll/heuristic_intfor.c (+25) 
- (added) openmp/runtime/test/transform/unroll/partial_intfor.c (+25) 


``diff
diff --git a/clang/include/clang/Sema/SemaOpenMP.h 
b/clang/include/clang/Sema/SemaOpenMP.h
index 9927459bbc594..51981e1c9a8b9 100644
--- a/clang/include/clang/Sema/SemaOpenMP.h
+++ b/clang/include/clang/Sema/SemaOpenMP.h
@@ -1390,9 +1390,7 @@ class SemaOpenMP : public SemaBase {
   bool checkTransformableLoopNest(
   OpenMPDirectiveKind Kind, Stmt *AStmt, int NumLoops,
   SmallVectorImpl &LoopHelpers,
-  Stmt *&Body,
-  SmallVectorImpl, 0>>
-  &OriginalInits);
+  Stmt *&Body, SmallVectorImpl> &OriginalInits);
 
   /// Helper to keep information about the current `omp begin/end declare
   /// variant` nesting.
diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp 
b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index ef3aa3a8e0dc6..5069f5b5a291b 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -142,7 +142,7 @@ class OMPTeamsScope final : public OMPLexicalScope {
 /// of used expression from loop statement.
 class OMPLoopScope : public CodeGenFunction::RunCleanupsScope {
   void emitPreInitStmt(CodeGenFunction &CGF, const OMPLoopBasedDirective &S) {
-const DeclStmt *PreInits;
+const Stmt *PreInits;
 CodeGenFunction::OMPMapVars PreCondVars;
 if (auto *LD = dyn_cast(&S)) {
   llvm::DenseSet EmittedAsPrivate;
@@ -182,17 +182,34 @@ class OMPLoopScope : public 
CodeGenFunction::RunCleanupsScope {
 }
 return false;
   });
-  PreInits = cast_or_null(LD->getPreInits());
+  PreInits = LD->getPreInits();
 } else if (const auto *Tile = dyn_cast(&S)) {
-  PreInits = cast_or_null(Tile->getPreInits());
+  PreInits = Tile->getPreInits();
 } else if (const auto *Unroll = dyn_cast(&S)) {
-  PreInits = cast_or_null(Unroll->getPreInits());
+  PreInits = Unroll->getPreInits();
 } else {
   llvm_unreachable("Unknown loop-based directive kind.");
 }
 if (PreInits) {
-  for (const auto *I : PreInits->decls())
-CGF.EmitVarDecl(cast(*I));
+  // CompoundStmts and DeclStmts are used as lists of P

[llvm-branch-commits] [clang] [openmp] [Clang][OpenMP][Tile] Allow non-constant tile sizes. (PR #91345)

2024-05-13 Thread Michael Kruse via llvm-branch-commits

https://github.com/Meinersbur updated 
https://github.com/llvm/llvm-project/pull/91345

>From a2aa6950ce3880b8e669025d95ac9e72245e26a7 Mon Sep 17 00:00:00 2001
From: Michael Kruse 
Date: Tue, 7 May 2024 16:42:41 +0200
Subject: [PATCH 1/4] Allow non-constant tile sizes

---
 clang/include/clang/Parse/Parser.h|  17 ++
 clang/lib/Parse/ParseOpenMP.cpp   |  65 --
 clang/lib/Sema/SemaOpenMP.cpp | 113 +++--
 clang/test/OpenMP/tile_ast_print.cpp  |  17 ++
 clang/test/OpenMP/tile_codegen.cpp| 216 --
 clang/test/OpenMP/tile_messages.cpp   |  50 +++-
 openmp/runtime/test/transform/tile/intfor.c   | 187 +++
 .../test/transform/tile/negtile_intfor.c  |  44 
 .../tile/parallel-wsloop-collapse-intfor.cpp  | 100 
 9 files changed, 737 insertions(+), 72 deletions(-)
 create mode 100644 openmp/runtime/test/transform/tile/intfor.c
 create mode 100644 openmp/runtime/test/transform/tile/negtile_intfor.c
 create mode 100644 
openmp/runtime/test/transform/tile/parallel-wsloop-collapse-intfor.cpp

diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index daefd4f28f011..1b500c11457f4 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -3553,6 +3553,23 @@ class Parser : public CodeCompletionHandler {
   OMPClause *ParseOpenMPVarListClause(OpenMPDirectiveKind DKind,
   OpenMPClauseKind Kind, bool ParseOnly);
 
+  /// Parses a clause consisting of a list of expressions.
+  ///
+  /// \param Kind  The clause to parse.
+  /// \param ClauseNameLoc [out] The location of the clause name.
+  /// \param OpenLoc   [out] The location of '('.
+  /// \param CloseLoc  [out] The location of ')'.
+  /// \param Exprs [out] The parsed expressions.
+  /// \param ReqIntConst   If true, each expression must be an integer 
constant.
+  ///
+  /// \return Whether the clause was parsed successfully.
+  bool ParseOpenMPExprListClause(OpenMPClauseKind Kind,
+ SourceLocation &ClauseNameLoc,
+ SourceLocation &OpenLoc,
+ SourceLocation &CloseLoc,
+ SmallVectorImpl &Exprs,
+ bool ReqIntConst = false);
+
   /// Parses and creates OpenMP 5.0 iterators expression:
   ///  = 'iterator' '(' { [  ] identifier =
   ///  }+ ')'
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 18ba1185ee8de..b8b32f9546c4f 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -3107,34 +3107,14 @@ bool Parser::ParseOpenMPSimpleVarList(
 }
 
 OMPClause *Parser::ParseOpenMPSizesClause() {
-  SourceLocation ClauseNameLoc = ConsumeToken();
+  SourceLocation ClauseNameLoc, OpenLoc, CloseLoc;
   SmallVector ValExprs;
-
-  BalancedDelimiterTracker T(*this, tok::l_paren, 
tok::annot_pragma_openmp_end);
-  if (T.consumeOpen()) {
-Diag(Tok, diag::err_expected) << tok::l_paren;
+  if (ParseOpenMPExprListClause(OMPC_sizes, ClauseNameLoc, OpenLoc, CloseLoc,
+ValExprs))
 return nullptr;
-  }
-
-  while (true) {
-ExprResult Val = ParseConstantExpression();
-if (!Val.isUsable()) {
-  T.skipToEnd();
-  return nullptr;
-}
-
-ValExprs.push_back(Val.get());
-
-if (Tok.is(tok::r_paren) || Tok.is(tok::annot_pragma_openmp_end))
-  break;
-
-ExpectAndConsume(tok::comma);
-  }
-
-  T.consumeClose();
 
-  return Actions.OpenMP().ActOnOpenMPSizesClause(
-  ValExprs, ClauseNameLoc, T.getOpenLocation(), T.getCloseLocation());
+  return Actions.OpenMP().ActOnOpenMPSizesClause(ValExprs, ClauseNameLoc,
+ OpenLoc, CloseLoc);
 }
 
 OMPClause *Parser::ParseOpenMPUsesAllocatorClause(OpenMPDirectiveKind DKind) {
@@ -4991,3 +4971,38 @@ OMPClause 
*Parser::ParseOpenMPVarListClause(OpenMPDirectiveKind DKind,
   OMPVarListLocTy Locs(Loc, LOpen, Data.RLoc);
   return Actions.OpenMP().ActOnOpenMPVarListClause(Kind, Vars, Locs, Data);
 }
+
+bool Parser::ParseOpenMPExprListClause(OpenMPClauseKind Kind,
+   SourceLocation &ClauseNameLoc,
+   SourceLocation &OpenLoc,
+   SourceLocation &CloseLoc,
+   SmallVectorImpl &Exprs,
+   bool ReqIntConst) {
+  assert(getOpenMPClauseName(Kind) == PP.getSpelling(Tok) &&
+ "Expected parsing to start at clause name");
+  ClauseNameLoc = ConsumeToken();
+
+  // Parse inside of '(' and ')'.
+  BalancedDelimiterTracker T(*this, tok::l_paren, 
tok::annot_pragma_openmp_end);
+  if (T.consumeOpen()) {
+Diag(Tok, diag::err_expected) << tok::l_paren;
+return true;
+  }
+
+  // Parse the list with interleaved comma

[llvm-branch-commits] [clang] [openmp] [Clang][OpenMP][Tile] Allow non-constant tile sizes. (PR #91345)

2024-05-13 Thread Michael Kruse via llvm-branch-commits


@@ -15197,6 +15202,36 @@ StmtResult 
SemaOpenMP::ActOnOpenMPTileDirective(ArrayRef Clauses,
   // Once the original iteration values are set, append the innermost body.
   Stmt *Inner = Body;
 
+  auto MakeDimTileSize = [&SemaRef = this->SemaRef, &CopyTransformer, &Context,
+  SizesClause, CurScope](int I) -> Expr * {
+Expr *DimTileSizeExpr = SizesClause->getSizesRefs()[I];
+if (isa(DimTileSizeExpr))
+  return AssertSuccess(CopyTransformer.TransformExpr(DimTileSizeExpr));
+
+// When the tile size is not a constant but a variable, it is possible to
+// pass non-positive numbers. To preserve the invariant that every loop

Meinersbur wrote:

Added the example to the comment to clarify

https://github.com/llvm/llvm-project/pull/91345
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [openmp] [Clang][OpenMP][Tile] Allow non-constant tile sizes. (PR #91345)

2024-05-13 Thread Michael Kruse via llvm-branch-commits

https://github.com/Meinersbur updated 
https://github.com/llvm/llvm-project/pull/91345

>From a2aa6950ce3880b8e669025d95ac9e72245e26a7 Mon Sep 17 00:00:00 2001
From: Michael Kruse 
Date: Tue, 7 May 2024 16:42:41 +0200
Subject: [PATCH 1/5] Allow non-constant tile sizes

---
 clang/include/clang/Parse/Parser.h|  17 ++
 clang/lib/Parse/ParseOpenMP.cpp   |  65 --
 clang/lib/Sema/SemaOpenMP.cpp | 113 +++--
 clang/test/OpenMP/tile_ast_print.cpp  |  17 ++
 clang/test/OpenMP/tile_codegen.cpp| 216 --
 clang/test/OpenMP/tile_messages.cpp   |  50 +++-
 openmp/runtime/test/transform/tile/intfor.c   | 187 +++
 .../test/transform/tile/negtile_intfor.c  |  44 
 .../tile/parallel-wsloop-collapse-intfor.cpp  | 100 
 9 files changed, 737 insertions(+), 72 deletions(-)
 create mode 100644 openmp/runtime/test/transform/tile/intfor.c
 create mode 100644 openmp/runtime/test/transform/tile/negtile_intfor.c
 create mode 100644 
openmp/runtime/test/transform/tile/parallel-wsloop-collapse-intfor.cpp

diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index daefd4f28f011..1b500c11457f4 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -3553,6 +3553,23 @@ class Parser : public CodeCompletionHandler {
   OMPClause *ParseOpenMPVarListClause(OpenMPDirectiveKind DKind,
   OpenMPClauseKind Kind, bool ParseOnly);
 
+  /// Parses a clause consisting of a list of expressions.
+  ///
+  /// \param Kind  The clause to parse.
+  /// \param ClauseNameLoc [out] The location of the clause name.
+  /// \param OpenLoc   [out] The location of '('.
+  /// \param CloseLoc  [out] The location of ')'.
+  /// \param Exprs [out] The parsed expressions.
+  /// \param ReqIntConst   If true, each expression must be an integer 
constant.
+  ///
+  /// \return Whether the clause was parsed successfully.
+  bool ParseOpenMPExprListClause(OpenMPClauseKind Kind,
+ SourceLocation &ClauseNameLoc,
+ SourceLocation &OpenLoc,
+ SourceLocation &CloseLoc,
+ SmallVectorImpl &Exprs,
+ bool ReqIntConst = false);
+
   /// Parses and creates OpenMP 5.0 iterators expression:
   ///  = 'iterator' '(' { [  ] identifier =
   ///  }+ ')'
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 18ba1185ee8de..b8b32f9546c4f 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -3107,34 +3107,14 @@ bool Parser::ParseOpenMPSimpleVarList(
 }
 
 OMPClause *Parser::ParseOpenMPSizesClause() {
-  SourceLocation ClauseNameLoc = ConsumeToken();
+  SourceLocation ClauseNameLoc, OpenLoc, CloseLoc;
   SmallVector ValExprs;
-
-  BalancedDelimiterTracker T(*this, tok::l_paren, 
tok::annot_pragma_openmp_end);
-  if (T.consumeOpen()) {
-Diag(Tok, diag::err_expected) << tok::l_paren;
+  if (ParseOpenMPExprListClause(OMPC_sizes, ClauseNameLoc, OpenLoc, CloseLoc,
+ValExprs))
 return nullptr;
-  }
-
-  while (true) {
-ExprResult Val = ParseConstantExpression();
-if (!Val.isUsable()) {
-  T.skipToEnd();
-  return nullptr;
-}
-
-ValExprs.push_back(Val.get());
-
-if (Tok.is(tok::r_paren) || Tok.is(tok::annot_pragma_openmp_end))
-  break;
-
-ExpectAndConsume(tok::comma);
-  }
-
-  T.consumeClose();
 
-  return Actions.OpenMP().ActOnOpenMPSizesClause(
-  ValExprs, ClauseNameLoc, T.getOpenLocation(), T.getCloseLocation());
+  return Actions.OpenMP().ActOnOpenMPSizesClause(ValExprs, ClauseNameLoc,
+ OpenLoc, CloseLoc);
 }
 
 OMPClause *Parser::ParseOpenMPUsesAllocatorClause(OpenMPDirectiveKind DKind) {
@@ -4991,3 +4971,38 @@ OMPClause 
*Parser::ParseOpenMPVarListClause(OpenMPDirectiveKind DKind,
   OMPVarListLocTy Locs(Loc, LOpen, Data.RLoc);
   return Actions.OpenMP().ActOnOpenMPVarListClause(Kind, Vars, Locs, Data);
 }
+
+bool Parser::ParseOpenMPExprListClause(OpenMPClauseKind Kind,
+   SourceLocation &ClauseNameLoc,
+   SourceLocation &OpenLoc,
+   SourceLocation &CloseLoc,
+   SmallVectorImpl &Exprs,
+   bool ReqIntConst) {
+  assert(getOpenMPClauseName(Kind) == PP.getSpelling(Tok) &&
+ "Expected parsing to start at clause name");
+  ClauseNameLoc = ConsumeToken();
+
+  // Parse inside of '(' and ')'.
+  BalancedDelimiterTracker T(*this, tok::l_paren, 
tok::annot_pragma_openmp_end);
+  if (T.consumeOpen()) {
+Diag(Tok, diag::err_expected) << tok::l_paren;
+return true;
+  }
+
+  // Parse the list with interleaved comma

[llvm-branch-commits] [clang] [openmp] [Clang][OpenMP][Tile] Allow non-constant tile sizes. (PR #91345)

2024-05-13 Thread Michael Kruse via llvm-branch-commits


@@ -17432,16 +17457,54 @@ OMPClause 
*SemaOpenMP::ActOnOpenMPSizesClause(ArrayRef SizeExprs,
   SourceLocation StartLoc,
   SourceLocation LParenLoc,
   SourceLocation EndLoc) {
-  for (Expr *SizeExpr : SizeExprs) {
-ExprResult NumForLoopsResult = VerifyPositiveIntegerConstantInClause(
-SizeExpr, OMPC_sizes, /*StrictlyPositive=*/true);
-if (!NumForLoopsResult.isUsable())
-  return nullptr;
+  SmallVector SanitizedSizeExprs;
+  llvm::append_range(SanitizedSizeExprs, SizeExprs);
+
+  for (Expr *&SizeExpr : SanitizedSizeExprs) {
+// Skip if already sanitized, e.g. during a partial template instantiation.
+if (!SizeExpr)
+  continue;
+
+bool IsValid = isNonNegativeIntegerValue(SizeExpr, SemaRef, OMPC_sizes,
+ /*StrictlyPositive=*/true);
+
+// isNonNegativeIntegerValue returns true for non-integral types (but still
+// emits error diagnostic), so check for the expected type explicitly.
+QualType SizeTy = SizeExpr->getType();
+if (!SizeTy->isIntegerType())
+  IsValid = false;
+
+// Handling in templates is tricky. There are four possibilities to
+// consider:
+//
+// 1a. The expression is valid and we are in a instantiated template or not
+// in a template:
+//   Pass valid expression to be further analysed later in Sema.
+// 1b. The expression is valid and we are in a template (including partial
+// instantiation):
+//   isNonNegativeIntegerValue skipped any checks so there is no
+//   guarantee it will be correct after instantiation.
+//   ActOnOpenMPSizesClause will be called again at instantiation when
+//   it is not in a dependent context anymore. This may cause warnings
+//   to be emitted multiple times.
+// 2a. The expression is invalid and we are in an instantiated template or
+// not in a template:
+//   Invalidate the expression with a clearly wrong value (nullptr) so
+//   later in Sema we do not have to do the same validity analysis 
again
+//   or crash from unexpected data. Error diagnostics have already been
+//   emitted.
+// 2b. The expression is invalid and we are in a template (including 
partial
+// instantiation):
+//   Pass the invalid expression as-is, template instantiation may
+//   replace unexpected types/values with valid ones. The directives
+//   with this clause must not try to use these expressions in 
dependent
+//   contexts.

Meinersbur wrote:

Added clarification

https://github.com/llvm/llvm-project/pull/91345
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/18.x: [LV, LAA] Don't vectorize loops with load and store to invar address. (PR #91092)

2024-05-13 Thread Florian Hahn via llvm-branch-commits

https://github.com/fhahn approved this pull request.

LG to be back-ported if desired. It fixes an mis-compile but I am not aware of 
any end-to-end reports. I am not sure what the criteria for cherry-picks on the 
release branch are at this point in the release

https://github.com/llvm/llvm-project/pull/91092
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/18.x: [LV, LAA] Don't vectorize loops with load and store to invar address. (PR #91092)

2024-05-13 Thread Nikita Popov via llvm-branch-commits

nikic wrote:

I wonder why CI doesn't flag this as an ABI-breaking change, given that it 
modifies members of a class in llvm/include.

https://github.com/llvm/llvm-project/pull/91092
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] ec66d39 - Revert "Revert "[DirectX] Fix DXIL part header version encoding" (#91791)"

2024-05-13 Thread via llvm-branch-commits

Author: Xiang Li
Date: 2024-05-13T08:58:36-04:00
New Revision: ec66d3931a3320cc21c278f94e6eeb815d4d274b

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

LOG: Revert "Revert "[DirectX] Fix DXIL part header version encoding" (#91791)"

This reverts commit d655054395e2dba2b949e170d7764cc8c9c8a597.

Added: 


Modified: 
llvm/include/llvm/BinaryFormat/DXContainer.h
llvm/include/llvm/TargetParser/Triple.h
llvm/lib/MC/MCDXContainerWriter.cpp
llvm/lib/TargetParser/Triple.cpp
llvm/test/CodeGen/DirectX/embed-dxil.ll
llvm/unittests/Object/DXContainerTest.cpp

Removed: 




diff  --git a/llvm/include/llvm/BinaryFormat/DXContainer.h 
b/llvm/include/llvm/BinaryFormat/DXContainer.h
index 847d8103e6811..013431faff272 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainer.h
+++ b/llvm/include/llvm/BinaryFormat/DXContainer.h
@@ -103,8 +103,8 @@ struct PartHeader {
 
 struct BitcodeHeader {
   uint8_t Magic[4]; // ACSII "DXIL".
-  uint8_t MajorVersion; // DXIL version.
   uint8_t MinorVersion; // DXIL version.
+  uint8_t MajorVersion; // DXIL version.
   uint16_t Unused;
   uint32_t Offset; // Offset to LLVM bitcode (from start of header).
   uint32_t Size;   // Size of LLVM bitcode (in bytes).

diff  --git a/llvm/include/llvm/TargetParser/Triple.h 
b/llvm/include/llvm/TargetParser/Triple.h
index 8f9d99816931a..b3bb354b38ff5 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -429,7 +429,7 @@ class Triple {
   /// (SubArch).  This should only be called with Vulkan SPIR-V triples.
   VersionTuple getVulkanVersion() const;
 
-  /// Parse the DXIL version number from the DXIL version
+  /// Parse the DXIL version number from the OSVersion and DXIL version
   /// (SubArch).  This should only be called with DXIL triples.
   VersionTuple getDXILVersion() const;
 

diff  --git a/llvm/lib/MC/MCDXContainerWriter.cpp 
b/llvm/lib/MC/MCDXContainerWriter.cpp
index ff64c6e538ac6..1d82a7ec849fe 100644
--- a/llvm/lib/MC/MCDXContainerWriter.cpp
+++ b/llvm/lib/MC/MCDXContainerWriter.cpp
@@ -129,6 +129,9 @@ uint64_t DXContainerObjectWriter::writeObject(MCAssembler 
&Asm,
   // The program header's size field is in 32-bit words.
   Header.Size = (SectionSize + sizeof(dxbc::ProgramHeader) + 3) / 4;
   memcpy(Header.Bitcode.Magic, "DXIL", 4);
+  VersionTuple DXILVersion = TT.getDXILVersion();
+  Header.Bitcode.MajorVersion = DXILVersion.getMajor();
+  Header.Bitcode.MinorVersion = DXILVersion.getMinor().value_or(0);
   Header.Bitcode.Offset = sizeof(dxbc::BitcodeHeader);
   Header.Bitcode.Size = SectionSize;
   if (sys::IsBigEndianHost)

diff  --git a/llvm/lib/TargetParser/Triple.cpp 
b/llvm/lib/TargetParser/Triple.cpp
index f8269a51dc0bb..4fc1ff5aaa051 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -1510,6 +1510,8 @@ VersionTuple Triple::getDXILVersion() const {
   if (getArch() != dxil || getOS() != ShaderModel)
 llvm_unreachable("invalid DXIL triple");
   StringRef Arch = getArchName();
+  if (getSubArch() == NoSubArch)
+Arch = getDXILArchNameFromShaderModel(getOSName());
   Arch.consume_front("dxilv");
   VersionTuple DXILVersion = parseVersionFromName(Arch);
   // FIXME: validate DXIL version against Shader Model version.

diff  --git a/llvm/test/CodeGen/DirectX/embed-dxil.ll 
b/llvm/test/CodeGen/DirectX/embed-dxil.ll
index 306e5c385b5a3..9f4fb19d86fa0 100644
--- a/llvm/test/CodeGen/DirectX/embed-dxil.ll
+++ b/llvm/test/CodeGen/DirectX/embed-dxil.ll
@@ -42,8 +42,8 @@ define i32 @add(i32 %a, i32 %b) {
 ; DXC-NEXT:   MinorVersion:5
 ; DXC-NEXT:   ShaderKind:  6
 ; DXC-NEXT:   Size:[[#div(SIZE,4)]]
-; DXC-NEXT:   DXILMajorVersion: [[#]]
-; DXC-NEXT:   DXILMinorVersion: [[#]]
+; DXC-NEXT:   DXILMajorVersion: 1
+; DXC-NEXT:   DXILMinorVersion: 5
 ; DXC-NEXT:   DXILSize:[[#SIZE - 24]]
 ; DXC-NEXT:   DXIL:[ 0x42, 0x43, 0xC0, 0xDE,
 ; DXC:  - Name:SFI0

diff  --git a/llvm/unittests/Object/DXContainerTest.cpp 
b/llvm/unittests/Object/DXContainerTest.cpp
index 115de47a3cefd..b83eecc339081 100644
--- a/llvm/unittests/Object/DXContainerTest.cpp
+++ b/llvm/unittests/Object/DXContainerTest.cpp
@@ -126,6 +126,51 @@ TEST(DXCFile, ParseOverlappingParts) {
   "Part offset for part 1 begins before the previous part ends"));
 }
 
+// This test verify DXILMajorVersion and DXILMinorVersion are correctly parsed.
+// This test is based on the binary output constructed from this yaml.
+// --- !dxcontainer
+// Header:
+//   Hash:[ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
+//  0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
+//   Version:
+// Major:   

[llvm-branch-commits] [clang] [openmp] [Clang][OpenMP] Fix tile/unroll on iterator- and foreach-loops. (PR #91459)

2024-05-13 Thread Alexey Bataev via llvm-branch-commits


@@ -182,17 +182,34 @@ class OMPLoopScope : public 
CodeGenFunction::RunCleanupsScope {
 }
 return false;
   });
-  PreInits = cast_or_null(LD->getPreInits());
+  PreInits = LD->getPreInits();
 } else if (const auto *Tile = dyn_cast(&S)) {
-  PreInits = cast_or_null(Tile->getPreInits());
+  PreInits = Tile->getPreInits();
 } else if (const auto *Unroll = dyn_cast(&S)) {
-  PreInits = cast_or_null(Unroll->getPreInits());
+  PreInits = Unroll->getPreInits();
 } else {
   llvm_unreachable("Unknown loop-based directive kind.");
 }
 if (PreInits) {
-  for (const auto *I : PreInits->decls())
-CGF.EmitVarDecl(cast(*I));
+  // CompoundStmts and DeclStmts are used as lists of PreInit statements 
and
+  // declarations. Since declarations must be visible in the the following
+  // that they initialize, unpack the ComboundStmt they are nested in.
+  SmallVector PreInitStmts;
+  if (auto *PreInitCompound = dyn_cast(PreInits))

alexey-bataev wrote:

Why need to create coumpound stmt? DeclStmt support multiple declarations 
itself.

https://github.com/llvm/llvm-project/pull/91459
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang] Revise IDE folder structure (PR #89743)

2024-05-13 Thread Michael Kruse via llvm-branch-commits

Meinersbur wrote:

@AaronBallman Thanks for having a look.

> With this patch, I get errors when loading a visual studio solution generated 
> with these change, and all of clang's libraries are placed at the top level. 
> The error is a dialog box saying "The solution already contains an item named 
> 'clang'."

I got similar errors with "Unittest" and "UnitTest". I only solved it by using 
"Unit". I am assuming this is because there is something else already with that 
name but inconsistent case. I never for this for "Clang"/"clang", but it could 
be when not all patches from the series are applied. Specifically I think 
clang-tools-extra may use "Clang"/"clang".

> Another thing (that is existing behavior) worth noting is that at some point, 
> we lost the ability to browse directly to files in Visual Studio. Instead of 
> going to `Clang Libraries->clangDriver->Source Files->ToolChain.cpp`, you 
> have to go to `Object Libraries->obj.clangDriver->Source 
> Files->ToolChain.cpp` which is pretty strange. Your patch doesn't change 
> this, but if we're correcting folder structure behavior, we should probably 
> address that at the same time if we can.

This is how CMake handles object libraries. There is one target 
`obj.clangDriver` that builds all the *.obj file, and a library that is not 
used. The target `clangDriver` then has a dependency on `obj.clangDriver` and 
has its *.obj files added, but not the source files. This is to be able to link 
a static library (`clangDriver_static`) and a dynamic library (`clangDriver`) 
at the [same 
time](https://github.com/llvm/llvm-project/blob/ca1bd5995f6ed934f9187305190a5abfac049173/llvm/cmake/modules/AddLLVM.cmake#L593)
 but compiling the source files just once. I don't know the reason, but in 
contrast to other subprojects Clang uses this build mode [even when building 
just one 
library](https://github.com/llvm/llvm-project/blob/ca1bd5995f6ed934f9187305190a5abfac049173/clang/cmake/modules/AddClang.cmake#L102).
 

There is an exception for XCode, and we could do the same for MSVC (or add the 
source files as `ADDITIONAL_HEADERS` to make them show up). However, for this 
patch series I did not intent to change anything about how the build system 
works.

https://github.com/llvm/llvm-project/pull/89743
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [LAA] Use SCEVUse to add extra NUW flags to pointer bounds. (WIP) (PR #91962)

2024-05-13 Thread Florian Hahn via llvm-branch-commits

https://github.com/fhahn created https://github.com/llvm/llvm-project/pull/91962

Use SCEVUse to add a NUW flag to the upper bound of an accessed pointer.
We must already have proved that the pointers do not wrap, as otherwise
we could not use them for runtime check computations.

By adding the use-specific NUW flag, we can detect cases where SCEV can
prove that the compared pointers must overlap, so the runtime checks
will always be false. In that case, there is no point in vectorizing
with runtime checks.

Note that this depends c2895cd27fbf200d1da056bc66d77eeb62690bf0, which
could be submitted separately if desired; without the current change, I
don't think it triggers in practice though.

Depends on https://github.com/llvm/llvm-project/pull/91961

>From 448c6db95cf89b8f6d007f7049afd02ca21d4427 Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Wed, 1 May 2024 11:03:42 +0100
Subject: [PATCH 1/3] [SCEV,LAA] Add tests to make sure scoped SCEVs don't
 impact other SCEVs.

---
 .../LoopAccessAnalysis/scoped-scevs.ll| 182 ++
 1 file changed, 182 insertions(+)
 create mode 100644 llvm/test/Analysis/LoopAccessAnalysis/scoped-scevs.ll

diff --git a/llvm/test/Analysis/LoopAccessAnalysis/scoped-scevs.ll 
b/llvm/test/Analysis/LoopAccessAnalysis/scoped-scevs.ll
new file mode 100644
index 0..323ba2a739cf8
--- /dev/null
+++ b/llvm/test/Analysis/LoopAccessAnalysis/scoped-scevs.ll
@@ -0,0 +1,182 @@
+; NOTE: Assertions have been autogenerated by 
utils/update_analyze_test_checks.py UTC_ARGS: --version 4
+; RUN: opt -passes='print,print' 
-disable-output %s 2>&1 | FileCheck --check-prefixes=LAA,AFTER %s
+; RUN: opt 
-passes='print,print,print' 
-disable-output %s 2>&1 | FileCheck --check-prefixes=BEFORE,LAA,AFTER %s
+
+target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
+
+declare void @use(ptr)
+
+; Check that scoped expressions created by LAA do not interfere with non-scoped
+; SCEVs with the same operands. The tests first run print to
+; populate the SCEV cache. They contain a GEP computing A+405, which is the end
+; of the accessed range, before and/or after the loop. No nuw flags should be
+; added to them in the second print output.
+
+define ptr @test_ptr_range_end_computed_before_and_after_loop(ptr %A) {
+; BEFORE-LABEL: 'test_ptr_range_end_computed_before_and_after_loop'
+; BEFORE-NEXT:  Classifying expressions for: 
@test_ptr_range_end_computed_before_and_after_loop
+; BEFORE:%x = getelementptr inbounds i8, ptr %A, i64 405
+; BEFORE-NEXT:--> (405 + %A) U: full-set S: full-set
+; BEFORE:%y = getelementptr inbounds i8, ptr %A, i64 405
+; BEFORE-NEXT:--> (405 + %A) U: full-set S: full-set
+;
+; LAA-LABEL: 'test_ptr_range_end_computed_before_and_after_loop'
+; LAA-NEXT:loop:
+; LAA-NEXT:  Memory dependences are safe with run-time checks
+; LAA-NEXT:  Dependences:
+; LAA-NEXT:  Run-time memory checks:
+; LAA-NEXT:  Check 0:
+; LAA-NEXT:Comparing group ([[GRP1:0x[0-9a-f]+]]):
+; LAA-NEXT:  %gep.A.400 = getelementptr inbounds i32, ptr %A.1, i64 %iv
+; LAA-NEXT:Against group ([[GRP2:0x[0-9a-f]+]]):
+; LAA-NEXT:  %gep.A = getelementptr inbounds i8, ptr %A, i64 %iv
+; LAA-NEXT:  Grouped accesses:
+; LAA-NEXT:Group [[GRP1]]:
+; LAA-NEXT:  (Low: (1 + %A) High: (405 + %A))
+; LAA-NEXT:Member: {(1 + %A),+,4}<%loop>
+; LAA-NEXT:Group [[GRP2]]:
+; LAA-NEXT:  (Low: %A High: (101 + %A))
+; LAA-NEXT:Member: {%A,+,1}<%loop>
+; LAA-EMPTY:
+; LAA-NEXT:  Non vectorizable stores to invariant address were not found 
in loop.
+; LAA-NEXT:  SCEV assumptions:
+; LAA-EMPTY:
+; LAA-NEXT:  Expressions re-written:
+;
+; AFTER-LABEL: 'test_ptr_range_end_computed_before_and_after_loop'
+; AFTER-NEXT:  Classifying expressions for: 
@test_ptr_range_end_computed_before_and_after_loop
+; AFTER:%x = getelementptr inbounds i8, ptr %A, i64 405
+; AFTER-NEXT:--> (405 + %A) U: full-set S: full-set
+; AFTER:%y = getelementptr inbounds i8, ptr %A, i64 405
+; AFTER-NEXT:--> (405 + %A) U: full-set S: full-set
+entry:
+  %A.1 = getelementptr inbounds i8, ptr %A, i64 1
+  %x = getelementptr inbounds i8, ptr %A, i64 405
+  call void @use(ptr %x)
+  br label %loop
+
+loop:
+  %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
+  %gep.A.400 = getelementptr inbounds i32, ptr %A.1, i64 %iv
+  %gep.A = getelementptr inbounds i8, ptr %A, i64 %iv
+  %l = load i8, ptr %gep.A, align 1
+  %ext = zext i8 %l to i32
+  store i32 %ext, ptr %gep.A.400, align 4
+  %iv.next = add nuw nsw i64 %iv, 1
+  %ec = icmp eq i64 %iv, 100
+  br i1 %ec, label %exit, label %loop
+
+exit:
+  %y = getelementptr inbounds i8, ptr %A, i64 405
+  ret ptr %y
+}
+
+define void @test_ptr_range_end_computed_before_loop(ptr %A) {
+; BEFORE-LABEL: 'test_ptr_range_end_computed_before_loop'
+; BEFORE-NEXT:  Classifying expressions for: 
@test_ptr_range_end_computed_before_loop
+; BEFORE-NEXT:

[llvm-branch-commits] [llvm] [LAA] Use SCEVUse to add extra NUW flags to pointer bounds. (WIP) (PR #91962)

2024-05-13 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-analysis

Author: Florian Hahn (fhahn)


Changes

Use SCEVUse to add a NUW flag to the upper bound of an accessed pointer.
We must already have proved that the pointers do not wrap, as otherwise
we could not use them for runtime check computations.

By adding the use-specific NUW flag, we can detect cases where SCEV can
prove that the compared pointers must overlap, so the runtime checks
will always be false. In that case, there is no point in vectorizing
with runtime checks.

Note that this depends c2895cd27fbf200d1da056bc66d77eeb62690bf0, which
could be submitted separately if desired; without the current change, I
don't think it triggers in practice though.

Depends on https://github.com/llvm/llvm-project/pull/91961

---

Patch is 35.45 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/91962.diff


5 Files Affected:

- (modified) llvm/include/llvm/Analysis/LoopAccessAnalysis.h (+9-5) 
- (modified) llvm/lib/Analysis/LoopAccessAnalysis.cpp (+15-5) 
- (modified) llvm/lib/Analysis/ScalarEvolution.cpp (+15-5) 
- (modified) llvm/test/Analysis/LoopAccessAnalysis/forked-pointers.ll (+67-67) 
- (added) llvm/test/Analysis/LoopAccessAnalysis/scoped-scevs.ll (+149) 


``diff
diff --git a/llvm/include/llvm/Analysis/LoopAccessAnalysis.h 
b/llvm/include/llvm/Analysis/LoopAccessAnalysis.h
index 6ebd0fb8477a0..0663ef6a2865d 100644
--- a/llvm/include/llvm/Analysis/LoopAccessAnalysis.h
+++ b/llvm/include/llvm/Analysis/LoopAccessAnalysis.h
@@ -372,10 +372,10 @@ struct RuntimeCheckingPtrGroup {
 
   /// The SCEV expression which represents the upper bound of all the
   /// pointers in this group.
-  const SCEV *High;
+  SCEVUse High;
   /// The SCEV expression which represents the lower bound of all the
   /// pointers in this group.
-  const SCEV *Low;
+  SCEVUse Low;
   /// Indices of all the pointers that constitute this grouping.
   SmallVector Members;
   /// Address space of the involved pointers.
@@ -413,10 +413,10 @@ class RuntimePointerChecking {
 TrackingVH PointerValue;
 /// Holds the smallest byte address accessed by the pointer throughout all
 /// iterations of the loop.
-const SCEV *Start;
+SCEVUse Start;
 /// Holds the largest byte address accessed by the pointer throughout all
 /// iterations of the loop, plus 1.
-const SCEV *End;
+SCEVUse End;
 /// Holds the information if this pointer is used for writing to memory.
 bool IsWritePtr;
 /// Holds the id of the set of pointers that could be dependent because of 
a
@@ -429,7 +429,7 @@ class RuntimePointerChecking {
 /// True if the pointer expressions needs to be frozen after expansion.
 bool NeedsFreeze;
 
-PointerInfo(Value *PointerValue, const SCEV *Start, const SCEV *End,
+PointerInfo(Value *PointerValue, SCEVUse Start, SCEVUse End,
 bool IsWritePtr, unsigned DependencySetId, unsigned AliasSetId,
 const SCEV *Expr, bool NeedsFreeze)
 : PointerValue(PointerValue), Start(Start), End(End),
@@ -443,8 +443,10 @@ class RuntimePointerChecking {
   /// Reset the state of the pointer runtime information.
   void reset() {
 Need = false;
+AlwaysFalse = false;
 Pointers.clear();
 Checks.clear();
+CheckingGroups.clear();
   }
 
   /// Insert a pointer and calculate the start and end SCEVs.
@@ -501,6 +503,8 @@ class RuntimePointerChecking {
   /// This flag indicates if we need to add the runtime check.
   bool Need = false;
 
+  bool AlwaysFalse = false;
+
   /// Information about the pointers that may require checking.
   SmallVector Pointers;
 
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp 
b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
index e1d0f900c9050..208c034763f7c 100644
--- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -210,8 +210,8 @@ void RuntimePointerChecking::insert(Loop *Lp, Value *Ptr, 
const SCEV *PtrExpr,
 bool NeedsFreeze) {
   ScalarEvolution *SE = PSE.getSE();
 
-  const SCEV *ScStart;
-  const SCEV *ScEnd;
+  SCEVUse ScStart;
+  SCEVUse ScEnd;
 
   if (SE->isLoopInvariant(PtrExpr, Lp)) {
 ScStart = ScEnd = PtrExpr;
@@ -223,6 +223,8 @@ void RuntimePointerChecking::insert(Loop *Lp, Value *Ptr, 
const SCEV *PtrExpr,
 ScStart = AR->getStart();
 ScEnd = AR->evaluateAtIteration(Ex, *SE);
 const SCEV *Step = AR->getStepRecurrence(*SE);
+if (auto *Comm = dyn_cast(ScEnd))
+  ScEnd = SCEVUse(ScEnd, 2);
 
 // For expressions with negative step, the upper bound is ScStart and the
 // lower bound is ScEnd.
@@ -244,7 +246,10 @@ void RuntimePointerChecking::insert(Loop *Lp, Value *Ptr, 
const SCEV *PtrExpr,
   auto &DL = Lp->getHeader()->getModule()->getDataLayout();
   Type *IdxTy = DL.getIndexType(Ptr->getType());
   const SCEV *EltSizeSCEV = SE->getStoreSizeOfExpr(IdxTy, AccessTy);
-  ScEnd = SE->getAddExpr(ScEnd, EltSizeSCEV

[llvm-branch-commits] [llvm] [SCEV] Add option to request use-specific SCEV for a GEP expr (WIP). (PR #91964)

2024-05-13 Thread Florian Hahn via llvm-branch-commits

https://github.com/fhahn created https://github.com/llvm/llvm-project/pull/91964

Use SCEVUse from https://github.com/llvm/llvm-project/pull/91961 to return a 
SCEVUse with use-specific no-wrap flags for GEP expr, when demanded.

Clients need to opt-in, as the use-specific flags may not be valid in some 
contexts (e.g. backedge taken counts).

>From dea2c74ec83f390025cb0389859e472e8676c768 Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Sun, 12 May 2024 09:57:54 +0100
Subject: [PATCH] [SCEV] Add option to request use-specific SCEV for a GEP expr
 (WIP).

Use SCEVUse from https://github.com/llvm/llvm-project/pull/91961 to
return a SCEVUse with use-specific no-wrap flags for GEP expr, when
demanded.

Clients need to opt-in, as the use-specific flags may not be valid in
some contexts (e.g. backedge taken counts).
---
 llvm/include/llvm/Analysis/ScalarEvolution.h  | 14 
 llvm/lib/Analysis/ScalarEvolution.cpp | 36 +++
 .../Analysis/ScalarEvolution/min-max-exprs.ll |  2 +-
 .../ScalarEvolution/no-wrap-add-exprs.ll  | 12 +++
 .../no-wrap-symbolic-becount.ll   |  2 +-
 .../test/Analysis/ScalarEvolution/ptrtoint.ll |  4 +--
 llvm/test/Analysis/ScalarEvolution/sdiv.ll|  2 +-
 llvm/test/Analysis/ScalarEvolution/srem.ll|  2 +-
 8 files changed, 41 insertions(+), 33 deletions(-)

diff --git a/llvm/include/llvm/Analysis/ScalarEvolution.h 
b/llvm/include/llvm/Analysis/ScalarEvolution.h
index 2859df9964555..4ca3dbc1c6703 100644
--- a/llvm/include/llvm/Analysis/ScalarEvolution.h
+++ b/llvm/include/llvm/Analysis/ScalarEvolution.h
@@ -653,7 +653,7 @@ class ScalarEvolution {
 
   /// Return a SCEV expression for the full generality of the specified
   /// expression.
-  SCEVUse getSCEV(Value *V);
+  SCEVUse getSCEV(Value *V, bool UseCtx = false);
 
   /// Return an existing SCEV for V if there is one, otherwise return nullptr.
   SCEVUse getExistingSCEV(Value *V);
@@ -735,9 +735,11 @@ class ScalarEvolution {
   /// \p GEP The GEP. The indices contained in the GEP itself are ignored,
   /// instead we use IndexExprs.
   /// \p IndexExprs The expressions for the indices.
-  SCEVUse getGEPExpr(GEPOperator *GEP, ArrayRef IndexExprs);
+  SCEVUse getGEPExpr(GEPOperator *GEP, ArrayRef IndexExprs,
+ bool UseCtx = false);
   SCEVUse getGEPExpr(GEPOperator *GEP,
- const SmallVectorImpl &IndexExprs);
+ const SmallVectorImpl &IndexExprs,
+ bool UseCtx = false);
   SCEVUse getAbsExpr(SCEVUse Op, bool IsNSW);
   SCEVUse getMinMaxExpr(SCEVTypes Kind, ArrayRef Operands);
   SCEVUse getMinMaxExpr(SCEVTypes Kind, SmallVectorImpl &Operands);
@@ -1783,11 +1785,11 @@ class ScalarEvolution {
 
   /// We know that there is no SCEV for the specified value.  Analyze the
   /// expression recursively.
-  SCEVUse createSCEV(Value *V);
+  SCEVUse createSCEV(Value *V, bool UseCtx = false);
 
   /// We know that there is no SCEV for the specified value. Create a new SCEV
   /// for \p V iteratively.
-  SCEVUse createSCEVIter(Value *V);
+  SCEVUse createSCEVIter(Value *V, bool UseCtx = false);
   /// Collect operands of \p V for which SCEV expressions should be constructed
   /// first. Returns a SCEV directly if it can be constructed trivially for \p
   /// V.
@@ -1826,7 +1828,7 @@ class ScalarEvolution {
Value *FalseVal);
 
   /// Provide the special handling we need to analyze GEP SCEVs.
-  SCEVUse createNodeForGEP(GEPOperator *GEP);
+  SCEVUse createNodeForGEP(GEPOperator *GEP, bool UseCtx = false);
 
   /// Implementation code for getSCEVAtScope; called at most once for each
   /// SCEV+Loop pair.
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp 
b/llvm/lib/Analysis/ScalarEvolution.cpp
index 320be6f26fc0a..68f4ddd47d69a 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -2741,6 +2741,8 @@ SCEVUse 
ScalarEvolution::getAddExpr(SmallVectorImpl &Ops,
 break;
   // If we have an add, expand the add operands onto the end of the 
operands
   // list.
+  // CommonFlags = maskFlags(CommonFlags, setFlags(Add->getNoWrapFlags(),
+  // static_cast(Ops[Idx].getInt(;
   Ops.erase(Ops.begin()+Idx);
   append_range(Ops, Add->operands());
   DeletedAdd = true;
@@ -3759,13 +3761,14 @@ SCEVUse 
ScalarEvolution::getAddRecExpr(SmallVectorImpl &Operands,
 }
 
 SCEVUse ScalarEvolution::getGEPExpr(GEPOperator *GEP,
-ArrayRef IndexExprs) {
-  return getGEPExpr(GEP, SmallVector(IndexExprs));
+ArrayRef IndexExprs,
+bool UseCtx) {
+  return getGEPExpr(GEP, SmallVector(IndexExprs), UseCtx);
 }
 
-SCEVUse
-ScalarEvolution::getGEPExpr(GEPOperator *GEP,
-const SmallVectorImpl &IndexExprs) {
+SCEVUse ScalarEvolution::getGEPExpr(GEPOperator *GEP,
+const

[llvm-branch-commits] [llvm] [SCEV] Add option to request use-specific SCEV for a GEP expr (WIP). (PR #91964)

2024-05-13 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-analysis

Author: Florian Hahn (fhahn)


Changes

Use SCEVUse from https://github.com/llvm/llvm-project/pull/91961 to return a 
SCEVUse with use-specific no-wrap flags for GEP expr, when demanded.

Clients need to opt-in, as the use-specific flags may not be valid in some 
contexts (e.g. backedge taken counts).

---
Full diff: https://github.com/llvm/llvm-project/pull/91964.diff


8 Files Affected:

- (modified) llvm/include/llvm/Analysis/ScalarEvolution.h (+8-6) 
- (modified) llvm/lib/Analysis/ScalarEvolution.cpp (+21-15) 
- (modified) llvm/test/Analysis/ScalarEvolution/min-max-exprs.ll (+1-1) 
- (modified) llvm/test/Analysis/ScalarEvolution/no-wrap-add-exprs.ll (+6-6) 
- (modified) llvm/test/Analysis/ScalarEvolution/no-wrap-symbolic-becount.ll 
(+1-1) 
- (modified) llvm/test/Analysis/ScalarEvolution/ptrtoint.ll (+2-2) 
- (modified) llvm/test/Analysis/ScalarEvolution/sdiv.ll (+1-1) 
- (modified) llvm/test/Analysis/ScalarEvolution/srem.ll (+1-1) 


``diff
diff --git a/llvm/include/llvm/Analysis/ScalarEvolution.h 
b/llvm/include/llvm/Analysis/ScalarEvolution.h
index 2859df9964555..4ca3dbc1c6703 100644
--- a/llvm/include/llvm/Analysis/ScalarEvolution.h
+++ b/llvm/include/llvm/Analysis/ScalarEvolution.h
@@ -653,7 +653,7 @@ class ScalarEvolution {
 
   /// Return a SCEV expression for the full generality of the specified
   /// expression.
-  SCEVUse getSCEV(Value *V);
+  SCEVUse getSCEV(Value *V, bool UseCtx = false);
 
   /// Return an existing SCEV for V if there is one, otherwise return nullptr.
   SCEVUse getExistingSCEV(Value *V);
@@ -735,9 +735,11 @@ class ScalarEvolution {
   /// \p GEP The GEP. The indices contained in the GEP itself are ignored,
   /// instead we use IndexExprs.
   /// \p IndexExprs The expressions for the indices.
-  SCEVUse getGEPExpr(GEPOperator *GEP, ArrayRef IndexExprs);
+  SCEVUse getGEPExpr(GEPOperator *GEP, ArrayRef IndexExprs,
+ bool UseCtx = false);
   SCEVUse getGEPExpr(GEPOperator *GEP,
- const SmallVectorImpl &IndexExprs);
+ const SmallVectorImpl &IndexExprs,
+ bool UseCtx = false);
   SCEVUse getAbsExpr(SCEVUse Op, bool IsNSW);
   SCEVUse getMinMaxExpr(SCEVTypes Kind, ArrayRef Operands);
   SCEVUse getMinMaxExpr(SCEVTypes Kind, SmallVectorImpl &Operands);
@@ -1783,11 +1785,11 @@ class ScalarEvolution {
 
   /// We know that there is no SCEV for the specified value.  Analyze the
   /// expression recursively.
-  SCEVUse createSCEV(Value *V);
+  SCEVUse createSCEV(Value *V, bool UseCtx = false);
 
   /// We know that there is no SCEV for the specified value. Create a new SCEV
   /// for \p V iteratively.
-  SCEVUse createSCEVIter(Value *V);
+  SCEVUse createSCEVIter(Value *V, bool UseCtx = false);
   /// Collect operands of \p V for which SCEV expressions should be constructed
   /// first. Returns a SCEV directly if it can be constructed trivially for \p
   /// V.
@@ -1826,7 +1828,7 @@ class ScalarEvolution {
Value *FalseVal);
 
   /// Provide the special handling we need to analyze GEP SCEVs.
-  SCEVUse createNodeForGEP(GEPOperator *GEP);
+  SCEVUse createNodeForGEP(GEPOperator *GEP, bool UseCtx = false);
 
   /// Implementation code for getSCEVAtScope; called at most once for each
   /// SCEV+Loop pair.
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp 
b/llvm/lib/Analysis/ScalarEvolution.cpp
index 320be6f26fc0a..68f4ddd47d69a 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -2741,6 +2741,8 @@ SCEVUse 
ScalarEvolution::getAddExpr(SmallVectorImpl &Ops,
 break;
   // If we have an add, expand the add operands onto the end of the 
operands
   // list.
+  // CommonFlags = maskFlags(CommonFlags, setFlags(Add->getNoWrapFlags(),
+  // static_cast(Ops[Idx].getInt(;
   Ops.erase(Ops.begin()+Idx);
   append_range(Ops, Add->operands());
   DeletedAdd = true;
@@ -3759,13 +3761,14 @@ SCEVUse 
ScalarEvolution::getAddRecExpr(SmallVectorImpl &Operands,
 }
 
 SCEVUse ScalarEvolution::getGEPExpr(GEPOperator *GEP,
-ArrayRef IndexExprs) {
-  return getGEPExpr(GEP, SmallVector(IndexExprs));
+ArrayRef IndexExprs,
+bool UseCtx) {
+  return getGEPExpr(GEP, SmallVector(IndexExprs), UseCtx);
 }
 
-SCEVUse
-ScalarEvolution::getGEPExpr(GEPOperator *GEP,
-const SmallVectorImpl &IndexExprs) {
+SCEVUse ScalarEvolution::getGEPExpr(GEPOperator *GEP,
+const SmallVectorImpl &IndexExprs,
+bool UseCtx) {
   SCEVUse BaseExpr = getSCEV(GEP->getPointerOperand());
   // getSCEV(Base)->getType() has the same address space as Base->getType()
   // because SCEV::getType() preserves the address space.
@@ -3835,6 +3838,9 @@ ScalarEvolution::getGEPExpr(GEP

[llvm-branch-commits] [libc] ec88e86 - Revert "[libc][POSIX][pthreads] implemented missing pthread_rwlockattr functi…"

2024-05-13 Thread via llvm-branch-commits

Author: Schrodinger ZHU Yifan
Date: 2024-05-13T09:42:22-04:00
New Revision: ec88e86edd6a05bd902e844141a60686e9f9dbc4

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

LOG: Revert "[libc][POSIX][pthreads] implemented missing pthread_rwlockattr 
functi…"

This reverts commit d2676a73336b83607565fb2e4ce61bd67d732b09.

Added: 


Modified: 
libc/config/linux/x86_64/entrypoints.txt
libc/include/pthread.h.def
libc/spec/posix.td
libc/src/pthread/CMakeLists.txt
libc/src/pthread/pthread_rwlockattr_init.cpp
libc/test/src/pthread/CMakeLists.txt
libc/test/src/pthread/pthread_rwlockattr_test.cpp

Removed: 
libc/src/pthread/pthread_rwlockattr_getkind_np.cpp
libc/src/pthread/pthread_rwlockattr_getkind_np.h
libc/src/pthread/pthread_rwlockattr_setkind_np.cpp
libc/src/pthread/pthread_rwlockattr_setkind_np.h



diff  --git a/libc/config/linux/x86_64/entrypoints.txt 
b/libc/config/linux/x86_64/entrypoints.txt
index 155deddaaade3..5e3ddd34fb4dc 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -673,10 +673,8 @@ if(LLVM_LIBC_FULL_BUILD)
 libc.src.pthread.pthread_mutexattr_settype
 libc.src.pthread.pthread_once
 libc.src.pthread.pthread_rwlockattr_destroy
-libc.src.pthread.pthread_rwlockattr_getkind_np
 libc.src.pthread.pthread_rwlockattr_getpshared
 libc.src.pthread.pthread_rwlockattr_init
-libc.src.pthread.pthread_rwlockattr_setkind_np
 libc.src.pthread.pthread_rwlockattr_setpshared
 libc.src.pthread.pthread_setspecific
 

diff  --git a/libc/include/pthread.h.def b/libc/include/pthread.h.def
index d41273b5590ea..a94d770657e10 100644
--- a/libc/include/pthread.h.def
+++ b/libc/include/pthread.h.def
@@ -38,11 +38,6 @@ enum {
 #define PTHREAD_PROCESS_PRIVATE 0
 #define PTHREAD_PROCESS_SHARED 1
 
-#define PTHREAD_RWLOCK_PREFER_READER_NP 0
-#define PTHREAD_RWLOCK_PREFER_WRITER_NP 1
-#define PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP 2
-
-
 %%public_api()
 
 #endif // LLVM_LIBC_PTHREAD_H

diff  --git a/libc/spec/posix.td b/libc/spec/posix.td
index e16353b8142de..e7a0cf883c607 100644
--- a/libc/spec/posix.td
+++ b/libc/spec/posix.td
@@ -1234,11 +1234,6 @@ def POSIX : StandardSpec<"POSIX"> {
   RetValSpec,
   [ArgSpec]
   >,
-  FunctionSpec<
-  "pthread_rwlockattr_getkind_np",
-  RetValSpec,
-  [ArgSpec, ArgSpec]
-  >,
   FunctionSpec<
   "pthread_rwlockattr_getpshared",
   RetValSpec,
@@ -1249,11 +1244,6 @@ def POSIX : StandardSpec<"POSIX"> {
   RetValSpec,
   [ArgSpec]
   >,
-  FunctionSpec<
-  "pthread_rwlockattr_setkind_np",
-  RetValSpec,
-  [ArgSpec, ArgSpec]
-  >,
   FunctionSpec<
   "pthread_rwlockattr_setpshared",
   RetValSpec,

diff  --git a/libc/src/pthread/CMakeLists.txt b/libc/src/pthread/CMakeLists.txt
index e5bebb63c6401..c57475c9114fa 100644
--- a/libc/src/pthread/CMakeLists.txt
+++ b/libc/src/pthread/CMakeLists.txt
@@ -470,16 +470,6 @@ add_entrypoint_object(
 libc.include.pthread
 )
 
-add_entrypoint_object(
-  pthread_rwlockattr_getkind_np
-  SRCS
-pthread_rwlockattr_getkind_np.cpp
-  HDRS
-pthread_rwlockattr_getkind_np.h
-  DEPENDS
-libc.include.pthread
-)
-
 add_entrypoint_object(
   pthread_rwlockattr_getpshared
   SRCS
@@ -500,17 +490,6 @@ add_entrypoint_object(
 libc.include.pthread
 )
 
-add_entrypoint_object(
-  pthread_rwlockattr_setkind_np
-  SRCS
-pthread_rwlockattr_setkind_np.cpp
-  HDRS
-pthread_rwlockattr_setkind_np.h
-  DEPENDS
-libc.include.pthread
-libc.include.errno
-)
-
 add_entrypoint_object(
   pthread_rwlockattr_setpshared
   SRCS

diff  --git a/libc/src/pthread/pthread_rwlockattr_getkind_np.cpp 
b/libc/src/pthread/pthread_rwlockattr_getkind_np.cpp
deleted file mode 100644
index 0c821797b42ca..0
--- a/libc/src/pthread/pthread_rwlockattr_getkind_np.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-//===-- Implementation of the pthread_rwlockattr_getkind_np 
---===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#include "pthread_rwlockattr_getkind_np.h"
-
-#include "src/__support/common.h"
-
-#include  // pthread_rwlockattr_t
-
-namespace LIBC_NAMESPACE {
-
-LLVM_LIBC_FUNCTION(int, pthread_rwlockattr_getkind_np,
-   (const pthread_rwlockattr_t *__restrict attr,
-int *__restrict pref)) {
-  *pref = attr->pref;
-  return 0;
-}
-
-} // namespace LIBC_NAMESPACE

diff  --git a/li

[llvm-branch-commits] [lld] release/18.x: [lld][WebAssembly] Fix test on Windows, use llvm-ar instead of ar (PR #91967)

2024-05-13 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/91967

Backport 4b4763ffebaed9f1fee94b8ad5a1a450a9726683

Requested by: @tstellar

>From 16388668633f61f07b91eaaf9400810cbe19f326 Mon Sep 17 00:00:00 2001
From: Reid Kleckner 
Date: Wed, 24 Jan 2024 11:10:53 -0800
Subject: [PATCH] [lld][WebAssembly] Fix test on Windows, use llvm-ar instead
 of ar

(cherry picked from commit 4b4763ffebaed9f1fee94b8ad5a1a450a9726683)
---
 lld/test/wasm/signature-mismatch.s | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lld/test/wasm/signature-mismatch.s 
b/lld/test/wasm/signature-mismatch.s
index 7dc1b8ced3530..17f805a80727a 100644
--- a/lld/test/wasm/signature-mismatch.s
+++ b/lld/test/wasm/signature-mismatch.s
@@ -9,7 +9,7 @@
 # RUN: obj2yaml %t.reloc.o | FileCheck %s -check-prefix=RELOC
 
 # RUN: rm -f %t.a
-# RUN: ar crS %t.a %t.ret32.o %t.call.o
+# RUN: llvm-ar crS %t.a %t.ret32.o %t.call.o
 # RUN: wasm-ld --export=call_ret32 --export=ret32 -o %t2.wasm %t.main.o %t.a 
2>&1 | FileCheck %s -check-prefix=ARCHIVE
 # RUN: obj2yaml %t2.wasm | FileCheck %s -check-prefix=YAML
 

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] release/18.x: [lld][WebAssembly] Fix test on Windows, use llvm-ar instead of ar (PR #91967)

2024-05-13 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/91967
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] release/18.x: [lld][WebAssembly] Fix test on Windows, use llvm-ar instead of ar (PR #91967)

2024-05-13 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-lld

Author: None (llvmbot)


Changes

Backport 4b4763ffebaed9f1fee94b8ad5a1a450a9726683

Requested by: @tstellar

---
Full diff: https://github.com/llvm/llvm-project/pull/91967.diff


1 Files Affected:

- (modified) lld/test/wasm/signature-mismatch.s (+1-1) 


``diff
diff --git a/lld/test/wasm/signature-mismatch.s 
b/lld/test/wasm/signature-mismatch.s
index 7dc1b8ced3530..17f805a80727a 100644
--- a/lld/test/wasm/signature-mismatch.s
+++ b/lld/test/wasm/signature-mismatch.s
@@ -9,7 +9,7 @@
 # RUN: obj2yaml %t.reloc.o | FileCheck %s -check-prefix=RELOC
 
 # RUN: rm -f %t.a
-# RUN: ar crS %t.a %t.ret32.o %t.call.o
+# RUN: llvm-ar crS %t.a %t.ret32.o %t.call.o
 # RUN: wasm-ld --export=call_ret32 --export=ret32 -o %t2.wasm %t.main.o %t.a 
2>&1 | FileCheck %s -check-prefix=ARCHIVE
 # RUN: obj2yaml %t2.wasm | FileCheck %s -check-prefix=YAML
 

``




https://github.com/llvm/llvm-project/pull/91967
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/18.x: [Clang][Sema] Revise the transformation of CTAD parameters of nested class templates (#91628) (PR #91890)

2024-05-13 Thread Erich Keane via llvm-branch-commits

https://github.com/erichkeane approved this pull request.

This seems useful enough with little enough impact to add to the release 
branch.  If we've got another one coming, I see no reason not to.

https://github.com/llvm/llvm-project/pull/91890
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/18.x: [LV, LAA] Don't vectorize loops with load and store to invar address. (PR #91092)

2024-05-13 Thread via llvm-branch-commits

AtariDreams wrote:

> I wonder why CI doesn't flag this as an ABI-breaking change, given that it 
> modifies members of a class in llvm/include.

If I had to guess it's because some of the padding between the bool element and 
the smallvector is being used for the second bool.

https://github.com/llvm/llvm-project/pull/91092
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/18.x: [LV, LAA] Don't vectorize loops with load and store to invar address. (PR #91092)

2024-05-13 Thread via llvm-branch-commits

AtariDreams wrote:

So the offsets themselves aren't changing 

https://github.com/llvm/llvm-project/pull/91092
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] release/18.x: [lld][WebAssembly] Fix test on Windows, use llvm-ar instead of ar (PR #91967)

2024-05-13 Thread Sam Clegg via llvm-branch-commits

https://github.com/sbc100 approved this pull request.


https://github.com/llvm/llvm-project/pull/91967
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] b00930f - Remove dup test.

2024-05-13 Thread Xiang Li via llvm-branch-commits

Author: Xiang Li
Date: 2024-05-13T12:15:38-04:00
New Revision: b00930fe0583b03da5ddf678b8a19b7e9d46655a

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

LOG: Remove dup test.

Added: 


Modified: 
llvm/unittests/Object/DXContainerTest.cpp

Removed: 




diff  --git a/llvm/unittests/Object/DXContainerTest.cpp 
b/llvm/unittests/Object/DXContainerTest.cpp
index b83eecc339081..9da6543c520c7 100644
--- a/llvm/unittests/Object/DXContainerTest.cpp
+++ b/llvm/unittests/Object/DXContainerTest.cpp
@@ -126,51 +126,6 @@ TEST(DXCFile, ParseOverlappingParts) {
   "Part offset for part 1 begins before the previous part ends"));
 }
 
-// This test verify DXILMajorVersion and DXILMinorVersion are correctly parsed.
-// This test is based on the binary output constructed from this yaml.
-// --- !dxcontainer
-// Header:
-//   Hash:[ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
-//  0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
-//   Version:
-// Major:   1
-// Minor:   0
-//   PartCount:   1
-// Parts:
-//   - Name:DXIL
-// Size:28
-// Program:
-//   MajorVersion:6
-//   MinorVersion:5
-//   ShaderKind:  5
-//   Size:8
-//   DXILMajorVersion: 1
-//   DXILMinorVersion: 5
-//   DXILSize:4
-//   DXIL:[ 0x42, 0x43, 0xC0, 0xDE, ]
-// ...
-TEST(DXCFile, ParseDXILPart) {
-  uint8_t Buffer[] = {
-  0x44, 0x58, 0x42, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
-  0x48, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
-  0x44, 0x58, 0x49, 0x4c, 0x1c, 0x00, 0x00, 0x00, 0x65, 0x00, 0x05, 0x00,
-  0x08, 0x00, 0x00, 0x00, 0x44, 0x58, 0x49, 0x4c, 0x05, 0x01, 0x00, 0x00,
-  0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x42, 0x43, 0xc0, 0xde};
-  DXContainer C =
-  llvm::cantFail(DXContainer::create(getMemoryBuffer<116>(Buffer)));
-  EXPECT_EQ(C.getHeader().PartCount, 1u);
-  const std::optional &DXIL = C.getDXIL();
-  EXPECT_TRUE(DXIL.has_value());
-  dxbc::ProgramHeader Header = DXIL->first;
-  EXPECT_EQ(Header.MajorVersion, 6u);
-  EXPECT_EQ(Header.MinorVersion, 5u);
-  EXPECT_EQ(Header.ShaderKind, 5u);
-  EXPECT_EQ(Header.Size, 8u);
-  EXPECT_EQ(Header.Bitcode.MajorVersion, 1u);
-  EXPECT_EQ(Header.Bitcode.MinorVersion, 5u);
-}
-
 TEST(DXCFile, ParseEmptyParts) {
   uint8_t Buffer[] = {
   0x44, 0x58, 0x42, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -260,6 +215,8 @@ TEST(DXCFile, ParseDXILPart) {
   EXPECT_EQ(Header.getMinorVersion(), 5u);
   EXPECT_EQ(Header.ShaderKind, 5u);
   EXPECT_EQ(Header.Size, 8u);
+  EXPECT_EQ(Header.Bitcode.MajorVersion, 1u);
+  EXPECT_EQ(Header.Bitcode.MinorVersion, 5u);
 }
 
 static Expected



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm][NFC] Document cl::opt MisExpectTolerance and fix typo (PR #90670)

2024-05-13 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/90670


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm][NFC] Document cl::opt MisExpectTolerance and fix typo (PR #90670)

2024-05-13 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/90670


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm][NFC] Document cl::opt MisExpectTolerance and fix typo (PR #90670)

2024-05-13 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi closed 
https://github.com/llvm/llvm-project/pull/90670
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] 7a5f2fb - Revert "[LLD] Implement --enable-non-contiguous-regions (#90007)"

2024-05-13 Thread via llvm-branch-commits

Author: Daniel Thornburgh
Date: 2024-05-13T10:38:10-07:00
New Revision: 7a5f2fb7a1326108258eb614e278810ee84d4bf6

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

LOG: Revert "[LLD] Implement --enable-non-contiguous-regions (#90007)"

This reverts commit 673114447b66335268467396a073cdaaadd0b601.

Added: 


Modified: 
lld/ELF/Config.h
lld/ELF/Driver.cpp
lld/ELF/InputSection.cpp
lld/ELF/InputSection.h
lld/ELF/LinkerScript.cpp
lld/ELF/LinkerScript.h
lld/ELF/Options.td
lld/ELF/OutputSections.cpp
lld/ELF/OutputSections.h
lld/ELF/SyntheticSections.cpp
lld/ELF/SyntheticSections.h
lld/ELF/Writer.cpp
lld/docs/ELF/linker_script.rst
lld/docs/ReleaseNotes.rst
lld/docs/ld.lld.1

Removed: 
lld/test/ELF/linkerscript/enable-non-contiguous-regions-arm-exidx.test
lld/test/ELF/linkerscript/enable-non-contiguous-regions.test



diff  --git a/lld/ELF/Config.h b/lld/ELF/Config.h
index dbb81412453af..c55b547a733c7 100644
--- a/lld/ELF/Config.h
+++ b/lld/ELF/Config.h
@@ -238,7 +238,6 @@ struct Config {
   bool emitLLVM;
   bool emitRelocs;
   bool enableNewDtags;
-  bool enableNonContiguousRegions;
   bool executeOnly;
   bool exportDynamic;
   bool fixCortexA53Errata843419;

diff  --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 828499fa05a34..dd33f4bd772f2 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -1250,8 +1250,6 @@ static void readConfigs(opt::InputArgList &args) {
   config->emitRelocs = args.hasArg(OPT_emit_relocs);
   config->enableNewDtags =
   args.hasFlag(OPT_enable_new_dtags, OPT_disable_new_dtags, true);
-  config->enableNonContiguousRegions =
-  args.hasArg(OPT_enable_non_contiguous_regions);
   config->entry = args.getLastArgValue(OPT_entry);
 
   errorHandler().errorHandlingScript =
@@ -3087,7 +3085,7 @@ template  void 
LinkerDriver::link(opt::InputArgList &args) {
 // sectionBases.
 for (SectionCommand *cmd : script->sectionCommands)
   if (auto *osd = dyn_cast(cmd))
-osd->osec.finalizeInputSections(script.get());
+osd->osec.finalizeInputSections();
   }
 
   // Two input sections with 
diff erent output sections should not be folded.

diff  --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index 2a1ccd997f8bc..fa81611e7c9e7 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -161,7 +161,6 @@ uint64_t SectionBase::getOffset(uint64_t offset) const {
   }
   case Regular:
   case Synthetic:
-  case Spill:
 return cast(this)->outSecOff + offset;
   case EHFrame: {
 // Two code paths may reach here. First, clang_rt.crtbegin.o and GCC
@@ -310,12 +309,6 @@ std::string InputSectionBase::getObjMsg(uint64_t off) 
const {
   .str();
 }
 
-PotentialSpillSection::PotentialSpillSection(const InputSectionBase &source,
- InputSectionDescription &isd)
-: InputSection(source.file, source.flags, source.type, source.addralign, 
{},
-   source.name, SectionBase::Spill),
-  isd(&isd) {}
-
 InputSection InputSection::discarded(nullptr, 0, 0, 0, ArrayRef(), 
"");
 
 InputSection::InputSection(InputFile *f, uint64_t flags, uint32_t type,

diff  --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h
index 58e5306fd6dcd..1fb7077ca435b 100644
--- a/lld/ELF/InputSection.h
+++ b/lld/ELF/InputSection.h
@@ -48,7 +48,7 @@ template  struct RelsOrRelas {
 // sections.
 class SectionBase {
 public:
-  enum Kind { Regular, Synthetic, Spill, EHFrame, Merge, Output };
+  enum Kind { Regular, Synthetic, EHFrame, Merge, Output };
 
   Kind kind() const { return (Kind)sectionKind; }
 
@@ -382,8 +382,7 @@ class InputSection : public InputSectionBase {
 
   static bool classof(const SectionBase *s) {
 return s->kind() == SectionBase::Regular ||
-   s->kind() == SectionBase::Synthetic ||
-   s->kind() == SectionBase::Spill;
+   s->kind() == SectionBase::Synthetic;
   }
 
   // Write this section to a mmap'ed file, assuming Buf is pointing to
@@ -426,26 +425,6 @@ class InputSection : public InputSectionBase {
   template  void copyShtGroup(uint8_t *buf);
 };
 
-// A marker for a potential spill location for another input section. This
-// broadly acts as if it were the original section until address assignment.
-// Then it is either replaced with the real input section or removed.
-class PotentialSpillSection : public InputSection {
-public:
-  // The containing input section description; used to quickly replace this 
stub
-  // with the actual section.
-  InputSectionDescription *isd;
-
-  // Next potential spill location for the same source input section.
-  PotentialSpillSection *next = nullptr;
-
-  PotentialSpillSection(const InputSectionBase &source,
-

[llvm-branch-commits] [BOLT] Use aggregated FuncBranchData in writeBATYAML (PR #91289)

2024-05-13 Thread Alexander Yermolovich via llvm-branch-commits


@@ -2386,25 +2362,26 @@ std::error_code 
DataAggregator::writeBATYAML(BinaryContext &BC,
 return std::pair(BlockIt->first, BlockIt->second.getBBIndex());
   };
 
-  for (const auto &[FromOffset, SuccKV] : Branches.IntraIndex) {
-const auto &[_, Index] = getBlock(FromOffset);
-yaml::bolt::BinaryBasicBlockProfile &YamlBB = YamlBF.Blocks[Index];
-for (const auto &[SuccOffset, SuccDataIdx] : SuccKV)
-  if (BlockMap.isInputBlock(SuccOffset))
-YamlBB.Successors.emplace_back(
-getSuccessorInfo(SuccOffset, SuccDataIdx));
-  }
-  for (const auto &[FromOffset, CallTo] : Branches.InterIndex) {
-const auto &[BlockOffset, BlockIndex] = getBlock(FromOffset);
-yaml::bolt::BinaryBasicBlockProfile &YamlBB = 
YamlBF.Blocks[BlockIndex];
-const uint32_t Offset = FromOffset - BlockOffset;
-for (const auto &[CallToLoc, CallToIdx] : CallTo)
-  YamlBB.CallSites.emplace_back(
-  getCallSiteInfo(CallToLoc, CallToIdx, Offset));
-llvm::sort(YamlBB.CallSites, [](yaml::bolt::CallSiteInfo &A,
-yaml::bolt::CallSiteInfo &B) {
-  return A.Offset < B.Offset;
-});
+  for (const llvm::bolt::BranchInfo &BI : Branches.Data) {
+using namespace yaml::bolt;
+const auto &[BlockOffset, BlockIndex] = getBlock(BI.From.Offset);
+BinaryBasicBlockProfile &YamlBB = YamlBF.Blocks[BlockIndex];
+if (BI.To.IsSymbol && BI.To.Name == BI.From.Name && BI.To.Offset != 0) 
{
+  // Internal branch
+  const unsigned SuccIndex = getBlock(BI.To.Offset).second;
+  auto &SI = YamlBB.Successors.emplace_back(SuccessorInfo{SuccIndex});
+  SI.Count = BI.Branches;

ayermolo wrote:

Why can't this be part of constructor?

https://github.com/llvm/llvm-project/pull/91289
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] 32a4fd6 - Revert "[mlir][vector] Add Vector-dialect interleave-to-shuffle pattern, enab…"

2024-05-13 Thread via llvm-branch-commits

Author: Benoit Jacob
Date: 2024-05-13T13:43:40-04:00
New Revision: 32a4fd693ac0920cdf3410884494abfee6ac02d4

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

LOG: Revert "[mlir][vector] Add Vector-dialect interleave-to-shuffle pattern, 
enab…"

This reverts commit cf40c93b5be5cd0011ebbf3a9eead224f7b7079a.

Added: 


Modified: 
mlir/include/mlir/Dialect/Vector/TransformOps/VectorTransformOps.td
mlir/include/mlir/Dialect/Vector/Transforms/LoweringPatterns.h
mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
mlir/lib/Dialect/Vector/TransformOps/VectorTransformOps.cpp
mlir/lib/Dialect/Vector/Transforms/LowerVectorInterleave.cpp

Removed: 
mlir/test/Dialect/Vector/vector-interleave-to-shuffle.mlir



diff  --git 
a/mlir/include/mlir/Dialect/Vector/TransformOps/VectorTransformOps.td 
b/mlir/include/mlir/Dialect/Vector/TransformOps/VectorTransformOps.td
index bc3c16d40520e..f6371f39c3944 100644
--- a/mlir/include/mlir/Dialect/Vector/TransformOps/VectorTransformOps.td
+++ b/mlir/include/mlir/Dialect/Vector/TransformOps/VectorTransformOps.td
@@ -306,20 +306,6 @@ def ApplyLowerInterleavePatternsOp : Op]> {
-  let description = [{
-Indicates that 1D vector interleave operations should be rewritten as
-vector shuffle operations.
-
-This is motivated by some current codegen backends not handling vector
-interleave operations.
-  }];
-
-  let assemblyFormat = "attr-dict";
-}
-
 def ApplyRewriteNarrowTypePatternsOp : Op]> {

diff  --git a/mlir/include/mlir/Dialect/Vector/Transforms/LoweringPatterns.h 
b/mlir/include/mlir/Dialect/Vector/Transforms/LoweringPatterns.h
index 8fd9904fabc0e..350d2777cadf5 100644
--- a/mlir/include/mlir/Dialect/Vector/Transforms/LoweringPatterns.h
+++ b/mlir/include/mlir/Dialect/Vector/Transforms/LoweringPatterns.h
@@ -273,9 +273,6 @@ void 
populateVectorInterleaveLoweringPatterns(RewritePatternSet &patterns,
   int64_t targetRank = 1,
   PatternBenefit benefit = 1);
 
-void populateVectorInterleaveToShufflePatterns(RewritePatternSet &patterns,
-   PatternBenefit benefit = 1);
-
 } // namespace vector
 } // namespace mlir
 #endif // MLIR_DIALECT_VECTOR_TRANSFORMS_LOWERINGPATTERNS_H

diff  --git a/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp 
b/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
index c2dd37f481466..868a3521e7a0f 100644
--- a/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
+++ b/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
@@ -18,7 +18,6 @@
 #include "mlir/Dialect/SPIRV/IR/SPIRVTypes.h"
 #include "mlir/Dialect/SPIRV/Transforms/SPIRVConversion.h"
 #include "mlir/Dialect/Vector/IR/VectorOps.h"
-#include "mlir/Dialect/Vector/Transforms/LoweringPatterns.h"
 #include "mlir/IR/Attributes.h"
 #include "mlir/IR/BuiltinAttributes.h"
 #include "mlir/IR/BuiltinTypes.h"
@@ -829,9 +828,6 @@ void mlir::populateVectorToSPIRVPatterns(SPIRVTypeConverter 
&typeConverter,
   // than the generic one that extracts all elements.
   patterns.add(typeConverter, 
patterns.getContext(),
PatternBenefit(2));
-
-  // Need this until vector.interleave is handled.
-  vector::populateVectorInterleaveToShufflePatterns(patterns);
 }
 
 void mlir::populateVectorReductionToSPIRVDotProductPatterns(

diff  --git a/mlir/lib/Dialect/Vector/TransformOps/VectorTransformOps.cpp 
b/mlir/lib/Dialect/Vector/TransformOps/VectorTransformOps.cpp
index 61fd6bd972e3a..885644864c0f7 100644
--- a/mlir/lib/Dialect/Vector/TransformOps/VectorTransformOps.cpp
+++ b/mlir/lib/Dialect/Vector/TransformOps/VectorTransformOps.cpp
@@ -164,11 +164,6 @@ void 
transform::ApplyLowerInterleavePatternsOp::populatePatterns(
   vector::populateVectorInterleaveLoweringPatterns(patterns);
 }
 
-void transform::ApplyInterleaveToShufflePatternsOp::populatePatterns(
-RewritePatternSet &patterns) {
-  vector::populateVectorInterleaveToShufflePatterns(patterns);
-}
-
 void transform::ApplyRewriteNarrowTypePatternsOp::populatePatterns(
 RewritePatternSet &patterns) {
   populateVectorNarrowTypeRewritePatterns(patterns);

diff  --git a/mlir/lib/Dialect/Vector/Transforms/LowerVectorInterleave.cpp 
b/mlir/lib/Dialect/Vector/Transforms/LowerVectorInterleave.cpp
index 5326760c9b4eb..3a456076f8fba 100644
--- a/mlir/lib/Dialect/Vector/Transforms/LowerVectorInterleave.cpp
+++ b/mlir/lib/Dialect/Vector/Transforms/LowerVectorInterleave.cpp
@@ -16,7 +16,6 @@
 #include "mlir/Dialect/Vector/Utils/VectorUtils.h"
 #include "mlir/IR/BuiltinTypes.h"
 #include "mlir/IR/PatternMatch.h"
-#include "mlir/Support/LogicalResult.h"
 
 #define DEBUG_TYPE "vector-interleave-lowering"
 
@@ -78,49 +77,9 @@ class UnrollInterlea

[llvm-branch-commits] [lld] [llvm] release/18.x: [RISCV][lld] Set the type of TLSDESC relocation's referenced local symbol to STT_NOTYPE (PR #91678)

2024-05-13 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/91678

>From 9c6b3b2733a99543b19e3cd38752ebd99188bd6d Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Fri, 22 Mar 2024 12:27:41 -0700
Subject: [PATCH] [RISCV][lld] Set the type of TLSDESC relocation's referenced
 local symbol to STT_NOTYPE

When adding fixups for RISCV_TLSDESC_ADD_LO and RISCV_TLSDESC_LOAD_LO,
the local label added for RISCV TLSDESC relocations have STT_TLS set,
which is incorrect. Instead, these labels should have `STT_NOTYPE`.

This patch stops adding such fixups and avoid setting the STT_TLS on
these symbols. Failing to do so can cause LLD to emit an error `has an
STT_TLS symbol but doesn't have an SHF_TLS section`. We additionally,
adjust how LLD services these relocations to avoid errors with
incompatible relocation and symbol types.

Reviewers: topperc, MaskRay

Reviewed By: MaskRay

Pull Request: https://github.com/llvm/llvm-project/pull/85817

(cherry picked from commit dfe4ca9b7f4a422500d78280dc5eefd1979939e6)
---
 lld/ELF/Relocations.cpp   |  5 +++-
 lld/test/ELF/riscv-tlsdesc-relax.s|  8 ++
 lld/test/ELF/riscv-tlsdesc.s  | 27 +++
 .../Target/RISCV/MCTargetDesc/RISCVMCExpr.cpp |  2 --
 4 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 619fbaf5dc545..92a1b9baaca3d 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -1480,7 +1480,10 @@ template  void 
RelocationScanner::scanOne(RelTy *&i) {
 
   // Process TLS relocations, including TLS optimizations. Note that
   // R_TPREL and R_TPREL_NEG relocations are resolved in processAux.
-  if (sym.isTls()) {
+  //
+  // Some RISCV TLSDESC relocations reference a local NOTYPE symbol,
+  // but we need to process them in handleTlsRelocation.
+  if (sym.isTls() || oneof(expr)) {
 if (unsigned processed =
 handleTlsRelocation(type, sym, *sec, offset, addend, expr)) {
   i += processed - 1;
diff --git a/lld/test/ELF/riscv-tlsdesc-relax.s 
b/lld/test/ELF/riscv-tlsdesc-relax.s
index fb24317e6535c..5718d4175be11 100644
--- a/lld/test/ELF/riscv-tlsdesc-relax.s
+++ b/lld/test/ELF/riscv-tlsdesc-relax.s
@@ -33,12 +33,14 @@
 # GD64-NEXT: c.add   a0, tp
 # GD64-NEXT: jal {{.*}} 
 ## &.got[c]-. = 0x20c0+8 - 0x1020 = 0x10a8
+# GD64-LABEL: <.Ltlsdesc_hi1>:
 # GD64-NEXT:   1020: auipc   a4, 0x1
 # GD64-NEXT: ld  a5, 0xa8(a4)
 # GD64-NEXT: addia0, a4, 0xa8
 # GD64-NEXT: jalrt0, 0x0(a5)
 # GD64-NEXT: c.add   a0, tp
 ## &.got[c]-. = 0x20c0+8 - 0x1032 = 0x1096
+# GD64-LABEL: <.Ltlsdesc_hi2>:
 # GD64-NEXT:   1032: auipc   a6, 0x1
 # GD64-NEXT: ld  a7, 0x96(a6)
 # GD64-NEXT: addia0, a6, 0x96
@@ -64,6 +66,7 @@
 # LE64-NEXT: jal {{.*}} 
 # LE64-NEXT: R_RISCV_JAL foo
 # LE64-NEXT: R_RISCV_RELAX *ABS*
+# LE64-LABEL: <.Ltlsdesc_hi1>:
 # LE64-NEXT: addia0, zero, 0x7ff
 # LE64-NEXT: R_RISCV_TLSDESC_HI20 b
 # LE64-NEXT: R_RISCV_RELAX *ABS*
@@ -71,6 +74,7 @@
 # LE64-NEXT: R_RISCV_TLSDESC_ADD_LO12 .Ltlsdesc_hi1
 # LE64-NEXT: R_RISCV_TLSDESC_CALL .Ltlsdesc_hi1
 # LE64-NEXT: c.add   a0, tp
+# LE64-LABEL: <.Ltlsdesc_hi2>:
 # LE64-NEXT: addizero, zero, 0x0
 # LE64-NEXT: R_RISCV_TLSDESC_HI20 b
 # LE64-NEXT: addizero, zero, 0x0
@@ -93,9 +97,11 @@
 # LE64A-NEXT: addia0, a0, -0x479
 # LE64A-NEXT: c.add   a0, tp
 # LE64A-NEXT: jal {{.*}} 
+# LE64A-LABEL: <.Ltlsdesc_hi1>:
 # LE64A-NEXT: lui a0, 0x2
 # LE64A-NEXT: addia0, a0, -0x479
 # LE64A-NEXT: c.add   a0, tp
+# LE64A-LABEL: <.Ltlsdesc_hi2>:
 # LE64A-NEXT: addizero, zero, 0x0
 # LE64A-NEXT: addizero, zero, 0x0
 # LE64A-NEXT: lui a0, 0x2
@@ -115,10 +121,12 @@
 # IE64-NEXT: c.add   a0, tp
 # IE64-NEXT: jal {{.*}} 
 ## &.got[c]-. = 0x120e0+8 - 0x11018 = 0x10d0
+# IE64-LABEL: <.Ltlsdesc_hi1>:
 # IE64-NEXT:  11018: auipc   a0, 0x1
 # IE64-NEXT: ld  a0, 0xd0(a0)
 # IE64-NEXT: c.add   a0, tp
 ## &.got[c]-. = 0x120e0+8 - 0x1102a = 0x10be
+# IE64-LABEL: <.Ltlsdesc_hi2>:
 # IE64-NEXT: addizero, zero, 0x0
 # IE64-NEXT: addizero, zero, 0x0
 # IE64-NEXT:  1102a: auipc   a0, 0x1
diff --git a/lld/test/ELF/riscv-tlsdesc.s b/lld/test/ELF/riscv-tlsdesc.s
index c583e15cf30ce..935ecbddfbfff 100644
--- a/lld/test/ELF/riscv-tlsdesc.s
+++ b/lld/test/ELF/riscv-tlsdesc.s
@@ -29,11 +29,13 @@
 # RUN: ld.lld -e 0 -z now a.32.o c.32.so -o a.32.ie
 # RUN: llvm-objdump --no-show-raw-insn -M no-aliases -h -d a.32.ie | FileCheck 
%s --check-prefix=IE32
 
-# RUN: llvm-mc -triple=riscv64 -filetype=obj d.s -o d.64.o
-# RUN: not ld.lld -shared -soname=d.64.so -o d.64.so d.64.o 2>&1 | FileCheck 
%s --ch

[llvm-branch-commits] [BOLT] Use aggregated FuncBranchData in writeBATYAML (PR #91289)

2024-05-13 Thread Amir Ayupov via llvm-branch-commits


@@ -2386,25 +2362,26 @@ std::error_code 
DataAggregator::writeBATYAML(BinaryContext &BC,
 return std::pair(BlockIt->first, BlockIt->second.getBBIndex());
   };
 
-  for (const auto &[FromOffset, SuccKV] : Branches.IntraIndex) {
-const auto &[_, Index] = getBlock(FromOffset);
-yaml::bolt::BinaryBasicBlockProfile &YamlBB = YamlBF.Blocks[Index];
-for (const auto &[SuccOffset, SuccDataIdx] : SuccKV)
-  if (BlockMap.isInputBlock(SuccOffset))
-YamlBB.Successors.emplace_back(
-getSuccessorInfo(SuccOffset, SuccDataIdx));
-  }
-  for (const auto &[FromOffset, CallTo] : Branches.InterIndex) {
-const auto &[BlockOffset, BlockIndex] = getBlock(FromOffset);
-yaml::bolt::BinaryBasicBlockProfile &YamlBB = 
YamlBF.Blocks[BlockIndex];
-const uint32_t Offset = FromOffset - BlockOffset;
-for (const auto &[CallToLoc, CallToIdx] : CallTo)
-  YamlBB.CallSites.emplace_back(
-  getCallSiteInfo(CallToLoc, CallToIdx, Offset));
-llvm::sort(YamlBB.CallSites, [](yaml::bolt::CallSiteInfo &A,
-yaml::bolt::CallSiteInfo &B) {
-  return A.Offset < B.Offset;
-});
+  for (const llvm::bolt::BranchInfo &BI : Branches.Data) {
+using namespace yaml::bolt;
+const auto &[BlockOffset, BlockIndex] = getBlock(BI.From.Offset);
+BinaryBasicBlockProfile &YamlBB = YamlBF.Blocks[BlockIndex];
+if (BI.To.IsSymbol && BI.To.Name == BI.From.Name && BI.To.Offset != 0) 
{
+  // Internal branch
+  const unsigned SuccIndex = getBlock(BI.To.Offset).second;
+  auto &SI = YamlBB.Successors.emplace_back(SuccessorInfo{SuccIndex});
+  SI.Count = BI.Branches;

aaupov wrote:

It can, but I decided to keep it this way for two reasons:
1) type impedance (int vs uint) between BI and SI requiring a cast
2) making it explicit where Branches and Mispreds are assigned (vs implicitly 
in constructor parameter order).

https://github.com/llvm/llvm-project/pull/91289
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [BOLT] Use aggregated FuncBranchData in writeBATYAML (PR #91289)

2024-05-13 Thread Maksim Panchenko via llvm-branch-commits

https://github.com/maksfb edited https://github.com/llvm/llvm-project/pull/91289
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [BOLT] Use aggregated FuncBranchData in writeBATYAML (PR #91289)

2024-05-13 Thread Maksim Panchenko via llvm-branch-commits

https://github.com/maksfb approved this pull request.

Looks good on my end.

https://github.com/llvm/llvm-project/pull/91289
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [BOLT] Use aggregated FuncBranchData in writeBATYAML (PR #91289)

2024-05-13 Thread Maksim Panchenko via llvm-branch-commits


@@ -2386,25 +2362,26 @@ std::error_code 
DataAggregator::writeBATYAML(BinaryContext &BC,
 return std::pair(BlockIt->first, BlockIt->second.getBBIndex());
   };
 
-  for (const auto &[FromOffset, SuccKV] : Branches.IntraIndex) {
-const auto &[_, Index] = getBlock(FromOffset);
-yaml::bolt::BinaryBasicBlockProfile &YamlBB = YamlBF.Blocks[Index];
-for (const auto &[SuccOffset, SuccDataIdx] : SuccKV)
-  if (BlockMap.isInputBlock(SuccOffset))
-YamlBB.Successors.emplace_back(
-getSuccessorInfo(SuccOffset, SuccDataIdx));
-  }
-  for (const auto &[FromOffset, CallTo] : Branches.InterIndex) {
-const auto &[BlockOffset, BlockIndex] = getBlock(FromOffset);
-yaml::bolt::BinaryBasicBlockProfile &YamlBB = 
YamlBF.Blocks[BlockIndex];
-const uint32_t Offset = FromOffset - BlockOffset;
-for (const auto &[CallToLoc, CallToIdx] : CallTo)
-  YamlBB.CallSites.emplace_back(
-  getCallSiteInfo(CallToLoc, CallToIdx, Offset));
-llvm::sort(YamlBB.CallSites, [](yaml::bolt::CallSiteInfo &A,
-yaml::bolt::CallSiteInfo &B) {
-  return A.Offset < B.Offset;
-});
+  for (const llvm::bolt::BranchInfo &BI : Branches.Data) {

maksfb wrote:

nit: no need for `llvm::bolt::`.

https://github.com/llvm/llvm-project/pull/91289
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [BOLT] Use aggregated FuncBranchData in writeBATYAML (PR #91289)

2024-05-13 Thread Amir Ayupov via llvm-branch-commits


@@ -2386,25 +2362,26 @@ std::error_code 
DataAggregator::writeBATYAML(BinaryContext &BC,
 return std::pair(BlockIt->first, BlockIt->second.getBBIndex());
   };
 
-  for (const auto &[FromOffset, SuccKV] : Branches.IntraIndex) {
-const auto &[_, Index] = getBlock(FromOffset);
-yaml::bolt::BinaryBasicBlockProfile &YamlBB = YamlBF.Blocks[Index];
-for (const auto &[SuccOffset, SuccDataIdx] : SuccKV)
-  if (BlockMap.isInputBlock(SuccOffset))
-YamlBB.Successors.emplace_back(
-getSuccessorInfo(SuccOffset, SuccDataIdx));
-  }
-  for (const auto &[FromOffset, CallTo] : Branches.InterIndex) {
-const auto &[BlockOffset, BlockIndex] = getBlock(FromOffset);
-yaml::bolt::BinaryBasicBlockProfile &YamlBB = 
YamlBF.Blocks[BlockIndex];
-const uint32_t Offset = FromOffset - BlockOffset;
-for (const auto &[CallToLoc, CallToIdx] : CallTo)
-  YamlBB.CallSites.emplace_back(
-  getCallSiteInfo(CallToLoc, CallToIdx, Offset));
-llvm::sort(YamlBB.CallSites, [](yaml::bolt::CallSiteInfo &A,
-yaml::bolt::CallSiteInfo &B) {
-  return A.Offset < B.Offset;
-});
+  for (const llvm::bolt::BranchInfo &BI : Branches.Data) {

aaupov wrote:

Unfortunately we need a FQ name:
`llvm::bolt::BranchInfo`:
https://github.com/llvm/llvm-project/blob/5944579ab20cfcb6d1a9d1a2fe3d4b478ea24c64/bolt/include/bolt/Profile/DataReader.h#L78
```
`llvm::bolt::DataAggregator::BranchInfo`:
https://github.com/llvm/llvm-project/blob/5944579ab20cfcb6d1a9d1a2fe3d4b478ea24c64/bolt/include/bolt/Profile/DataAggregator.h#L125

I thought about renaming the latter to `TakenInfo` to match its counterpart 
`FTInfo`: 
https://github.com/llvm/llvm-project/blob/5944579ab20cfcb6d1a9d1a2fe3d4b478ea24c64/bolt/include/bolt/Profile/DataAggregator.h#L120
WDYT?

https://github.com/llvm/llvm-project/pull/91289
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [BOLT] Use aggregated FuncBranchData in writeBATYAML (PR #91289)

2024-05-13 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov edited https://github.com/llvm/llvm-project/pull/91289
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [BOLT][NFC] Rename DataAggregator::BranchInfo to TakenInfo (PR #92017)

2024-05-13 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov created 
https://github.com/llvm/llvm-project/pull/92017

Avoid name aliasing with llvm::bolt::BranchInfo, drop namespace
specifier.

Test Plan: NFC



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [BOLT] Use aggregated FuncBranchData in writeBATYAML (PR #91289)

2024-05-13 Thread Amir Ayupov via llvm-branch-commits


@@ -2386,25 +2362,26 @@ std::error_code 
DataAggregator::writeBATYAML(BinaryContext &BC,
 return std::pair(BlockIt->first, BlockIt->second.getBBIndex());
   };
 
-  for (const auto &[FromOffset, SuccKV] : Branches.IntraIndex) {
-const auto &[_, Index] = getBlock(FromOffset);
-yaml::bolt::BinaryBasicBlockProfile &YamlBB = YamlBF.Blocks[Index];
-for (const auto &[SuccOffset, SuccDataIdx] : SuccKV)
-  if (BlockMap.isInputBlock(SuccOffset))
-YamlBB.Successors.emplace_back(
-getSuccessorInfo(SuccOffset, SuccDataIdx));
-  }
-  for (const auto &[FromOffset, CallTo] : Branches.InterIndex) {
-const auto &[BlockOffset, BlockIndex] = getBlock(FromOffset);
-yaml::bolt::BinaryBasicBlockProfile &YamlBB = 
YamlBF.Blocks[BlockIndex];
-const uint32_t Offset = FromOffset - BlockOffset;
-for (const auto &[CallToLoc, CallToIdx] : CallTo)
-  YamlBB.CallSites.emplace_back(
-  getCallSiteInfo(CallToLoc, CallToIdx, Offset));
-llvm::sort(YamlBB.CallSites, [](yaml::bolt::CallSiteInfo &A,
-yaml::bolt::CallSiteInfo &B) {
-  return A.Offset < B.Offset;
-});
+  for (const llvm::bolt::BranchInfo &BI : Branches.Data) {

aaupov wrote:

Dropped in follow-up diff https://github.com/llvm/llvm-project/pull/92017.

https://github.com/llvm/llvm-project/pull/91289
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [BOLT][NFC] Rename DataAggregator::BranchInfo to TakenInfo (PR #92017)

2024-05-13 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-bolt

Author: Amir Ayupov (aaupov)


Changes

Avoid name aliasing with llvm::bolt::BranchInfo, drop namespace
specifier.

Test Plan: NFC


---
Full diff: https://github.com/llvm/llvm-project/pull/92017.diff


2 Files Affected:

- (modified) bolt/include/bolt/Profile/DataAggregator.h (+2-2) 
- (modified) bolt/lib/Profile/DataAggregator.cpp (+6-6) 


``diff
diff --git a/bolt/include/bolt/Profile/DataAggregator.h 
b/bolt/include/bolt/Profile/DataAggregator.h
index f2fa59bcaa1a3..48f01511f4827 100644
--- a/bolt/include/bolt/Profile/DataAggregator.h
+++ b/bolt/include/bolt/Profile/DataAggregator.h
@@ -122,14 +122,14 @@ class DataAggregator : public DataReader {
 uint64_t ExternCount{0};
   };
 
-  struct BranchInfo {
+  struct TakenInfo {
 uint64_t TakenCount{0};
 uint64_t MispredCount{0};
   };
 
   /// Intermediate storage for profile data. We save the results of parsing
   /// and use them later for processing and assigning profile.
-  std::unordered_map BranchLBRs;
+  std::unordered_map BranchLBRs;
   std::unordered_map FallthroughLBRs;
   std::vector AggregatedLBRs;
   std::unordered_map BasicSamples;
diff --git a/bolt/lib/Profile/DataAggregator.cpp 
b/bolt/lib/Profile/DataAggregator.cpp
index 167899ccba125..0e11963c676f0 100644
--- a/bolt/lib/Profile/DataAggregator.cpp
+++ b/bolt/lib/Profile/DataAggregator.cpp
@@ -1464,7 +1464,7 @@ uint64_t DataAggregator::parseLBRSample(const 
PerfBranchSample &Sample,
 uint64_t To = getBinaryFunctionContainingAddress(LBR.To) ? LBR.To : 0;
 if (!From && !To)
   continue;
-BranchInfo &Info = BranchLBRs[Trace(From, To)];
+TakenInfo &Info = BranchLBRs[Trace(From, To)];
 ++Info.TakenCount;
 Info.MispredCount += LBR.Mispred;
   }
@@ -1609,7 +1609,7 @@ void DataAggregator::processBranchEvents() {
 
   for (const auto &AggrLBR : BranchLBRs) {
 const Trace &Loc = AggrLBR.first;
-const BranchInfo &Info = AggrLBR.second;
+const TakenInfo &Info = AggrLBR.second;
 doBranch(Loc.From, Loc.To, Info.TakenCount, Info.MispredCount);
   }
 }
@@ -2253,13 +2253,13 @@ DataAggregator::writeAggregatedFile(StringRef 
OutputFilename) const {
   } else {
 for (const auto &KV : NamesToBranches) {
   const FuncBranchData &FBD = KV.second;
-  for (const llvm::bolt::BranchInfo &BI : FBD.Data) {
+  for (const BranchInfo &BI : FBD.Data) {
 writeLocation(BI.From);
 writeLocation(BI.To);
 OutFile << BI.Mispreds << " " << BI.Branches << "\n";
 ++BranchValues;
   }
-  for (const llvm::bolt::BranchInfo &BI : FBD.EntryData) {
+  for (const BranchInfo &BI : FBD.EntryData) {
 // Do not output if source is a known symbol, since this was already
 // accounted for in the source function
 if (BI.From.IsSymbol)
@@ -2366,7 +2366,7 @@ std::error_code 
DataAggregator::writeBATYAML(BinaryContext &BC,
 return std::pair(BlockIt->first, BlockIt->second.getBBIndex());
   };
 
-  for (const llvm::bolt::BranchInfo &BI : Branches.Data) {
+  for (const BranchInfo &BI : Branches.Data) {
 using namespace yaml::bolt;
 const auto &[BlockOffset, BlockIndex] = getBlock(BI.From.Offset);
 BinaryBasicBlockProfile &YamlBB = YamlBF.Blocks[BlockIndex];
@@ -2388,7 +2388,7 @@ std::error_code 
DataAggregator::writeBATYAML(BinaryContext &BC,
 }
   }
   // Set entry counts, similar to DataReader::readProfile.
-  for (const llvm::bolt::BranchInfo &BI : Branches.EntryData) {
+  for (const BranchInfo &BI : Branches.EntryData) {
 if (!BlockMap.isInputBlock(BI.To.Offset)) {
   if (opts::Verbosity >= 1)
 errs() << "BOLT-WARNING: Unexpected EntryData in " << FuncName

``




https://github.com/llvm/llvm-project/pull/92017
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [BOLT][NFC] Rename DataAggregator::BranchInfo to TakenInfo (PR #92017)

2024-05-13 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov edited https://github.com/llvm/llvm-project/pull/92017
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [BOLT] Use aggregated FuncBranchData in writeBATYAML (PR #91289)

2024-05-13 Thread Amir Ayupov via llvm-branch-commits


@@ -2386,25 +2362,26 @@ std::error_code 
DataAggregator::writeBATYAML(BinaryContext &BC,
 return std::pair(BlockIt->first, BlockIt->second.getBBIndex());
   };
 
-  for (const auto &[FromOffset, SuccKV] : Branches.IntraIndex) {
-const auto &[_, Index] = getBlock(FromOffset);
-yaml::bolt::BinaryBasicBlockProfile &YamlBB = YamlBF.Blocks[Index];
-for (const auto &[SuccOffset, SuccDataIdx] : SuccKV)
-  if (BlockMap.isInputBlock(SuccOffset))
-YamlBB.Successors.emplace_back(
-getSuccessorInfo(SuccOffset, SuccDataIdx));
-  }
-  for (const auto &[FromOffset, CallTo] : Branches.InterIndex) {
-const auto &[BlockOffset, BlockIndex] = getBlock(FromOffset);
-yaml::bolt::BinaryBasicBlockProfile &YamlBB = 
YamlBF.Blocks[BlockIndex];
-const uint32_t Offset = FromOffset - BlockOffset;
-for (const auto &[CallToLoc, CallToIdx] : CallTo)
-  YamlBB.CallSites.emplace_back(
-  getCallSiteInfo(CallToLoc, CallToIdx, Offset));
-llvm::sort(YamlBB.CallSites, [](yaml::bolt::CallSiteInfo &A,
-yaml::bolt::CallSiteInfo &B) {
-  return A.Offset < B.Offset;
-});
+  for (const llvm::bolt::BranchInfo &BI : Branches.Data) {
+using namespace yaml::bolt;
+const auto &[BlockOffset, BlockIndex] = getBlock(BI.From.Offset);
+BinaryBasicBlockProfile &YamlBB = YamlBF.Blocks[BlockIndex];
+if (BI.To.IsSymbol && BI.To.Name == BI.From.Name && BI.To.Offset != 0) 
{
+  // Internal branch
+  const unsigned SuccIndex = getBlock(BI.To.Offset).second;
+  auto &SI = YamlBB.Successors.emplace_back(SuccessorInfo{SuccIndex});
+  SI.Count = BI.Branches;

aaupov wrote:

Type impedance means that if Count and Mispreds are passed to the constructor 
there needs to be an explicit cast (as the constructor doesn't accept uints). 
Whereas if the values are assigned to, there's an implicit cast.

https://github.com/llvm/llvm-project/pull/91289
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [BOLT] Use aggregated FuncBranchData in writeBATYAML (PR #91289)

2024-05-13 Thread Amir Ayupov via llvm-branch-commits


@@ -2386,25 +2362,26 @@ std::error_code 
DataAggregator::writeBATYAML(BinaryContext &BC,
 return std::pair(BlockIt->first, BlockIt->second.getBBIndex());
   };
 
-  for (const auto &[FromOffset, SuccKV] : Branches.IntraIndex) {
-const auto &[_, Index] = getBlock(FromOffset);
-yaml::bolt::BinaryBasicBlockProfile &YamlBB = YamlBF.Blocks[Index];
-for (const auto &[SuccOffset, SuccDataIdx] : SuccKV)
-  if (BlockMap.isInputBlock(SuccOffset))
-YamlBB.Successors.emplace_back(
-getSuccessorInfo(SuccOffset, SuccDataIdx));
-  }
-  for (const auto &[FromOffset, CallTo] : Branches.InterIndex) {
-const auto &[BlockOffset, BlockIndex] = getBlock(FromOffset);
-yaml::bolt::BinaryBasicBlockProfile &YamlBB = 
YamlBF.Blocks[BlockIndex];
-const uint32_t Offset = FromOffset - BlockOffset;
-for (const auto &[CallToLoc, CallToIdx] : CallTo)
-  YamlBB.CallSites.emplace_back(
-  getCallSiteInfo(CallToLoc, CallToIdx, Offset));
-llvm::sort(YamlBB.CallSites, [](yaml::bolt::CallSiteInfo &A,
-yaml::bolt::CallSiteInfo &B) {
-  return A.Offset < B.Offset;
-});
+  for (const llvm::bolt::BranchInfo &BI : Branches.Data) {
+using namespace yaml::bolt;
+const auto &[BlockOffset, BlockIndex] = getBlock(BI.From.Offset);
+BinaryBasicBlockProfile &YamlBB = YamlBF.Blocks[BlockIndex];
+if (BI.To.IsSymbol && BI.To.Name == BI.From.Name && BI.To.Offset != 0) 
{
+  // Internal branch
+  const unsigned SuccIndex = getBlock(BI.To.Offset).second;
+  auto &SI = YamlBB.Successors.emplace_back(SuccessorInfo{SuccIndex});
+  SI.Count = BI.Branches;

aaupov wrote:

For example, an explicit cast in the constructor due to type impedance: 
https://github.com/llvm/llvm-project/blob/31a203fa8af47a8b2e8e357857b114cf90638b2e/bolt/lib/Profile/DataAggregator.cpp#L1296-L1298

https://github.com/llvm/llvm-project/pull/91289
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [BOLT] Use aggregated FuncBranchData in writeBATYAML (PR #91289)

2024-05-13 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov edited https://github.com/llvm/llvm-project/pull/91289
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm][IR] Extend BranchWeightMetadata to track provenance of weights (PR #86609)

2024-05-13 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/86609


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm][IR] Extend BranchWeightMetadata to track provenance of weights (PR #86609)

2024-05-13 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/86609


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm][misexpect] Update MisExpect to use provenance tracking metadata (PR #86610)

2024-05-13 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/86610


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm][ProfDataUtils] provide getNumBranchWeights API (PR #90146)

2024-05-13 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/90146


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm][ProfDataUtils] provide getNumBranchWeights API (PR #90146)

2024-05-13 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/90146


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm][misexpect] Update MisExpect to use provenance tracking metadata (PR #86610)

2024-05-13 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/86610


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [BOLT] Use aggregated FuncBranchData in writeBATYAML (PR #91289)

2024-05-13 Thread Alexander Yermolovich via llvm-branch-commits

https://github.com/ayermolo approved this pull request.


https://github.com/llvm/llvm-project/pull/91289
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [BOLT] Use aggregated FuncBranchData in writeBATYAML (PR #91289)

2024-05-13 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/91289


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [BOLT] Use aggregated FuncBranchData in writeBATYAML (PR #91289)

2024-05-13 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/91289


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [BOLT][NFC] Rename DataAggregator::BranchInfo to TakenInfo (PR #92017)

2024-05-13 Thread Davide Italiano via llvm-branch-commits

https://github.com/dcci approved this pull request.


https://github.com/llvm/llvm-project/pull/92017
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [BOLT][NFC] Rename DataAggregator::BranchInfo to TakenInfo (PR #92017)

2024-05-13 Thread Davide Italiano via llvm-branch-commits

dcci wrote:

I would suggest `BranchTakenInfo` rather than `TakenInfo`  but up to you/@maksfb

https://github.com/llvm/llvm-project/pull/92017
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/18.x: [AArch64][SelectionDAG] Mask for SUBS with multiple users cannot be elided (#90911) (PR #91151)

2024-05-13 Thread Tom Stellard via llvm-branch-commits

tstellar wrote:

@davemgreen What do you think about backporting this?

https://github.com/llvm/llvm-project/pull/91151
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [BOLT][NFC] Rename DataAggregator::BranchInfo to TakenInfo (PR #92017)

2024-05-13 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/92017


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [BOLT][NFC] Rename DataAggregator::BranchInfo to TakenInfo (PR #92017)

2024-05-13 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/92017


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/18.x: [DAGCombiner] In mergeTruncStore, make sure we aren't storing shifted in bits. (#90939) (PR #91038)

2024-05-13 Thread Tom Stellard via llvm-branch-commits

tstellar wrote:

@topperc Do you have any strong objections to backporting this?  This looks 
small to me and I think it's OK to fix long-standing bugs.

https://github.com/llvm/llvm-project/pull/91038
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] Backport "riscv-isa" module metadata to 18.x (PR #91514)

2024-05-13 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar updated 
https://github.com/llvm/llvm-project/pull/91514

>From 285cfe36fe2a5d8c5ba111f882394405a3f78f31 Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Tue, 13 Feb 2024 16:17:50 -0800
Subject: [PATCH 1/3] [RISCV] Add canonical ISA string as Module metadata in
 IR. (#80760)

In an LTO build, we don't set the ELF attributes to indicate what
extensions were compiled with. The target CPU/Attrs in
RISCVTargetMachine do not get set for an LTO build. Each function gets a
target-cpu/feature attribute, but this isn't usable to set ELF attributs
since we wouldn't know what function to use. We can't just once since it
might have been compiler with an attribute likes target_verson.

This patch adds the ISA as Module metadata so we can retrieve it in the
backend. Individual translation units can still be compiled with
different strings so we need to collect the unique set when Modules are
merged.

The backend will need to combine the unique ISA strings to produce a
single value for the ELF attributes. This will be done in a separate
patch.
---
 clang/lib/CodeGen/CodeGenModule.cpp   |  14 +
 .../RISCV/ntlh-intrinsics/riscv32-zihintntl.c | 350 +-
 .../test/CodeGen/RISCV/riscv-metadata-arch.c  |  20 +
 3 files changed, 209 insertions(+), 175 deletions(-)
 create mode 100644 clang/test/CodeGen/RISCV/riscv-metadata-arch.c

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 1280bcd36de94..eb13cd40eb8a2 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -67,6 +67,7 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/TimeProfiler.h"
 #include "llvm/Support/xxhash.h"
 #include "llvm/TargetParser/Triple.h"
@@ -1059,6 +1060,19 @@ void CodeGenModule::Release() {
 llvm::LLVMContext &Ctx = TheModule.getContext();
 getModule().addModuleFlag(llvm::Module::Error, "target-abi",
   llvm::MDString::get(Ctx, ABIStr));
+
+// Add the canonical ISA string as metadata so the backend can set the ELF
+// attributes correctly. We use AppendUnique so LTO will keep all of the
+// unique ISA strings that were linked together.
+const std::vector &Features =
+getTarget().getTargetOpts().Features;
+auto ParseResult = llvm::RISCVISAInfo::parseFeatures(
+Arch == llvm::Triple::riscv64 ? 64 : 32, Features);
+if (!errorToBool(ParseResult.takeError()))
+  getModule().addModuleFlag(
+  llvm::Module::AppendUnique, "riscv-isa",
+  llvm::MDNode::get(
+  Ctx, llvm::MDString::get(Ctx, (*ParseResult)->toString(;
   }
 
   if (CodeGenOpts.SanitizeCfiCrossDso) {
diff --git a/clang/test/CodeGen/RISCV/ntlh-intrinsics/riscv32-zihintntl.c 
b/clang/test/CodeGen/RISCV/ntlh-intrinsics/riscv32-zihintntl.c
index 897edbc6450af..b11c2ca010e7c 100644
--- a/clang/test/CodeGen/RISCV/ntlh-intrinsics/riscv32-zihintntl.c
+++ b/clang/test/CodeGen/RISCV/ntlh-intrinsics/riscv32-zihintntl.c
@@ -28,190 +28,190 @@ vint8m1_t *scvc1, *scvc2;
 
 // clang-format off
 void ntl_all_sizes() {   // CHECK-LABEL: 
ntl_all_sizes
-  uc = __riscv_ntl_load(&sc, __RISCV_NTLH_INNERMOST_PRIVATE);   // CHECK: load 
i8{{.*}}align 1, !nontemporal !4, !riscv-nontemporal-domain !5
-  sc = __riscv_ntl_load(&uc, __RISCV_NTLH_INNERMOST_PRIVATE);   // CHECK: load 
i8{{.*}}align 1, !nontemporal !4, !riscv-nontemporal-domain !5
-  us = __riscv_ntl_load(&ss, __RISCV_NTLH_INNERMOST_PRIVATE);   // CHECK: load 
i16{{.*}}align 2, !nontemporal !4, !riscv-nontemporal-domain !5
-  ss = __riscv_ntl_load(&us, __RISCV_NTLH_INNERMOST_PRIVATE);   // CHECK: load 
i16{{.*}}align 2, !nontemporal !4, !riscv-nontemporal-domain !5
-  ui = __riscv_ntl_load(&si, __RISCV_NTLH_INNERMOST_PRIVATE);   // CHECK: load 
i32{{.*}}align 4, !nontemporal !4, !riscv-nontemporal-domain !5
-  si = __riscv_ntl_load(&ui, __RISCV_NTLH_INNERMOST_PRIVATE);   // CHECK: load 
i32{{.*}}align 4, !nontemporal !4, !riscv-nontemporal-domain !5
-  ull = __riscv_ntl_load(&sll, __RISCV_NTLH_INNERMOST_PRIVATE); // CHECK: load 
i64{{.*}}align 8, !nontemporal !4, !riscv-nontemporal-domain !5
-  sll = __riscv_ntl_load(&ull, __RISCV_NTLH_INNERMOST_PRIVATE); // CHECK: load 
i64{{.*}}align 8, !nontemporal !4, !riscv-nontemporal-domain !5
-  h1 = __riscv_ntl_load(&h2, __RISCV_NTLH_INNERMOST_PRIVATE);   // CHECK: load 
half{{.*}}align 2, !nontemporal !4, !riscv-nontemporal-domain !5
-  f1 = __riscv_ntl_load(&f2, __RISCV_NTLH_INNERMOST_PRIVATE);   // CHECK: load 
float{{.*}}align 4, !nontemporal !4, !riscv-nontemporal-domain !5
-  d1 = __riscv_ntl_load(&d2, __RISCV_NTLH_INNERMOST_PRIVATE);   // CHECK: load 
double{{.*}}align 8, !nontemporal !4, !riscv-nontemporal-domain !5
-  v4si1 = __riscv_ntl_load(&v4si2, __RISCV_NTLH_INNERMOST_PRIVATE);   // 
CHECK: load <4

[llvm-branch-commits] [llvm] release/18.x: [workflows] Add a job for requesting a release note on release branch PRs (#91826) (PR #92049)

2024-05-13 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/92049

Backport c99d1156c28dfed67a8479dd97608d1f0d6cd593

Requested by: @tstellar

>From a82ddb9d8122a2e73c8385d38147782dbdbbe0aa Mon Sep 17 00:00:00 2001
From: Tom Stellard 
Date: Mon, 13 May 2024 16:31:21 -0700
Subject: [PATCH] [workflows] Add a job for requesting a release note on
 release branch PRs (#91826)

We have been collecting release notes from the PRs for most of the
18.1.x releases and this just helps automate the process.

(cherry picked from commit c99d1156c28dfed67a8479dd97608d1f0d6cd593)
---
 .github/workflows/pr-request-release-note.yml | 43 +++
 llvm/utils/git/github-automation.py   | 33 ++
 2 files changed, 76 insertions(+)
 create mode 100644 .github/workflows/pr-request-release-note.yml

diff --git a/.github/workflows/pr-request-release-note.yml 
b/.github/workflows/pr-request-release-note.yml
new file mode 100644
index 0..0fcb95f1fe294
--- /dev/null
+++ b/.github/workflows/pr-request-release-note.yml
@@ -0,0 +1,43 @@
+name: PR Request Release Note
+
+permissions:
+  contents: read
+  pull-requests: write
+
+on:
+  pull_request:
+types:
+  - closed
+
+jobs:
+  request-release-note:
+if: >-
+  github.repository_owner == 'llvm' &&
+  startsWith(github.ref, 'refs/heads/release')
+
+runs-on: ubuntu-latest
+steps:
+  # We need to pull the script from the main branch, so that we ensure
+  # we get the latest version of this script.
+  - name: Checkout Scripts
+uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # 
v4.1.1
+with:
+  sparse-checkout: |
+llvm/utils/git/requirements.txt
+llvm/utils/git/github-automation.py
+  sparse-checkout-cone-mode: false
+
+  - name: Install Dependencies
+run: |
+  pip install -r llvm/utils/git/requirements.txt
+
+  - name: Request Release Note
+env:
+  # We need to use an llvmbot token here, because we are mentioning a 
user.
+  GITHUB_TOKEN: ${{ github.token }}
+run: |
+  python3 llvm/utils/git/github-automation.py \
+--repo "$GITHUB_REPOSITORY" \
+--token "$GITHUB_TOKEN" \
+request-release-note \
+--pr-number ${{ github.event.pull_request.number}}
diff --git a/llvm/utils/git/github-automation.py 
b/llvm/utils/git/github-automation.py
index f78d91059ecd3..ac4077edb4fcc 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -675,6 +675,25 @@ def execute_command(self) -> bool:
 return False
 
 
+def request_release_note(token: str, repo_name: str, pr_number: int):
+repo = github.Github(token).get_repo(repo_name)
+pr = repo.get_issue(pr_number).as_pull_request()
+submitter = pr.user.login
+if submitter == "llvmbot":
+m = re.search("Requested by: @(.+)$", pr.body)
+if not m:
+submitter = None
+print("Warning could not determine user who requested backport.")
+submitter = m.group(1)
+
+mention = ""
+if submitter:
+mention = f"@{submitter}"
+
+comment = f"{mention} (or anyone else). If you would like to add a note 
about this fix in the release notes (completely optional). Please reply to this 
comment with a one or two sentence description of the fix.  When you are done, 
please add the release:note label to this PR. "
+pr.as_issue().create_comment(comment)
+
+
 parser = argparse.ArgumentParser()
 parser.add_argument(
 "--token", type=str, required=True, help="GitHub authentiation token"
@@ -736,6 +755,18 @@ def execute_command(self) -> bool:
 help="Set the default user and email for the git repo in LLVM_PROJECT_DIR 
to llvmbot",
 )
 
+request_release_note_parser = subparsers.add_parser(
+"request-release-note",
+help="Request a release note for a pull request",
+)
+request_release_note_parser.add_argument(
+"--pr-number",
+type=int,
+required=True,
+help="The pull request to request the release note",
+)
+
+
 args = parser.parse_args()
 
 if args.command == "issue-subscriber":
@@ -771,3 +802,5 @@ def execute_command(self) -> bool:
 sys.exit(1)
 elif args.command == "setup-llvmbot-git":
 setup_llvmbot_git()
+elif args.command == "request-release-note":
+request_release_note(args.token, args.repo, args.pr_number)

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/18.x: [workflows] Add a job for requesting a release note on release branch PRs (#91826) (PR #92049)

2024-05-13 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/92049
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/18.x: [workflows] Add a job for requesting a release note on release branch PRs (#91826) (PR #92049)

2024-05-13 Thread via llvm-branch-commits

llvmbot wrote:

@tru What do you think about merging this PR to the release branch?

https://github.com/llvm/llvm-project/pull/92049
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/18.x: [workflows] Add a job for requesting a release note on release branch PRs (#91826) (PR #92049)

2024-05-13 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-github-workflow

Author: None (llvmbot)


Changes

Backport c99d1156c28dfed67a8479dd97608d1f0d6cd593

Requested by: @tstellar

---
Full diff: https://github.com/llvm/llvm-project/pull/92049.diff


2 Files Affected:

- (added) .github/workflows/pr-request-release-note.yml (+43) 
- (modified) llvm/utils/git/github-automation.py (+33) 


``diff
diff --git a/.github/workflows/pr-request-release-note.yml 
b/.github/workflows/pr-request-release-note.yml
new file mode 100644
index 0..0fcb95f1fe294
--- /dev/null
+++ b/.github/workflows/pr-request-release-note.yml
@@ -0,0 +1,43 @@
+name: PR Request Release Note
+
+permissions:
+  contents: read
+  pull-requests: write
+
+on:
+  pull_request:
+types:
+  - closed
+
+jobs:
+  request-release-note:
+if: >-
+  github.repository_owner == 'llvm' &&
+  startsWith(github.ref, 'refs/heads/release')
+
+runs-on: ubuntu-latest
+steps:
+  # We need to pull the script from the main branch, so that we ensure
+  # we get the latest version of this script.
+  - name: Checkout Scripts
+uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # 
v4.1.1
+with:
+  sparse-checkout: |
+llvm/utils/git/requirements.txt
+llvm/utils/git/github-automation.py
+  sparse-checkout-cone-mode: false
+
+  - name: Install Dependencies
+run: |
+  pip install -r llvm/utils/git/requirements.txt
+
+  - name: Request Release Note
+env:
+  # We need to use an llvmbot token here, because we are mentioning a 
user.
+  GITHUB_TOKEN: ${{ github.token }}
+run: |
+  python3 llvm/utils/git/github-automation.py \
+--repo "$GITHUB_REPOSITORY" \
+--token "$GITHUB_TOKEN" \
+request-release-note \
+--pr-number ${{ github.event.pull_request.number}}
diff --git a/llvm/utils/git/github-automation.py 
b/llvm/utils/git/github-automation.py
index f78d91059ecd3..ac4077edb4fcc 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -675,6 +675,25 @@ def execute_command(self) -> bool:
 return False
 
 
+def request_release_note(token: str, repo_name: str, pr_number: int):
+repo = github.Github(token).get_repo(repo_name)
+pr = repo.get_issue(pr_number).as_pull_request()
+submitter = pr.user.login
+if submitter == "llvmbot":
+m = re.search("Requested by: @(.+)$", pr.body)
+if not m:
+submitter = None
+print("Warning could not determine user who requested backport.")
+submitter = m.group(1)
+
+mention = ""
+if submitter:
+mention = f"@{submitter}"
+
+comment = f"{mention} (or anyone else). If you would like to add a note 
about this fix in the release notes (completely optional). Please reply to this 
comment with a one or two sentence description of the fix.  When you are done, 
please add the release:note label to this PR. "
+pr.as_issue().create_comment(comment)
+
+
 parser = argparse.ArgumentParser()
 parser.add_argument(
 "--token", type=str, required=True, help="GitHub authentiation token"
@@ -736,6 +755,18 @@ def execute_command(self) -> bool:
 help="Set the default user and email for the git repo in LLVM_PROJECT_DIR 
to llvmbot",
 )
 
+request_release_note_parser = subparsers.add_parser(
+"request-release-note",
+help="Request a release note for a pull request",
+)
+request_release_note_parser.add_argument(
+"--pr-number",
+type=int,
+required=True,
+help="The pull request to request the release note",
+)
+
+
 args = parser.parse_args()
 
 if args.command == "issue-subscriber":
@@ -771,3 +802,5 @@ def execute_command(self) -> bool:
 sys.exit(1)
 elif args.command == "setup-llvmbot-git":
 setup_llvmbot_git()
+elif args.command == "request-release-note":
+request_release_note(args.token, args.repo, args.pr_number)

``




https://github.com/llvm/llvm-project/pull/92049
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] a82ddb9 - [workflows] Add a job for requesting a release note on release branch PRs (#91826)

2024-05-13 Thread via llvm-branch-commits

Author: Tom Stellard
Date: 2024-05-13T23:37:58Z
New Revision: a82ddb9d8122a2e73c8385d38147782dbdbbe0aa

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

LOG: [workflows] Add a job for requesting a release note on release branch PRs 
(#91826)

We have been collecting release notes from the PRs for most of the
18.1.x releases and this just helps automate the process.

(cherry picked from commit c99d1156c28dfed67a8479dd97608d1f0d6cd593)

Added: 
.github/workflows/pr-request-release-note.yml

Modified: 
llvm/utils/git/github-automation.py

Removed: 




diff  --git a/.github/workflows/pr-request-release-note.yml 
b/.github/workflows/pr-request-release-note.yml
new file mode 100644
index 0..0fcb95f1fe294
--- /dev/null
+++ b/.github/workflows/pr-request-release-note.yml
@@ -0,0 +1,43 @@
+name: PR Request Release Note
+
+permissions:
+  contents: read
+  pull-requests: write
+
+on:
+  pull_request:
+types:
+  - closed
+
+jobs:
+  request-release-note:
+if: >-
+  github.repository_owner == 'llvm' &&
+  startsWith(github.ref, 'refs/heads/release')
+
+runs-on: ubuntu-latest
+steps:
+  # We need to pull the script from the main branch, so that we ensure
+  # we get the latest version of this script.
+  - name: Checkout Scripts
+uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # 
v4.1.1
+with:
+  sparse-checkout: |
+llvm/utils/git/requirements.txt
+llvm/utils/git/github-automation.py
+  sparse-checkout-cone-mode: false
+
+  - name: Install Dependencies
+run: |
+  pip install -r llvm/utils/git/requirements.txt
+
+  - name: Request Release Note
+env:
+  # We need to use an llvmbot token here, because we are mentioning a 
user.
+  GITHUB_TOKEN: ${{ github.token }}
+run: |
+  python3 llvm/utils/git/github-automation.py \
+--repo "$GITHUB_REPOSITORY" \
+--token "$GITHUB_TOKEN" \
+request-release-note \
+--pr-number ${{ github.event.pull_request.number}}

diff  --git a/llvm/utils/git/github-automation.py 
b/llvm/utils/git/github-automation.py
index f78d91059ecd3..ac4077edb4fcc 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -675,6 +675,25 @@ def execute_command(self) -> bool:
 return False
 
 
+def request_release_note(token: str, repo_name: str, pr_number: int):
+repo = github.Github(token).get_repo(repo_name)
+pr = repo.get_issue(pr_number).as_pull_request()
+submitter = pr.user.login
+if submitter == "llvmbot":
+m = re.search("Requested by: @(.+)$", pr.body)
+if not m:
+submitter = None
+print("Warning could not determine user who requested backport.")
+submitter = m.group(1)
+
+mention = ""
+if submitter:
+mention = f"@{submitter}"
+
+comment = f"{mention} (or anyone else). If you would like to add a note 
about this fix in the release notes (completely optional). Please reply to this 
comment with a one or two sentence description of the fix.  When you are done, 
please add the release:note label to this PR. "
+pr.as_issue().create_comment(comment)
+
+
 parser = argparse.ArgumentParser()
 parser.add_argument(
 "--token", type=str, required=True, help="GitHub authentiation token"
@@ -736,6 +755,18 @@ def execute_command(self) -> bool:
 help="Set the default user and email for the git repo in LLVM_PROJECT_DIR 
to llvmbot",
 )
 
+request_release_note_parser = subparsers.add_parser(
+"request-release-note",
+help="Request a release note for a pull request",
+)
+request_release_note_parser.add_argument(
+"--pr-number",
+type=int,
+required=True,
+help="The pull request to request the release note",
+)
+
+
 args = parser.parse_args()
 
 if args.command == "issue-subscriber":
@@ -771,3 +802,5 @@ def execute_command(self) -> bool:
 sys.exit(1)
 elif args.command == "setup-llvmbot-git":
 setup_llvmbot_git()
+elif args.command == "request-release-note":
+request_release_note(args.token, args.repo, args.pr_number)



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/18.x: [workflows] Add a job for requesting a release note on release branch PRs (#91826) (PR #92049)

2024-05-13 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar closed 
https://github.com/llvm/llvm-project/pull/92049
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/18.x: [workflows] Add a job for requesting a release note on release branch PRs (#91826) (PR #92049)

2024-05-13 Thread Tom Stellard via llvm-branch-commits

tstellar wrote:

Merging this now so I can test it out.

https://github.com/llvm/llvm-project/pull/92049
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [flang] [flang][OpenMP] Don't pass clauses to op-generating functions anymore (PR #90108)

2024-05-13 Thread Krzysztof Parzyszek via llvm-branch-commits

https://github.com/kparzysz edited 
https://github.com/llvm/llvm-project/pull/90108
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [BOLT][NFC] Rename DataAggregator::BranchInfo to TakenInfo (PR #92017)

2024-05-13 Thread Amir Ayupov via llvm-branch-commits

aaupov wrote:

> I would suggest `BranchTakenInfo` rather than `TakenInfo` but up to 
> you/@maksfb

`TakenBranchInfo` is a better-sounding order at least to me. @maksfb - you 
choose :) 

https://github.com/llvm/llvm-project/pull/92017
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/18.x: Reland "[clang-repl] Keep the first llvm::Module empty to avoid invalid memory access. (#89031)" (PR #90544)

2024-05-13 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar updated 
https://github.com/llvm/llvm-project/pull/90544

>From c5b3fa491f001e06bca9a2f0754937d3614fd9e8 Mon Sep 17 00:00:00 2001
From: Vassil Vassilev 
Date: Sat, 20 Apr 2024 18:28:38 +
Subject: [PATCH] Reland "[clang-repl] Keep the first llvm::Module empty to
 avoid invalid memory access. (#89031)"

Original commit message: "

Clang's CodeGen is designed to work with a single llvm::Module. In many cases
for convenience various CodeGen parts have a reference to the llvm::Module
(TheModule or Module) which does not change when a new module is pushed.
However, the execution engine wants to take ownership of the module which does
not map well to CodeGen's design. To work this around we clone the module and
pass it down.

With some effort it is possible to teach CodeGen to ask the CodeGenModule for
its current module and that would have an overall positive impact on CodeGen
improving the encapsulation of various parts but that's not resilient to future
regression.

This patch takes a more conservative approach and keeps the first llvm::Module
empty intentionally and does not pass it to the Jit. That's also not bullet
proof because we have to guarantee that CodeGen does not write on the
blueprint. However, we have inserted some assertions to catch accidental
additions to that canary module.

This change will fixes a long-standing invalid memory access reported by
valgrind when we enable the TBAA optimization passes. It also unblock progress
on https://github.com/llvm/llvm-project/pull/84758.
"

This patch reverts adc4f6233df734fbe3793118ecc89d3584e0c90f and removes
the check of `named_metadata_empty` of the first llvm::Module because on darwin
clang inserts some harmless metadata which we can ignore.

(cherry picked from commit a3f07d36cbc9e3a0d004609d140474c1d8a25bb6)
---
 clang/lib/Interpreter/IncrementalParser.cpp | 24 -
 clang/lib/Interpreter/IncrementalParser.h   |  5 +
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Interpreter/IncrementalParser.cpp 
b/clang/lib/Interpreter/IncrementalParser.cpp
index 370bcbfee8b01..f5f32b9f3924a 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -209,6 +209,10 @@ IncrementalParser::IncrementalParser(Interpreter &Interp,
   if (Err)
 return;
   CI->ExecuteAction(*Act);
+
+  if (getCodeGen())
+CachedInCodeGenModule = GenModule();
+
   std::unique_ptr IncrConsumer =
   std::make_unique(Interp, CI->takeASTConsumer());
   CI->setASTConsumer(std::move(IncrConsumer));
@@ -224,11 +228,8 @@ IncrementalParser::IncrementalParser(Interpreter &Interp,
 return; // PTU.takeError();
   }
 
-  if (CodeGenerator *CG = getCodeGen()) {
-std::unique_ptr M(CG->ReleaseModule());
-CG->StartModule("incr_module_" + std::to_string(PTUs.size()),
-M->getContext());
-PTU->TheModule = std::move(M);
+  if (getCodeGen()) {
+PTU->TheModule = GenModule();
 assert(PTU->TheModule && "Failed to create initial PTU");
   }
 }
@@ -364,6 +365,19 @@ IncrementalParser::Parse(llvm::StringRef input) {
 std::unique_ptr IncrementalParser::GenModule() {
   static unsigned ID = 0;
   if (CodeGenerator *CG = getCodeGen()) {
+// Clang's CodeGen is designed to work with a single llvm::Module. In many
+// cases for convenience various CodeGen parts have a reference to the
+// llvm::Module (TheModule or Module) which does not change when a new
+// module is pushed. However, the execution engine wants to take ownership
+// of the module which does not map well to CodeGen's design. To work this
+// around we created an empty module to make CodeGen happy. We should make
+// sure it always stays empty.
+assert((!CachedInCodeGenModule ||
+(CachedInCodeGenModule->empty() &&
+ CachedInCodeGenModule->global_empty() &&
+ CachedInCodeGenModule->alias_empty() &&
+ CachedInCodeGenModule->ifunc_empty())) &&
+   "CodeGen wrote to a readonly module");
 std::unique_ptr M(CG->ReleaseModule());
 CG->StartModule("incr_module_" + std::to_string(ID++), M->getContext());
 return M;
diff --git a/clang/lib/Interpreter/IncrementalParser.h 
b/clang/lib/Interpreter/IncrementalParser.h
index e13b74c7f6594..f63bce50acd3b 100644
--- a/clang/lib/Interpreter/IncrementalParser.h
+++ b/clang/lib/Interpreter/IncrementalParser.h
@@ -24,6 +24,7 @@
 #include 
 namespace llvm {
 class LLVMContext;
+class Module;
 } // namespace llvm
 
 namespace clang {
@@ -57,6 +58,10 @@ class IncrementalParser {
   /// of code.
   std::list PTUs;
 
+  /// When CodeGen is created the first llvm::Module gets cached in many places
+  /// and we must keep it alive.
+  std::unique_ptr CachedInCodeGenModule;
+
   IncrementalParser();
 
 public:

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://li

[llvm-branch-commits] [clang] c5b3fa4 - Reland "[clang-repl] Keep the first llvm::Module empty to avoid invalid memory access. (#89031)"

2024-05-13 Thread Tom Stellard via llvm-branch-commits

Author: Vassil Vassilev
Date: 2024-05-13T17:19:22-07:00
New Revision: c5b3fa491f001e06bca9a2f0754937d3614fd9e8

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

LOG: Reland "[clang-repl] Keep the first llvm::Module empty to avoid invalid 
memory access. (#89031)"

Original commit message: "

Clang's CodeGen is designed to work with a single llvm::Module. In many cases
for convenience various CodeGen parts have a reference to the llvm::Module
(TheModule or Module) which does not change when a new module is pushed.
However, the execution engine wants to take ownership of the module which does
not map well to CodeGen's design. To work this around we clone the module and
pass it down.

With some effort it is possible to teach CodeGen to ask the CodeGenModule for
its current module and that would have an overall positive impact on CodeGen
improving the encapsulation of various parts but that's not resilient to future
regression.

This patch takes a more conservative approach and keeps the first llvm::Module
empty intentionally and does not pass it to the Jit. That's also not bullet
proof because we have to guarantee that CodeGen does not write on the
blueprint. However, we have inserted some assertions to catch accidental
additions to that canary module.

This change will fixes a long-standing invalid memory access reported by
valgrind when we enable the TBAA optimization passes. It also unblock progress
on https://github.com/llvm/llvm-project/pull/84758.
"

This patch reverts adc4f6233df734fbe3793118ecc89d3584e0c90f and removes
the check of `named_metadata_empty` of the first llvm::Module because on darwin
clang inserts some harmless metadata which we can ignore.

(cherry picked from commit a3f07d36cbc9e3a0d004609d140474c1d8a25bb6)

Added: 


Modified: 
clang/lib/Interpreter/IncrementalParser.cpp
clang/lib/Interpreter/IncrementalParser.h

Removed: 




diff  --git a/clang/lib/Interpreter/IncrementalParser.cpp 
b/clang/lib/Interpreter/IncrementalParser.cpp
index 370bcbfee8b01..f5f32b9f3924a 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -209,6 +209,10 @@ IncrementalParser::IncrementalParser(Interpreter &Interp,
   if (Err)
 return;
   CI->ExecuteAction(*Act);
+
+  if (getCodeGen())
+CachedInCodeGenModule = GenModule();
+
   std::unique_ptr IncrConsumer =
   std::make_unique(Interp, CI->takeASTConsumer());
   CI->setASTConsumer(std::move(IncrConsumer));
@@ -224,11 +228,8 @@ IncrementalParser::IncrementalParser(Interpreter &Interp,
 return; // PTU.takeError();
   }
 
-  if (CodeGenerator *CG = getCodeGen()) {
-std::unique_ptr M(CG->ReleaseModule());
-CG->StartModule("incr_module_" + std::to_string(PTUs.size()),
-M->getContext());
-PTU->TheModule = std::move(M);
+  if (getCodeGen()) {
+PTU->TheModule = GenModule();
 assert(PTU->TheModule && "Failed to create initial PTU");
   }
 }
@@ -364,6 +365,19 @@ IncrementalParser::Parse(llvm::StringRef input) {
 std::unique_ptr IncrementalParser::GenModule() {
   static unsigned ID = 0;
   if (CodeGenerator *CG = getCodeGen()) {
+// Clang's CodeGen is designed to work with a single llvm::Module. In many
+// cases for convenience various CodeGen parts have a reference to the
+// llvm::Module (TheModule or Module) which does not change when a new
+// module is pushed. However, the execution engine wants to take ownership
+// of the module which does not map well to CodeGen's design. To work this
+// around we created an empty module to make CodeGen happy. We should make
+// sure it always stays empty.
+assert((!CachedInCodeGenModule ||
+(CachedInCodeGenModule->empty() &&
+ CachedInCodeGenModule->global_empty() &&
+ CachedInCodeGenModule->alias_empty() &&
+ CachedInCodeGenModule->ifunc_empty())) &&
+   "CodeGen wrote to a readonly module");
 std::unique_ptr M(CG->ReleaseModule());
 CG->StartModule("incr_module_" + std::to_string(ID++), M->getContext());
 return M;

diff  --git a/clang/lib/Interpreter/IncrementalParser.h 
b/clang/lib/Interpreter/IncrementalParser.h
index e13b74c7f6594..f63bce50acd3b 100644
--- a/clang/lib/Interpreter/IncrementalParser.h
+++ b/clang/lib/Interpreter/IncrementalParser.h
@@ -24,6 +24,7 @@
 #include 
 namespace llvm {
 class LLVMContext;
+class Module;
 } // namespace llvm
 
 namespace clang {
@@ -57,6 +58,10 @@ class IncrementalParser {
   /// of code.
   std::list PTUs;
 
+  /// When CodeGen is created the first llvm::Module gets cached in many places
+  /// and we must keep it alive.
+  std::unique_ptr CachedInCodeGenModule;
+
   IncrementalParser();
 
 public:




[llvm-branch-commits] [clang] release/18.x: Reland "[clang-repl] Keep the first llvm::Module empty to avoid invalid memory access. (#89031)" (PR #90544)

2024-05-13 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar closed 
https://github.com/llvm/llvm-project/pull/90544
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/18.x: Reland "[clang-repl] Keep the first llvm::Module empty to avoid invalid memory access. (#89031)" (PR #90544)

2024-05-13 Thread Tom Stellard via llvm-branch-commits

tstellar wrote:

@nikic (or anyone else). If you would like to add a note about this fix in the 
release notes (completely optional). Please reply to this comment with a one or 
two sentence description of the fix.  When you are done, please add the 
release:note label to this PR.

https://github.com/llvm/llvm-project/pull/90544
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] release/18.x: [lld][WebAssembly] Fix test on Windows, use llvm-ar instead of ar (PR #91967)

2024-05-13 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar updated 
https://github.com/llvm/llvm-project/pull/91967

>From be6c81751cc99a07dac4eef7bc6564e15fd8dfa6 Mon Sep 17 00:00:00 2001
From: Reid Kleckner 
Date: Wed, 24 Jan 2024 11:10:53 -0800
Subject: [PATCH] [lld][WebAssembly] Fix test on Windows, use llvm-ar instead
 of ar

(cherry picked from commit 4b4763ffebaed9f1fee94b8ad5a1a450a9726683)
---
 lld/test/wasm/signature-mismatch.s | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lld/test/wasm/signature-mismatch.s 
b/lld/test/wasm/signature-mismatch.s
index 7dc1b8ced3530..17f805a80727a 100644
--- a/lld/test/wasm/signature-mismatch.s
+++ b/lld/test/wasm/signature-mismatch.s
@@ -9,7 +9,7 @@
 # RUN: obj2yaml %t.reloc.o | FileCheck %s -check-prefix=RELOC
 
 # RUN: rm -f %t.a
-# RUN: ar crS %t.a %t.ret32.o %t.call.o
+# RUN: llvm-ar crS %t.a %t.ret32.o %t.call.o
 # RUN: wasm-ld --export=call_ret32 --export=ret32 -o %t2.wasm %t.main.o %t.a 
2>&1 | FileCheck %s -check-prefix=ARCHIVE
 # RUN: obj2yaml %t2.wasm | FileCheck %s -check-prefix=YAML
 

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] be6c817 - [lld][WebAssembly] Fix test on Windows, use llvm-ar instead of ar

2024-05-13 Thread Tom Stellard via llvm-branch-commits

Author: Reid Kleckner
Date: 2024-05-13T17:46:50-07:00
New Revision: be6c81751cc99a07dac4eef7bc6564e15fd8dfa6

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

LOG: [lld][WebAssembly] Fix test on Windows, use llvm-ar instead of ar

(cherry picked from commit 4b4763ffebaed9f1fee94b8ad5a1a450a9726683)

Added: 


Modified: 
lld/test/wasm/signature-mismatch.s

Removed: 




diff  --git a/lld/test/wasm/signature-mismatch.s 
b/lld/test/wasm/signature-mismatch.s
index 7dc1b8ced3530..17f805a80727a 100644
--- a/lld/test/wasm/signature-mismatch.s
+++ b/lld/test/wasm/signature-mismatch.s
@@ -9,7 +9,7 @@
 # RUN: obj2yaml %t.reloc.o | FileCheck %s -check-prefix=RELOC
 
 # RUN: rm -f %t.a
-# RUN: ar crS %t.a %t.ret32.o %t.call.o
+# RUN: llvm-ar crS %t.a %t.ret32.o %t.call.o
 # RUN: wasm-ld --export=call_ret32 --export=ret32 -o %t2.wasm %t.main.o %t.a 
2>&1 | FileCheck %s -check-prefix=ARCHIVE
 # RUN: obj2yaml %t2.wasm | FileCheck %s -check-prefix=YAML
 



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] release/18.x: [lld][WebAssembly] Fix test on Windows, use llvm-ar instead of ar (PR #91967)

2024-05-13 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar closed 
https://github.com/llvm/llvm-project/pull/91967
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] release/18.x: [lld][WebAssembly] Fix test on Windows, use llvm-ar instead of ar (PR #91967)

2024-05-13 Thread Tom Stellard via llvm-branch-commits

tstellar wrote:

@sbc100 (or anyone else). If you would like to add a note about this fix in the 
release notes (completely optional). Please reply to this comment with a one or 
two sentence description of the fix.  When you are done, please add the 
release:note label to this PR.

https://github.com/llvm/llvm-project/pull/91967
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/18.x: [Clang][Sema] Revise the transformation of CTAD parameters of nested class templates (#91628) (PR #91890)

2024-05-13 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar updated 
https://github.com/llvm/llvm-project/pull/91890

>From 8d65f14cb6ff87536433b934fea3730c63bd466a Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 10 May 2024 20:47:15 +0800
Subject: [PATCH] [Clang][Sema] Revise the transformation of CTAD parameters of
 nested class templates (#91628)

This fixes a regression introduced by bee78b88f.

When we form a deduction guide for a constructor, basically, we do the
following work:
- Collect template parameters from the constructor's surrounding class
template, if present.
- Collect template parameters from the constructor.
- Splice these template parameters together into a new template
parameter list.
- Turn all the references (e.g. the function parameter list) to the
invented parameter list by applying a `TreeTransform` to the function
type.

In the previous fix, we handled cases of nested class templates by
substituting the "outer" template parameters (i.e. those not declared at
the surrounding class template or the constructor) with the
instantiating template arguments. The approach per se makes sense, but
there was a flaw in the following case:

```cpp
template  struct X {
  template  struct Y {
template  Y(T) {}
  };

  template  Y(T) -> Y;
};

X::Y y(42);
```

While we're transforming the parameters for `Y(T)`, we first attempt to
transform all references to `V` and `T`; then, we handle the references
to outer parameters `U` and `Us` using the template arguments from
`X` by transforming the same `ParamDecl`. However, the first step
results in the reference `T` being `` because the
invented `T` is the last of the parameter list of the deduction guide,
and what we're substituting with is a corresponding parameter pack
(which is `Us`, though empty). Hence we're messing up the substitution.

I think we can resolve it by reversing the substitution order, which
means handling outer template parameters first and then the inner
parameters.

There's no release note because this is a regression in 18, and I hope
we can catch up with the last release.

Fixes https://github.com/llvm/llvm-project/issues/88142

(cherry picked from commit 8c852ab57932a5cd954cb0d050c3d2ab486428df)
---
 clang/lib/Sema/SemaTemplate.cpp   | 25 ++-
 .../nested-implicit-deduction-guides.cpp  | 14 +++
 2 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index b619f5d729e86..a12a64939c464 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2404,9 +2404,6 @@ struct ConvertConstructorToDeductionGuideTransform {
   Args.addOuterRetainedLevel();
 }
 
-if (NestedPattern)
-  Args.addOuterRetainedLevels(NestedPattern->getTemplateDepth());
-
 FunctionProtoTypeLoc FPTL = CD->getTypeSourceInfo()->getTypeLoc()
.getAsAdjusted();
 assert(FPTL && "no prototype for constructor declaration");
@@ -2526,11 +2523,27 @@ struct ConvertConstructorToDeductionGuideTransform {
 
 //-- The types of the function parameters are those of the constructor.
 for (auto *OldParam : TL.getParams()) {
-  ParmVarDecl *NewParam =
-  transformFunctionTypeParam(OldParam, Args, MaterializedTypedefs);
-  if (NestedPattern && NewParam)
+  ParmVarDecl *NewParam = OldParam;
+  // Given
+  //   template  struct C {
+  // template  struct D {
+  //   template  D(U, V);
+  // };
+  //   };
+  // First, transform all the references to template parameters that are
+  // defined outside of the surrounding class template. That is T in the
+  // above example.
+  if (NestedPattern) {
 NewParam = transformFunctionTypeParam(NewParam, OuterInstantiationArgs,
   MaterializedTypedefs);
+if (!NewParam)
+  return QualType();
+  }
+  // Then, transform all the references to template parameters that are
+  // defined at the class template and the constructor. In this example,
+  // they're U and V, respectively.
+  NewParam =
+  transformFunctionTypeParam(NewParam, Args, MaterializedTypedefs);
   if (!NewParam)
 return QualType();
   ParamTypes.push_back(NewParam->getType());
diff --git a/clang/test/SemaTemplate/nested-implicit-deduction-guides.cpp 
b/clang/test/SemaTemplate/nested-implicit-deduction-guides.cpp
index 38b6706595a11..f289dc0452868 100644
--- a/clang/test/SemaTemplate/nested-implicit-deduction-guides.cpp
+++ b/clang/test/SemaTemplate/nested-implicit-deduction-guides.cpp
@@ -84,3 +84,17 @@ nested_init_list::concept_fail nil_invalid{1, ""};
 // expected-note@#INIT_LIST_INNER_INVALID {{candidate template ignored: 
substitution failure [with F = const char *]: constraints not satisfied for 
class template 'concept_fail' [with F = const char *]}}
 // expected-note@#INIT_LIST_INNER_INVALID {{candidate func

[llvm-branch-commits] [clang] 8d65f14 - [Clang][Sema] Revise the transformation of CTAD parameters of nested class templates (#91628)

2024-05-13 Thread Tom Stellard via llvm-branch-commits

Author: Younan Zhang
Date: 2024-05-13T17:53:00-07:00
New Revision: 8d65f14cb6ff87536433b934fea3730c63bd466a

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

LOG: [Clang][Sema] Revise the transformation of CTAD parameters of nested class 
templates (#91628)

This fixes a regression introduced by bee78b88f.

When we form a deduction guide for a constructor, basically, we do the
following work:
- Collect template parameters from the constructor's surrounding class
template, if present.
- Collect template parameters from the constructor.
- Splice these template parameters together into a new template
parameter list.
- Turn all the references (e.g. the function parameter list) to the
invented parameter list by applying a `TreeTransform` to the function
type.

In the previous fix, we handled cases of nested class templates by
substituting the "outer" template parameters (i.e. those not declared at
the surrounding class template or the constructor) with the
instantiating template arguments. The approach per se makes sense, but
there was a flaw in the following case:

```cpp
template  struct X {
  template  struct Y {
template  Y(T) {}
  };

  template  Y(T) -> Y;
};

X::Y y(42);
```

While we're transforming the parameters for `Y(T)`, we first attempt to
transform all references to `V` and `T`; then, we handle the references
to outer parameters `U` and `Us` using the template arguments from
`X` by transforming the same `ParamDecl`. However, the first step
results in the reference `T` being `` because the
invented `T` is the last of the parameter list of the deduction guide,
and what we're substituting with is a corresponding parameter pack
(which is `Us`, though empty). Hence we're messing up the substitution.

I think we can resolve it by reversing the substitution order, which
means handling outer template parameters first and then the inner
parameters.

There's no release note because this is a regression in 18, and I hope
we can catch up with the last release.

Fixes https://github.com/llvm/llvm-project/issues/88142

(cherry picked from commit 8c852ab57932a5cd954cb0d050c3d2ab486428df)

Added: 


Modified: 
clang/lib/Sema/SemaTemplate.cpp
clang/test/SemaTemplate/nested-implicit-deduction-guides.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index b619f5d729e86..a12a64939c464 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2404,9 +2404,6 @@ struct ConvertConstructorToDeductionGuideTransform {
   Args.addOuterRetainedLevel();
 }
 
-if (NestedPattern)
-  Args.addOuterRetainedLevels(NestedPattern->getTemplateDepth());
-
 FunctionProtoTypeLoc FPTL = CD->getTypeSourceInfo()->getTypeLoc()
.getAsAdjusted();
 assert(FPTL && "no prototype for constructor declaration");
@@ -2526,11 +2523,27 @@ struct ConvertConstructorToDeductionGuideTransform {
 
 //-- The types of the function parameters are those of the constructor.
 for (auto *OldParam : TL.getParams()) {
-  ParmVarDecl *NewParam =
-  transformFunctionTypeParam(OldParam, Args, MaterializedTypedefs);
-  if (NestedPattern && NewParam)
+  ParmVarDecl *NewParam = OldParam;
+  // Given
+  //   template  struct C {
+  // template  struct D {
+  //   template  D(U, V);
+  // };
+  //   };
+  // First, transform all the references to template parameters that are
+  // defined outside of the surrounding class template. That is T in the
+  // above example.
+  if (NestedPattern) {
 NewParam = transformFunctionTypeParam(NewParam, OuterInstantiationArgs,
   MaterializedTypedefs);
+if (!NewParam)
+  return QualType();
+  }
+  // Then, transform all the references to template parameters that are
+  // defined at the class template and the constructor. In this example,
+  // they're U and V, respectively.
+  NewParam =
+  transformFunctionTypeParam(NewParam, Args, MaterializedTypedefs);
   if (!NewParam)
 return QualType();
   ParamTypes.push_back(NewParam->getType());

diff  --git a/clang/test/SemaTemplate/nested-implicit-deduction-guides.cpp 
b/clang/test/SemaTemplate/nested-implicit-deduction-guides.cpp
index 38b6706595a11..f289dc0452868 100644
--- a/clang/test/SemaTemplate/nested-implicit-deduction-guides.cpp
+++ b/clang/test/SemaTemplate/nested-implicit-deduction-guides.cpp
@@ -84,3 +84,17 @@ nested_init_list::concept_fail nil_invalid{1, ""};
 // expected-note@#INIT_LIST_INNER_INVALID {{candidate template ignored: 
substitution failure [with F = const char *]: constraints not satisfied for 
class te

[llvm-branch-commits] [clang] release/18.x: [Clang][Sema] Revise the transformation of CTAD parameters of nested class templates (#91628) (PR #91890)

2024-05-13 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar closed 
https://github.com/llvm/llvm-project/pull/91890
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/18.x: [Clang][Sema] Revise the transformation of CTAD parameters of nested class templates (#91628) (PR #91890)

2024-05-13 Thread Tom Stellard via llvm-branch-commits

tstellar wrote:

@zyn0217 (or anyone else). If you would like to add a note about this fix in 
the release notes (completely optional). Please reply to this comment with a 
one or two sentence description of the fix.  When you are done, please add the 
release:note label to this PR. 

https://github.com/llvm/llvm-project/pull/91890
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/18.x: [clang-format] Fix a crash with AlignArrayOfStructures option (#86420) (PR #91049)

2024-05-13 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar updated 
https://github.com/llvm/llvm-project/pull/91049

>From f1491c7460e788f15d3fc2ad2a6bcf86606272ec Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sun, 24 Mar 2024 15:22:40 -0700
Subject: [PATCH] [clang-format] Fix a crash with AlignArrayOfStructures option
 (#86420)

Fixes #86109.

(cherry picked from commit cceedc939a43c7c732a5888364251775bffc2dba)
---
 clang/lib/Format/WhitespaceManager.cpp |  2 +-
 clang/unittests/Format/FormatTest.cpp  | 18 --
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index df84f97a8e8ac..7525e6ee650b6 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1466,7 +1466,7 @@ WhitespaceManager::CellDescriptions 
WhitespaceManager::getCells(unsigned Start,
 : Cell);
 // Go to the next non-comment and ensure there is a break in front
 const auto *NextNonComment = C.Tok->getNextNonComment();
-while (NextNonComment->is(tok::comma))
+while (NextNonComment && NextNonComment->is(tok::comma))
   NextNonComment = NextNonComment->getNextNonComment();
 auto j = i;
 while (Changes[j].Tok != NextNonComment && j < End)
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 923128672c316..0161a1685eb12 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -20955,7 +20955,14 @@ TEST_F(FormatTest, 
CatchAlignArrayOfStructuresRightAlignment) {
 "[0] = {1, 1},\n"
 "[1] { 1, 1, },\n"
 "[2] { 1, 1, },\n"
-"};");
+"};",
+Style);
+  verifyNoCrash("test arr[] = {\n"
+"#define FOO(i) {i, i},\n"
+"SOME_GENERATOR(FOO)\n"
+"{2, 2}\n"
+"};",
+Style);
 
   verifyFormat("return GradForUnaryCwise(g, {\n"
"{{\"sign\"}, \"Sign\",  "
@@ -21208,7 +21215,14 @@ TEST_F(FormatTest, 
CatchAlignArrayOfStructuresLeftAlignment) {
 "[0] = {1, 1},\n"
 "[1] { 1, 1, },\n"
 "[2] { 1, 1, },\n"
-"};");
+"};",
+Style);
+  verifyNoCrash("test arr[] = {\n"
+"#define FOO(i) {i, i},\n"
+"SOME_GENERATOR(FOO)\n"
+"{2, 2}\n"
+"};",
+Style);
 
   verifyFormat("return GradForUnaryCwise(g, {\n"
"{{\"sign\"}, \"Sign\", {\"x\", 
"

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/18.x: [clang-format] Fix a crash with AlignArrayOfStructures option (#86420) (PR #91049)

2024-05-13 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar closed 
https://github.com/llvm/llvm-project/pull/91049
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] f1491c7 - [clang-format] Fix a crash with AlignArrayOfStructures option (#86420)

2024-05-13 Thread Tom Stellard via llvm-branch-commits

Author: Owen Pan
Date: 2024-05-13T17:55:32-07:00
New Revision: f1491c7460e788f15d3fc2ad2a6bcf86606272ec

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

LOG: [clang-format] Fix a crash with AlignArrayOfStructures option (#86420)

Fixes #86109.

(cherry picked from commit cceedc939a43c7c732a5888364251775bffc2dba)

Added: 


Modified: 
clang/lib/Format/WhitespaceManager.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index df84f97a8e8ac..7525e6ee650b6 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1466,7 +1466,7 @@ WhitespaceManager::CellDescriptions 
WhitespaceManager::getCells(unsigned Start,
 : Cell);
 // Go to the next non-comment and ensure there is a break in front
 const auto *NextNonComment = C.Tok->getNextNonComment();
-while (NextNonComment->is(tok::comma))
+while (NextNonComment && NextNonComment->is(tok::comma))
   NextNonComment = NextNonComment->getNextNonComment();
 auto j = i;
 while (Changes[j].Tok != NextNonComment && j < End)

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 923128672c316..0161a1685eb12 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -20955,7 +20955,14 @@ TEST_F(FormatTest, 
CatchAlignArrayOfStructuresRightAlignment) {
 "[0] = {1, 1},\n"
 "[1] { 1, 1, },\n"
 "[2] { 1, 1, },\n"
-"};");
+"};",
+Style);
+  verifyNoCrash("test arr[] = {\n"
+"#define FOO(i) {i, i},\n"
+"SOME_GENERATOR(FOO)\n"
+"{2, 2}\n"
+"};",
+Style);
 
   verifyFormat("return GradForUnaryCwise(g, {\n"
"{{\"sign\"}, \"Sign\",  "
@@ -21208,7 +21215,14 @@ TEST_F(FormatTest, 
CatchAlignArrayOfStructuresLeftAlignment) {
 "[0] = {1, 1},\n"
 "[1] { 1, 1, },\n"
 "[2] { 1, 1, },\n"
-"};");
+"};",
+Style);
+  verifyNoCrash("test arr[] = {\n"
+"#define FOO(i) {i, i},\n"
+"SOME_GENERATOR(FOO)\n"
+"{2, 2}\n"
+"};",
+Style);
 
   verifyFormat("return GradForUnaryCwise(g, {\n"
"{{\"sign\"}, \"Sign\", {\"x\", 
"



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/18.x: [clang-format] Fix a crash with AlignArrayOfStructures option (#86420) (PR #91049)

2024-05-13 Thread Tom Stellard via llvm-branch-commits

tstellar wrote:

@owenca (or anyone else). If you would like to add a note about this fix in the 
release notes (completely optional). Please reply to this comment with a one or 
two sentence description of the fix.  When you are done, please add the 
release:note label to this PR. 

https://github.com/llvm/llvm-project/pull/91049
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/18.x: [PPCMergeStringPool] Avoid replacing constant with instruction (#88846) (PR #91557)

2024-05-13 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar updated 
https://github.com/llvm/llvm-project/pull/91557

>From 1184a9cb30e6a12c883b918867f2f06bc3096fc0 Mon Sep 17 00:00:00 2001
From: Nikita Popov 
Date: Thu, 9 May 2024 13:27:20 +0900
Subject: [PATCH] [PPCMergeStringPool] Avoid replacing constant with
 instruction (#88846)

String pool merging currently, for a reason that's not entirely clear to
me, tries to create GEP instructions instead of GEP constant expressions
when replacing constant references. It only uses constant expressions in
cases where this is required. However, it does not catch all cases where
such a requirement exists. For example, the landingpad catch clause has
to be a constant.

Fix this by always using the constant expression variant, which also
makes the implementation simpler.

Additionally, there are some edge cases where even replacement with a
constant GEP is not legal. The one I am aware of is the
llvm.eh.typeid.for intrinsic, so add a special case to forbid
replacements for it.

Fixes https://github.com/llvm/llvm-project/issues/88844.

(cherry picked from commit 3a3aeb8eba40e981d3a9ff92175f949c2f3d4434)
---
 .../lib/Target/PowerPC/PPCMergeStringPool.cpp | 57 ++-
 .../mergeable-string-pool-exceptions.ll   | 47 +++
 .../PowerPC/mergeable-string-pool-large.ll| 14 ++---
 .../mergeable-string-pool-pass-only.mir   | 18 +++---
 .../CodeGen/PowerPC/mergeable-string-pool.ll  | 14 ++---
 5 files changed, 87 insertions(+), 63 deletions(-)
 create mode 100644 
llvm/test/CodeGen/PowerPC/mergeable-string-pool-exceptions.ll

diff --git a/llvm/lib/Target/PowerPC/PPCMergeStringPool.cpp 
b/llvm/lib/Target/PowerPC/PPCMergeStringPool.cpp
index d9465e86d8966..ebd876d50c44e 100644
--- a/llvm/lib/Target/PowerPC/PPCMergeStringPool.cpp
+++ b/llvm/lib/Target/PowerPC/PPCMergeStringPool.cpp
@@ -23,6 +23,7 @@
 #include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/Instructions.h"
+#include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/ValueSymbolTable.h"
 #include "llvm/Pass.h"
@@ -116,9 +117,20 @@ class PPCMergeStringPool : public ModulePass {
 // sure that they can be replaced.
 static bool hasReplaceableUsers(GlobalVariable &GV) {
   for (User *CurrentUser : GV.users()) {
-// Instruction users are always valid.
-if (isa(CurrentUser))
+if (auto *I = dyn_cast(CurrentUser)) {
+  // Do not merge globals in exception pads.
+  if (I->isEHPad())
+return false;
+
+  if (auto *II = dyn_cast(I)) {
+// Some intrinsics require a plain global.
+if (II->getIntrinsicID() == Intrinsic::eh_typeid_for)
+  return false;
+  }
+
+  // Other instruction users are always valid.
   continue;
+}
 
 // We cannot replace GlobalValue users because they are not just nodes
 // in IR. To replace a user like this we would need to create a new
@@ -302,14 +314,6 @@ void PPCMergeStringPool::replaceUsesWithGEP(GlobalVariable 
*GlobalToReplace,
 Users.push_back(CurrentUser);
 
   for (User *CurrentUser : Users) {
-Instruction *UserInstruction = dyn_cast(CurrentUser);
-Constant *UserConstant = dyn_cast(CurrentUser);
-
-// At this point we expect that the user is either an instruction or a
-// constant.
-assert((UserConstant || UserInstruction) &&
-   "Expected the user to be an instruction or a constant.");
-
 // The user was not found so it must have been replaced earlier.
 if (!userHasOperand(CurrentUser, GlobalToReplace))
   continue;
@@ -318,38 +322,13 @@ void 
PPCMergeStringPool::replaceUsesWithGEP(GlobalVariable *GlobalToReplace,
 if (isa(CurrentUser))
   continue;
 
-if (!UserInstruction) {
-  // User is a constant type.
-  Constant *ConstGEP = ConstantExpr::getInBoundsGetElementPtr(
-  PooledStructType, GPool, Indices);
-  UserConstant->handleOperandChange(GlobalToReplace, ConstGEP);
-  continue;
-}
-
-if (PHINode *UserPHI = dyn_cast(UserInstruction)) {
-  // GEP instructions cannot be added before PHI nodes.
-  // With getInBoundsGetElementPtr we create the GEP and then replace it
-  // inline into the PHI.
-  Constant *ConstGEP = ConstantExpr::getInBoundsGetElementPtr(
-  PooledStructType, GPool, Indices);
-  UserPHI->replaceUsesOfWith(GlobalToReplace, ConstGEP);
-  continue;
-}
-// The user is a valid instruction that is not a PHINode.
-GetElementPtrInst *GEPInst =
-GetElementPtrInst::Create(PooledStructType, GPool, Indices);
-GEPInst->insertBefore(UserInstruction);
-
-LLVM_DEBUG(dbgs() << "Inserting GEP before:\n");
-LLVM_DEBUG(UserInstruction->dump());
-
+Constant *ConstGEP = ConstantExpr::getInBoundsGetElementPtr(
+PooledStructType, GPool, Indices);
 LLVM_DEBUG(dbgs() << "Replacing this global:\n");
 LLVM_DEBUG(GlobalToReplace->dump());
 LLVM_DEBUG(dbgs() << "with this:\n");
-

[llvm-branch-commits] [llvm] 1184a9c - [PPCMergeStringPool] Avoid replacing constant with instruction (#88846)

2024-05-13 Thread Tom Stellard via llvm-branch-commits

Author: Nikita Popov
Date: 2024-05-13T17:59:22-07:00
New Revision: 1184a9cb30e6a12c883b918867f2f06bc3096fc0

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

LOG: [PPCMergeStringPool] Avoid replacing constant with instruction (#88846)

String pool merging currently, for a reason that's not entirely clear to
me, tries to create GEP instructions instead of GEP constant expressions
when replacing constant references. It only uses constant expressions in
cases where this is required. However, it does not catch all cases where
such a requirement exists. For example, the landingpad catch clause has
to be a constant.

Fix this by always using the constant expression variant, which also
makes the implementation simpler.

Additionally, there are some edge cases where even replacement with a
constant GEP is not legal. The one I am aware of is the
llvm.eh.typeid.for intrinsic, so add a special case to forbid
replacements for it.

Fixes https://github.com/llvm/llvm-project/issues/88844.

(cherry picked from commit 3a3aeb8eba40e981d3a9ff92175f949c2f3d4434)

Added: 
llvm/test/CodeGen/PowerPC/mergeable-string-pool-exceptions.ll

Modified: 
llvm/lib/Target/PowerPC/PPCMergeStringPool.cpp
llvm/test/CodeGen/PowerPC/mergeable-string-pool-large.ll
llvm/test/CodeGen/PowerPC/mergeable-string-pool-pass-only.mir
llvm/test/CodeGen/PowerPC/mergeable-string-pool.ll

Removed: 




diff  --git a/llvm/lib/Target/PowerPC/PPCMergeStringPool.cpp 
b/llvm/lib/Target/PowerPC/PPCMergeStringPool.cpp
index d9465e86d8966..ebd876d50c44e 100644
--- a/llvm/lib/Target/PowerPC/PPCMergeStringPool.cpp
+++ b/llvm/lib/Target/PowerPC/PPCMergeStringPool.cpp
@@ -23,6 +23,7 @@
 #include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/Instructions.h"
+#include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/ValueSymbolTable.h"
 #include "llvm/Pass.h"
@@ -116,9 +117,20 @@ class PPCMergeStringPool : public ModulePass {
 // sure that they can be replaced.
 static bool hasReplaceableUsers(GlobalVariable &GV) {
   for (User *CurrentUser : GV.users()) {
-// Instruction users are always valid.
-if (isa(CurrentUser))
+if (auto *I = dyn_cast(CurrentUser)) {
+  // Do not merge globals in exception pads.
+  if (I->isEHPad())
+return false;
+
+  if (auto *II = dyn_cast(I)) {
+// Some intrinsics require a plain global.
+if (II->getIntrinsicID() == Intrinsic::eh_typeid_for)
+  return false;
+  }
+
+  // Other instruction users are always valid.
   continue;
+}
 
 // We cannot replace GlobalValue users because they are not just nodes
 // in IR. To replace a user like this we would need to create a new
@@ -302,14 +314,6 @@ void PPCMergeStringPool::replaceUsesWithGEP(GlobalVariable 
*GlobalToReplace,
 Users.push_back(CurrentUser);
 
   for (User *CurrentUser : Users) {
-Instruction *UserInstruction = dyn_cast(CurrentUser);
-Constant *UserConstant = dyn_cast(CurrentUser);
-
-// At this point we expect that the user is either an instruction or a
-// constant.
-assert((UserConstant || UserInstruction) &&
-   "Expected the user to be an instruction or a constant.");
-
 // The user was not found so it must have been replaced earlier.
 if (!userHasOperand(CurrentUser, GlobalToReplace))
   continue;
@@ -318,38 +322,13 @@ void 
PPCMergeStringPool::replaceUsesWithGEP(GlobalVariable *GlobalToReplace,
 if (isa(CurrentUser))
   continue;
 
-if (!UserInstruction) {
-  // User is a constant type.
-  Constant *ConstGEP = ConstantExpr::getInBoundsGetElementPtr(
-  PooledStructType, GPool, Indices);
-  UserConstant->handleOperandChange(GlobalToReplace, ConstGEP);
-  continue;
-}
-
-if (PHINode *UserPHI = dyn_cast(UserInstruction)) {
-  // GEP instructions cannot be added before PHI nodes.
-  // With getInBoundsGetElementPtr we create the GEP and then replace it
-  // inline into the PHI.
-  Constant *ConstGEP = ConstantExpr::getInBoundsGetElementPtr(
-  PooledStructType, GPool, Indices);
-  UserPHI->replaceUsesOfWith(GlobalToReplace, ConstGEP);
-  continue;
-}
-// The user is a valid instruction that is not a PHINode.
-GetElementPtrInst *GEPInst =
-GetElementPtrInst::Create(PooledStructType, GPool, Indices);
-GEPInst->insertBefore(UserInstruction);
-
-LLVM_DEBUG(dbgs() << "Inserting GEP before:\n");
-LLVM_DEBUG(UserInstruction->dump());
-
+Constant *ConstGEP = ConstantExpr::getInBoundsGetElementPtr(
+PooledStructType, GPool, Indices);
 LLVM_DEBUG(dbgs() << "Replacing this global:\n");
 LLVM_DEBUG(GlobalToReplace->dump());
 LLVM

[llvm-branch-commits] [llvm] release/18.x: [PPCMergeStringPool] Avoid replacing constant with instruction (#88846) (PR #91557)

2024-05-13 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar closed 
https://github.com/llvm/llvm-project/pull/91557
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/18.x: [PPCMergeStringPool] Avoid replacing constant with instruction (#88846) (PR #91557)

2024-05-13 Thread Tom Stellard via llvm-branch-commits

tstellar wrote:

@nikic (or anyone else). If you would like to add a note about this fix in the 
release notes (completely optional). Please reply to this comment with a one or 
two sentence description of the fix.  When you are done, please add the 
release:note label to this PR.

https://github.com/llvm/llvm-project/pull/91557
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] release/18.x: [lld][WebAssembly] Fix test on Windows, use llvm-ar instead of ar (PR #91967)

2024-05-13 Thread Sam Clegg via llvm-branch-commits

sbc100 wrote:

Since this is just a test fix I don't think it needs to be in the release notes 
(but I could be wrong).

https://github.com/llvm/llvm-project/pull/91967
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] [llvm] release/18.x: [RISCV][lld] Set the type of TLSDESC relocation's referenced local symbol to STT_NOTYPE (PR #91678)

2024-05-13 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar updated 
https://github.com/llvm/llvm-project/pull/91678

>From 6cfa40e450cfe7980a0c4aa0e17a8367b89f8d39 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Fri, 22 Mar 2024 12:27:41 -0700
Subject: [PATCH] [RISCV][lld] Set the type of TLSDESC relocation's referenced
 local symbol to STT_NOTYPE

When adding fixups for RISCV_TLSDESC_ADD_LO and RISCV_TLSDESC_LOAD_LO,
the local label added for RISCV TLSDESC relocations have STT_TLS set,
which is incorrect. Instead, these labels should have `STT_NOTYPE`.

This patch stops adding such fixups and avoid setting the STT_TLS on
these symbols. Failing to do so can cause LLD to emit an error `has an
STT_TLS symbol but doesn't have an SHF_TLS section`. We additionally,
adjust how LLD services these relocations to avoid errors with
incompatible relocation and symbol types.

Reviewers: topperc, MaskRay

Reviewed By: MaskRay

Pull Request: https://github.com/llvm/llvm-project/pull/85817

(cherry picked from commit dfe4ca9b7f4a422500d78280dc5eefd1979939e6)
---
 lld/ELF/Relocations.cpp   |  5 +++-
 lld/test/ELF/riscv-tlsdesc-relax.s|  8 ++
 lld/test/ELF/riscv-tlsdesc.s  | 27 +++
 .../Target/RISCV/MCTargetDesc/RISCVMCExpr.cpp |  2 --
 4 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 619fbaf5dc545..92a1b9baaca3d 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -1480,7 +1480,10 @@ template  void 
RelocationScanner::scanOne(RelTy *&i) {
 
   // Process TLS relocations, including TLS optimizations. Note that
   // R_TPREL and R_TPREL_NEG relocations are resolved in processAux.
-  if (sym.isTls()) {
+  //
+  // Some RISCV TLSDESC relocations reference a local NOTYPE symbol,
+  // but we need to process them in handleTlsRelocation.
+  if (sym.isTls() || oneof(expr)) {
 if (unsigned processed =
 handleTlsRelocation(type, sym, *sec, offset, addend, expr)) {
   i += processed - 1;
diff --git a/lld/test/ELF/riscv-tlsdesc-relax.s 
b/lld/test/ELF/riscv-tlsdesc-relax.s
index fb24317e6535c..5718d4175be11 100644
--- a/lld/test/ELF/riscv-tlsdesc-relax.s
+++ b/lld/test/ELF/riscv-tlsdesc-relax.s
@@ -33,12 +33,14 @@
 # GD64-NEXT: c.add   a0, tp
 # GD64-NEXT: jal {{.*}} 
 ## &.got[c]-. = 0x20c0+8 - 0x1020 = 0x10a8
+# GD64-LABEL: <.Ltlsdesc_hi1>:
 # GD64-NEXT:   1020: auipc   a4, 0x1
 # GD64-NEXT: ld  a5, 0xa8(a4)
 # GD64-NEXT: addia0, a4, 0xa8
 # GD64-NEXT: jalrt0, 0x0(a5)
 # GD64-NEXT: c.add   a0, tp
 ## &.got[c]-. = 0x20c0+8 - 0x1032 = 0x1096
+# GD64-LABEL: <.Ltlsdesc_hi2>:
 # GD64-NEXT:   1032: auipc   a6, 0x1
 # GD64-NEXT: ld  a7, 0x96(a6)
 # GD64-NEXT: addia0, a6, 0x96
@@ -64,6 +66,7 @@
 # LE64-NEXT: jal {{.*}} 
 # LE64-NEXT: R_RISCV_JAL foo
 # LE64-NEXT: R_RISCV_RELAX *ABS*
+# LE64-LABEL: <.Ltlsdesc_hi1>:
 # LE64-NEXT: addia0, zero, 0x7ff
 # LE64-NEXT: R_RISCV_TLSDESC_HI20 b
 # LE64-NEXT: R_RISCV_RELAX *ABS*
@@ -71,6 +74,7 @@
 # LE64-NEXT: R_RISCV_TLSDESC_ADD_LO12 .Ltlsdesc_hi1
 # LE64-NEXT: R_RISCV_TLSDESC_CALL .Ltlsdesc_hi1
 # LE64-NEXT: c.add   a0, tp
+# LE64-LABEL: <.Ltlsdesc_hi2>:
 # LE64-NEXT: addizero, zero, 0x0
 # LE64-NEXT: R_RISCV_TLSDESC_HI20 b
 # LE64-NEXT: addizero, zero, 0x0
@@ -93,9 +97,11 @@
 # LE64A-NEXT: addia0, a0, -0x479
 # LE64A-NEXT: c.add   a0, tp
 # LE64A-NEXT: jal {{.*}} 
+# LE64A-LABEL: <.Ltlsdesc_hi1>:
 # LE64A-NEXT: lui a0, 0x2
 # LE64A-NEXT: addia0, a0, -0x479
 # LE64A-NEXT: c.add   a0, tp
+# LE64A-LABEL: <.Ltlsdesc_hi2>:
 # LE64A-NEXT: addizero, zero, 0x0
 # LE64A-NEXT: addizero, zero, 0x0
 # LE64A-NEXT: lui a0, 0x2
@@ -115,10 +121,12 @@
 # IE64-NEXT: c.add   a0, tp
 # IE64-NEXT: jal {{.*}} 
 ## &.got[c]-. = 0x120e0+8 - 0x11018 = 0x10d0
+# IE64-LABEL: <.Ltlsdesc_hi1>:
 # IE64-NEXT:  11018: auipc   a0, 0x1
 # IE64-NEXT: ld  a0, 0xd0(a0)
 # IE64-NEXT: c.add   a0, tp
 ## &.got[c]-. = 0x120e0+8 - 0x1102a = 0x10be
+# IE64-LABEL: <.Ltlsdesc_hi2>:
 # IE64-NEXT: addizero, zero, 0x0
 # IE64-NEXT: addizero, zero, 0x0
 # IE64-NEXT:  1102a: auipc   a0, 0x1
diff --git a/lld/test/ELF/riscv-tlsdesc.s b/lld/test/ELF/riscv-tlsdesc.s
index c583e15cf30ce..935ecbddfbfff 100644
--- a/lld/test/ELF/riscv-tlsdesc.s
+++ b/lld/test/ELF/riscv-tlsdesc.s
@@ -29,11 +29,13 @@
 # RUN: ld.lld -e 0 -z now a.32.o c.32.so -o a.32.ie
 # RUN: llvm-objdump --no-show-raw-insn -M no-aliases -h -d a.32.ie | FileCheck 
%s --check-prefix=IE32
 
-# RUN: llvm-mc -triple=riscv64 -filetype=obj d.s -o d.64.o
-# RUN: not ld.lld -shared -soname=d.64.so -o d.64.so d.64.o 2>&1 | FileCheck 
%s --c

[llvm-branch-commits] [lld] 6cfa40e - [RISCV][lld] Set the type of TLSDESC relocation's referenced local symbol to STT_NOTYPE

2024-05-13 Thread Tom Stellard via llvm-branch-commits

Author: Paul Kirth
Date: 2024-05-13T18:08:07-07:00
New Revision: 6cfa40e450cfe7980a0c4aa0e17a8367b89f8d39

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

LOG: [RISCV][lld] Set the type of TLSDESC relocation's referenced local symbol 
to STT_NOTYPE

When adding fixups for RISCV_TLSDESC_ADD_LO and RISCV_TLSDESC_LOAD_LO,
the local label added for RISCV TLSDESC relocations have STT_TLS set,
which is incorrect. Instead, these labels should have `STT_NOTYPE`.

This patch stops adding such fixups and avoid setting the STT_TLS on
these symbols. Failing to do so can cause LLD to emit an error `has an
STT_TLS symbol but doesn't have an SHF_TLS section`. We additionally,
adjust how LLD services these relocations to avoid errors with
incompatible relocation and symbol types.

Reviewers: topperc, MaskRay

Reviewed By: MaskRay

Pull Request: https://github.com/llvm/llvm-project/pull/85817

(cherry picked from commit dfe4ca9b7f4a422500d78280dc5eefd1979939e6)

Added: 


Modified: 
lld/ELF/Relocations.cpp
lld/test/ELF/riscv-tlsdesc-relax.s
lld/test/ELF/riscv-tlsdesc.s
llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.cpp

Removed: 




diff  --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 619fbaf5dc545..92a1b9baaca3d 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -1480,7 +1480,10 @@ template  void 
RelocationScanner::scanOne(RelTy *&i) {
 
   // Process TLS relocations, including TLS optimizations. Note that
   // R_TPREL and R_TPREL_NEG relocations are resolved in processAux.
-  if (sym.isTls()) {
+  //
+  // Some RISCV TLSDESC relocations reference a local NOTYPE symbol,
+  // but we need to process them in handleTlsRelocation.
+  if (sym.isTls() || oneof(expr)) {
 if (unsigned processed =
 handleTlsRelocation(type, sym, *sec, offset, addend, expr)) {
   i += processed - 1;

diff  --git a/lld/test/ELF/riscv-tlsdesc-relax.s 
b/lld/test/ELF/riscv-tlsdesc-relax.s
index fb24317e6535c..5718d4175be11 100644
--- a/lld/test/ELF/riscv-tlsdesc-relax.s
+++ b/lld/test/ELF/riscv-tlsdesc-relax.s
@@ -33,12 +33,14 @@
 # GD64-NEXT: c.add   a0, tp
 # GD64-NEXT: jal {{.*}} 
 ## &.got[c]-. = 0x20c0+8 - 0x1020 = 0x10a8
+# GD64-LABEL: <.Ltlsdesc_hi1>:
 # GD64-NEXT:   1020: auipc   a4, 0x1
 # GD64-NEXT: ld  a5, 0xa8(a4)
 # GD64-NEXT: addia0, a4, 0xa8
 # GD64-NEXT: jalrt0, 0x0(a5)
 # GD64-NEXT: c.add   a0, tp
 ## &.got[c]-. = 0x20c0+8 - 0x1032 = 0x1096
+# GD64-LABEL: <.Ltlsdesc_hi2>:
 # GD64-NEXT:   1032: auipc   a6, 0x1
 # GD64-NEXT: ld  a7, 0x96(a6)
 # GD64-NEXT: addia0, a6, 0x96
@@ -64,6 +66,7 @@
 # LE64-NEXT: jal {{.*}} 
 # LE64-NEXT: R_RISCV_JAL foo
 # LE64-NEXT: R_RISCV_RELAX *ABS*
+# LE64-LABEL: <.Ltlsdesc_hi1>:
 # LE64-NEXT: addia0, zero, 0x7ff
 # LE64-NEXT: R_RISCV_TLSDESC_HI20 b
 # LE64-NEXT: R_RISCV_RELAX *ABS*
@@ -71,6 +74,7 @@
 # LE64-NEXT: R_RISCV_TLSDESC_ADD_LO12 .Ltlsdesc_hi1
 # LE64-NEXT: R_RISCV_TLSDESC_CALL .Ltlsdesc_hi1
 # LE64-NEXT: c.add   a0, tp
+# LE64-LABEL: <.Ltlsdesc_hi2>:
 # LE64-NEXT: addizero, zero, 0x0
 # LE64-NEXT: R_RISCV_TLSDESC_HI20 b
 # LE64-NEXT: addizero, zero, 0x0
@@ -93,9 +97,11 @@
 # LE64A-NEXT: addia0, a0, -0x479
 # LE64A-NEXT: c.add   a0, tp
 # LE64A-NEXT: jal {{.*}} 
+# LE64A-LABEL: <.Ltlsdesc_hi1>:
 # LE64A-NEXT: lui a0, 0x2
 # LE64A-NEXT: addia0, a0, -0x479
 # LE64A-NEXT: c.add   a0, tp
+# LE64A-LABEL: <.Ltlsdesc_hi2>:
 # LE64A-NEXT: addizero, zero, 0x0
 # LE64A-NEXT: addizero, zero, 0x0
 # LE64A-NEXT: lui a0, 0x2
@@ -115,10 +121,12 @@
 # IE64-NEXT: c.add   a0, tp
 # IE64-NEXT: jal {{.*}} 
 ## &.got[c]-. = 0x120e0+8 - 0x11018 = 0x10d0
+# IE64-LABEL: <.Ltlsdesc_hi1>:
 # IE64-NEXT:  11018: auipc   a0, 0x1
 # IE64-NEXT: ld  a0, 0xd0(a0)
 # IE64-NEXT: c.add   a0, tp
 ## &.got[c]-. = 0x120e0+8 - 0x1102a = 0x10be
+# IE64-LABEL: <.Ltlsdesc_hi2>:
 # IE64-NEXT: addizero, zero, 0x0
 # IE64-NEXT: addizero, zero, 0x0
 # IE64-NEXT:  1102a: auipc   a0, 0x1

diff  --git a/lld/test/ELF/riscv-tlsdesc.s b/lld/test/ELF/riscv-tlsdesc.s
index c583e15cf30ce..935ecbddfbfff 100644
--- a/lld/test/ELF/riscv-tlsdesc.s
+++ b/lld/test/ELF/riscv-tlsdesc.s
@@ -29,11 +29,13 @@
 # RUN: ld.lld -e 0 -z now a.32.o c.32.so -o a.32.ie
 # RUN: llvm-objdump --no-show-raw-insn -M no-aliases -h -d a.32.ie | FileCheck 
%s --check-prefix=IE32
 
-# RUN: llvm-mc -triple=riscv64 -filetype=obj d.s -o d.64.o
-# RUN: not ld.lld -shared -so

[llvm-branch-commits] [llvm] release/18.x: [InstCombine] Drop nuw flag when CtlzOp is a sub nuw (#91776) (PR #91917)

2024-05-13 Thread Nikita Popov via llvm-branch-commits

https://github.com/nikic requested changes to this pull request.

Looks like the test is failing on the release branch.

https://github.com/llvm/llvm-project/pull/91917
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] [llvm] release/18.x: [RISCV][lld] Set the type of TLSDESC relocation's referenced local symbol to STT_NOTYPE (PR #91678)

2024-05-13 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar closed 
https://github.com/llvm/llvm-project/pull/91678
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] [llvm] release/18.x: [RISCV][lld] Set the type of TLSDESC relocation's referenced local symbol to STT_NOTYPE (PR #91678)

2024-05-13 Thread Tom Stellard via llvm-branch-commits

tstellar wrote:

@ilovepi (or anyone else). If you would like to add a note about this fix in 
the release notes (completely optional). Please reply to this comment with a 
one or two sentence description of the fix.  When you are done, please add the 
release:note label to this PR.


https://github.com/llvm/llvm-project/pull/91678
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/18.x: [InstCombine] Drop nuw flag when CtlzOp is a sub nuw (#91776) (PR #91917)

2024-05-13 Thread Yingwei Zheng via llvm-branch-commits


@@ -284,6 +284,42 @@ define <4 x i32> @bit_ceil_v4i32(<4 x i32> %x) {
   ret <4 x i32> %sel
 }
 
+define i32 @pr91691(i32 %0) {
+; CHECK-LABEL: @pr91691(
+; CHECK-NEXT:[[TMP2:%.*]] = sub i32 -2, [[TMP0:%.*]]
+; CHECK-NEXT:[[TMP3:%.*]] = tail call range(i32 0, 33) i32 
@llvm.ctlz.i32(i32 [[TMP2]], i1 false)
+; CHECK-NEXT:[[TMP4:%.*]] = sub nsw i32 0, [[TMP3]]
+; CHECK-NEXT:[[TMP5:%.*]] = and i32 [[TMP4]], 31
+; CHECK-NEXT:[[TMP6:%.*]] = shl nuw i32 1, [[TMP5]]
+; CHECK-NEXT:ret i32 [[TMP6]]
+;
+  %2 = sub nuw i32 -2, %0
+  %3 = tail call i32 @llvm.ctlz.i32(i32 %2, i1 false)
+  %4 = sub i32 32, %3
+  %5 = shl i32 1, %4
+  %6 = icmp ult i32 %0, -2
+  %7 = select i1 %6, i32 %5, i32 1
+  ret i32 %7
+}
+
+define i32 @pr91691_keep_nsw(i32 %0) {
+; CHECK-LABEL: @pr91691_keep_nsw(
+; CHECK-NEXT:[[TMP2:%.*]] = sub nsw i32 -2, [[TMP0:%.*]]
+; CHECK-NEXT:[[TMP3:%.*]] = tail call range(i32 0, 33) i32 
@llvm.ctlz.i32(i32 [[TMP2]], i1 false)
+; CHECK-NEXT:[[TMP4:%.*]] = sub nsw i32 0, [[TMP3]]
+; CHECK-NEXT:[[TMP5:%.*]] = and i32 [[TMP4]], 31
+; CHECK-NEXT:[[TMP6:%.*]] = shl nuw i32 1, [[TMP5]]
+; CHECK-NEXT:ret i32 [[TMP6]]
+;
+  %2 = sub nsw i32 -2, %0
+  %3 = tail call i32 @llvm.ctlz.i32(i32 %2, i1 false)
+  %4 = sub i32 32, %3
+  %5 = shl i32 1, %4
+  %6 = icmp ult i32 %0, -2
+  %7 = select i1 %6, i32 %5, i32 1
+  ret i32 %7
+}
+

dtcxzyw wrote:

```suggestion
define i32 @pr91691(i32 %0) {
; CHECK-LABEL: @pr91691(
; CHECK-NEXT:[[TMP2:%.*]] = sub i32 -2, [[TMP0:%.*]]
; CHECK-NEXT:[[TMP3:%.*]] = tail call i32 @llvm.ctlz.i32(i32 [[TMP2]], i1 
false), !range [[RNG0]]
; CHECK-NEXT:[[TMP4:%.*]] = sub nsw i32 0, [[TMP3]]
; CHECK-NEXT:[[TMP5:%.*]] = and i32 [[TMP4]], 31
; CHECK-NEXT:[[TMP6:%.*]] = shl nuw i32 1, [[TMP5]]
; CHECK-NEXT:ret i32 [[TMP6]]
;
  %2 = sub nuw i32 -2, %0
  %3 = tail call i32 @llvm.ctlz.i32(i32 %2, i1 false)
  %4 = sub i32 32, %3
  %5 = shl i32 1, %4
  %6 = icmp ult i32 %0, -2
  %7 = select i1 %6, i32 %5, i32 1
  ret i32 %7
}

define i32 @pr91691_keep_nsw(i32 %0) {
; CHECK-LABEL: @pr91691_keep_nsw(
; CHECK-NEXT:[[TMP2:%.*]] = sub nsw i32 -2, [[TMP0:%.*]]
; CHECK-NEXT:[[TMP3:%.*]] = tail call i32 @llvm.ctlz.i32(i32 [[TMP2]], i1 
false), !range [[RNG0]]
; CHECK-NEXT:[[TMP4:%.*]] = sub nsw i32 0, [[TMP3]]
; CHECK-NEXT:[[TMP5:%.*]] = and i32 [[TMP4]], 31
; CHECK-NEXT:[[TMP6:%.*]] = shl nuw i32 1, [[TMP5]]
; CHECK-NEXT:ret i32 [[TMP6]]
;
  %2 = sub nsw i32 -2, %0
  %3 = tail call i32 @llvm.ctlz.i32(i32 %2, i1 false)
  %4 = sub i32 32, %3
  %5 = shl i32 1, %4
  %6 = icmp ult i32 %0, -2
  %7 = select i1 %6, i32 %5, i32 1
  ret i32 %7
}

```

https://github.com/llvm/llvm-project/pull/91917
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/18.x: [InstCombine] Drop nuw flag when CtlzOp is a sub nuw (#91776) (PR #91917)

2024-05-13 Thread Yingwei Zheng via llvm-branch-commits


@@ -284,6 +284,42 @@ define <4 x i32> @bit_ceil_v4i32(<4 x i32> %x) {
   ret <4 x i32> %sel
 }
 
+define i32 @pr91691(i32 %0) {
+; CHECK-LABEL: @pr91691(
+; CHECK-NEXT:[[TMP2:%.*]] = sub i32 -2, [[TMP0:%.*]]
+; CHECK-NEXT:[[TMP3:%.*]] = tail call range(i32 0, 33) i32 
@llvm.ctlz.i32(i32 [[TMP2]], i1 false)
+; CHECK-NEXT:[[TMP4:%.*]] = sub nsw i32 0, [[TMP3]]
+; CHECK-NEXT:[[TMP5:%.*]] = and i32 [[TMP4]], 31
+; CHECK-NEXT:[[TMP6:%.*]] = shl nuw i32 1, [[TMP5]]
+; CHECK-NEXT:ret i32 [[TMP6]]
+;
+  %2 = sub nuw i32 -2, %0
+  %3 = tail call i32 @llvm.ctlz.i32(i32 %2, i1 false)
+  %4 = sub i32 32, %3
+  %5 = shl i32 1, %4
+  %6 = icmp ult i32 %0, -2
+  %7 = select i1 %6, i32 %5, i32 1
+  ret i32 %7
+}
+
+define i32 @pr91691_keep_nsw(i32 %0) {
+; CHECK-LABEL: @pr91691_keep_nsw(
+; CHECK-NEXT:[[TMP2:%.*]] = sub nsw i32 -2, [[TMP0:%.*]]
+; CHECK-NEXT:[[TMP3:%.*]] = tail call range(i32 0, 33) i32 
@llvm.ctlz.i32(i32 [[TMP2]], i1 false)
+; CHECK-NEXT:[[TMP4:%.*]] = sub nsw i32 0, [[TMP3]]
+; CHECK-NEXT:[[TMP5:%.*]] = and i32 [[TMP4]], 31
+; CHECK-NEXT:[[TMP6:%.*]] = shl nuw i32 1, [[TMP5]]
+; CHECK-NEXT:ret i32 [[TMP6]]
+;
+  %2 = sub nsw i32 -2, %0
+  %3 = tail call i32 @llvm.ctlz.i32(i32 %2, i1 false)
+  %4 = sub i32 32, %3
+  %5 = shl i32 1, %4
+  %6 = icmp ult i32 %0, -2
+  %7 = select i1 %6, i32 %5, i32 1
+  ret i32 %7
+}
+

dtcxzyw wrote:

@tstellar @nikic Do you guys have write access to this PR to directly commit 
these changes?


https://github.com/llvm/llvm-project/pull/91917
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/18.x: [InstCombine] Drop nuw flag when CtlzOp is a sub nuw (#91776) (PR #91917)

2024-05-13 Thread Nikita Popov via llvm-branch-commits


@@ -284,6 +284,42 @@ define <4 x i32> @bit_ceil_v4i32(<4 x i32> %x) {
   ret <4 x i32> %sel
 }
 
+define i32 @pr91691(i32 %0) {
+; CHECK-LABEL: @pr91691(
+; CHECK-NEXT:[[TMP2:%.*]] = sub i32 -2, [[TMP0:%.*]]
+; CHECK-NEXT:[[TMP3:%.*]] = tail call range(i32 0, 33) i32 
@llvm.ctlz.i32(i32 [[TMP2]], i1 false)
+; CHECK-NEXT:[[TMP4:%.*]] = sub nsw i32 0, [[TMP3]]
+; CHECK-NEXT:[[TMP5:%.*]] = and i32 [[TMP4]], 31
+; CHECK-NEXT:[[TMP6:%.*]] = shl nuw i32 1, [[TMP5]]
+; CHECK-NEXT:ret i32 [[TMP6]]
+;
+  %2 = sub nuw i32 -2, %0
+  %3 = tail call i32 @llvm.ctlz.i32(i32 %2, i1 false)
+  %4 = sub i32 32, %3
+  %5 = shl i32 1, %4
+  %6 = icmp ult i32 %0, -2
+  %7 = select i1 %6, i32 %5, i32 1
+  ret i32 %7
+}
+
+define i32 @pr91691_keep_nsw(i32 %0) {
+; CHECK-LABEL: @pr91691_keep_nsw(
+; CHECK-NEXT:[[TMP2:%.*]] = sub nsw i32 -2, [[TMP0:%.*]]
+; CHECK-NEXT:[[TMP3:%.*]] = tail call range(i32 0, 33) i32 
@llvm.ctlz.i32(i32 [[TMP2]], i1 false)
+; CHECK-NEXT:[[TMP4:%.*]] = sub nsw i32 0, [[TMP3]]
+; CHECK-NEXT:[[TMP5:%.*]] = and i32 [[TMP4]], 31
+; CHECK-NEXT:[[TMP6:%.*]] = shl nuw i32 1, [[TMP5]]
+; CHECK-NEXT:ret i32 [[TMP6]]
+;
+  %2 = sub nsw i32 -2, %0
+  %3 = tail call i32 @llvm.ctlz.i32(i32 %2, i1 false)
+  %4 = sub i32 32, %3
+  %5 = shl i32 1, %4
+  %6 = icmp ult i32 %0, -2
+  %7 = select i1 %6, i32 %5, i32 1
+  ret i32 %7
+}
+

nikic wrote:

I don't. I just checked, and the PRs are created with 
maintainer_can_modify=True in 
https://github.com/llvm/llvm-project/blob/e6b2197a89f5d6d0f56a03c03b8afda561eee899/llvm/utils/git/github-automation.py#L590
 I have no idea why this doesn't work...

https://github.com/llvm/llvm-project/pull/91917
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libclc] release/18.x: [libclc] Fix linking against libIRReader (PR #91553)

2024-05-13 Thread Nikita Popov via llvm-branch-commits

https://github.com/nikic milestoned 
https://github.com/llvm/llvm-project/pull/91553
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] release/18.x: change the visibility of libc++ header to public in libcxx module (PR #91182)

2024-05-13 Thread Nikita Popov via llvm-branch-commits

https://github.com/nikic milestoned 
https://github.com/llvm/llvm-project/pull/91182
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


  1   2   >