[llvm-branch-commits] [llvm] [LoongArch][DAGCombiner] Combine vxor (vand ..) to vandn (PR #161037)

2025-09-29 Thread Zhaoxin Yang via llvm-branch-commits


@@ -4939,6 +4939,86 @@ void LoongArchTargetLowering::ReplaceNodeResults(
   }
 }
 
+// Helper to attempt to return a cheaper, bit-inverted version of \p V.
+static SDValue isNOT(SDValue V, SelectionDAG &DAG) {
+  // TODO: don't always ignore oneuse constraints.
+  V = peekThroughBitcasts(V);
+  EVT VT = V.getValueType();
+
+  // Match not(xor X, -1) -> X.
+  if (V.getOpcode() == ISD::XOR &&
+  (ISD::isBuildVectorAllOnes(V.getOperand(1).getNode()) ||
+   isAllOnesConstant(V.getOperand(1
+return V.getOperand(0);
+
+  // Match not(extract_subvector(not(X)) -> extract_subvector(X).
+  if (V.getOpcode() == ISD::EXTRACT_SUBVECTOR &&
+  (isNullConstant(V.getOperand(1)) || V.getOperand(0).hasOneUse())) {
+if (SDValue Not = isNOT(V.getOperand(0), DAG)) {
+  Not = DAG.getBitcast(V.getOperand(0).getValueType(), Not);
+  return DAG.getNode(ISD::EXTRACT_SUBVECTOR, SDLoc(Not), VT, Not,
+ V.getOperand(1));
+}
+  }
+
+  // Match not(SplatVector(not(X)) -> SplatVector(X).
+  if (V.getOpcode() == ISD::BUILD_VECTOR) {
+if (SDValue SplatValue =
+cast(V.getNode())->getSplatValue()) {
+  if (!V->isOnlyUserOf(SplatValue.getNode()))
+return SDValue();
+
+  if (SDValue Not = isNOT(SplatValue, DAG)) {
+Not = DAG.getBitcast(V.getOperand(0).getValueType(), Not);
+return DAG.getSplat(VT, SDLoc(Not), Not);
+  }
+}
+  }
+
+  // Match not(or(not(X),not(Y))) -> and(X, Y).
+  if (V.getOpcode() == ISD::OR && DAG.getTargetLoweringInfo().isTypeLegal(VT) 
&&
+  V.getOperand(0).hasOneUse() && V.getOperand(1).hasOneUse()) {

ylzsx wrote:

Thanks, I will try to write a few tests to cover these cases. I previously 
tried to get some inspiration in llvm-test-suit, but I failed.

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


[llvm-branch-commits] [llvm] [llvm][mustache] Avoid extra allocations in parseSection (PR #159199)

2025-09-29 Thread Paul Kirth via llvm-branch-commits

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

>From 057142b5db72fcd1147607898a0e7751e75b6492 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Tue, 16 Sep 2025 09:40:04 -0700
Subject: [PATCH] [llvm][mustache] Avoid extra allocations in parseSection

We don't need to have extra allocations when concatenating raw bodies.
---
 llvm/lib/Support/Mustache.cpp | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Support/Mustache.cpp b/llvm/lib/Support/Mustache.cpp
index 8eebeaec11925..5bd3c8d7d0d6b 100644
--- a/llvm/lib/Support/Mustache.cpp
+++ b/llvm/lib/Support/Mustache.cpp
@@ -602,9 +602,16 @@ void Parser::parseSection(ASTNode *Parent, ASTNode::Type 
Ty,
   size_t Start = CurrentPtr;
   parseMustache(CurrentNode);
   const size_t End = CurrentPtr - 1;
+
+  size_t RawBodySize = 0;
+  for (size_t I = Start; I < End; ++I)
+RawBodySize += Tokens[I].RawBody.size();
+
   SmallString<128> RawBody;
-  for (std::size_t I = Start; I < End; I++)
+  RawBody.reserve(RawBodySize);
+  for (std::size_t I = Start; I < End; ++I)
 RawBody += Tokens[I].RawBody;
+
   CurrentNode->setRawBody(Ctx.Saver.save(StringRef(RawBody)));
   Parent->addChild(CurrentNode);
 }

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


[llvm-branch-commits] [llvm] [llvm][mustache] Use single pass when tokenizing (PR #159196)

2025-09-29 Thread Paul Kirth via llvm-branch-commits

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

>From cbc1f386bf88525a06976e8284889f720052c7ad Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Mon, 15 Sep 2025 23:27:50 -0700
Subject: [PATCH] [llvm][mustache] Use single pass when tokenizing

The old implementation used many string searches over the same portions
of the strings. This version sacrifices some API niceness for perf wins.

  Metric | Baseline | Single-Pass | Change
  -- |  | --- | ---
  Time (ms)  | 36.09| 35.78   | -0.86%
  Cycles | 35.3M| 35.0M   | -0.79%
  Instructions   | 86.7M| 85.8M   | -1.03%
  Branch Misses  | 116K | 114K| -1.91%
  Cache Misses   | 244K | 232K| -4.98%
---
 llvm/lib/Support/Mustache.cpp | 186 +-
 1 file changed, 73 insertions(+), 113 deletions(-)

diff --git a/llvm/lib/Support/Mustache.cpp b/llvm/lib/Support/Mustache.cpp
index 30ced31bd7c43..0053a425b758d 100644
--- a/llvm/lib/Support/Mustache.cpp
+++ b/llvm/lib/Support/Mustache.cpp
@@ -368,141 +368,101 @@ static const char *jsonKindToString(json::Value::Kind 
K) {
   llvm_unreachable("Unknown json::Value::Kind");
 }
 
-static Tag findNextTag(StringRef Template, size_t StartPos, StringRef Open,
-   StringRef Close) {
-  const StringLiteral TripleOpen("{{{");
-  const StringLiteral TripleClose("}}}");
-
-  size_t NormalOpenPos = Template.find(Open, StartPos);
-  size_t TripleOpenPos = Template.find(TripleOpen, StartPos);
-
-  Tag Result;
-
-  // Determine which tag comes first.
-  if (TripleOpenPos != StringRef::npos &&
-  (NormalOpenPos == StringRef::npos || TripleOpenPos <= NormalOpenPos)) {
-// Found a triple mustache tag.
-size_t EndPos =
-Template.find(TripleClose, TripleOpenPos + TripleOpen.size());
-if (EndPos == StringRef::npos)
-  return Result; // No closing tag found.
-
-Result.TagKind = Tag::Kind::Triple;
-Result.StartPosition = TripleOpenPos;
-size_t ContentStart = TripleOpenPos + TripleOpen.size();
-Result.Content = Template.substr(ContentStart, EndPos - ContentStart);
-Result.FullMatch = Template.substr(
-TripleOpenPos, (EndPos + TripleClose.size()) - TripleOpenPos);
-  } else if (NormalOpenPos != StringRef::npos) {
-// Found a normal mustache tag.
-size_t EndPos = Template.find(Close, NormalOpenPos + Open.size());
-if (EndPos == StringRef::npos)
-  return Result; // No closing tag found.
-
-Result.TagKind = Tag::Kind::Normal;
-Result.StartPosition = NormalOpenPos;
-size_t ContentStart = NormalOpenPos + Open.size();
-Result.Content = Template.substr(ContentStart, EndPos - ContentStart);
-Result.FullMatch =
-Template.substr(NormalOpenPos, (EndPos + Close.size()) - 
NormalOpenPos);
-  }
-
-  return Result;
-}
-
-static std::optional>
-processTag(const Tag &T, SmallVectorImpl &Tokens, MustacheContext &Ctx) 
{
-  LLVM_DEBUG(dbgs() << "[Tag] " << T.FullMatch << ", Content: " << T.Content
-<< ", Kind: " << tagKindToString(T.TagKind) << "\n");
-  if (T.TagKind == Tag::Kind::Triple) {
-Tokens.emplace_back(T.FullMatch, Ctx.Saver.save("&" + T.Content), '&', 
Ctx);
-return std::nullopt;
-  }
-  StringRef Interpolated = T.Content;
-  if (!Interpolated.trim().starts_with("=")) {
-char Front = Interpolated.empty() ? ' ' : Interpolated.trim().front();
-Tokens.emplace_back(T.FullMatch, Interpolated, Front, Ctx);
-return std::nullopt;
-  }
-  Tokens.emplace_back(T.FullMatch, Interpolated, '=', Ctx);
-  StringRef DelimSpec = Interpolated.trim();
-  DelimSpec = DelimSpec.drop_front(1);
-  DelimSpec = DelimSpec.take_until([](char C) { return C == '='; });
-  DelimSpec = DelimSpec.trim();
-
-  std::pair Ret = DelimSpec.split(' ');
-  LLVM_DEBUG(dbgs() << "[Set Delimiter] NewOpen: " << Ret.first
-<< ", NewClose: " << Ret.second << "\n");
-  return Ret;
-}
-
 // Simple tokenizer that splits the template into tokens.
-// The mustache spec allows {{{ }}} to unescape variables,
-// but we don't support that here. An unescape variable
-// is represented only by {{& variable}}.
 static SmallVector tokenize(StringRef Template, MustacheContext &Ctx) {
   LLVM_DEBUG(dbgs() << "[Tokenize Template] \"" << Template << "\"\n");
   SmallVector Tokens;
   SmallString<8> Open("{{");
   SmallString<8> Close("}}");
-  size_t Start = 0;
+  size_t Cursor = 0;
+  size_t TextStart = 0;
+
+  const StringLiteral TripleOpen("{{{");
+  const StringLiteral TripleClose("}}}");
 
-  while (Start < Template.size()) {
-LLVM_DEBUG(dbgs() << "[Tokenize Loop] Start=" << Start << ", Open='" << 
Open
-  << "', Close='" << Close << "'\n");
-Tag T = findNextTag(Template, Start, Open, Close);
+  while (Cursor < Template.size()) {
+StringRef TemplateSuffix = Template.substr(Cursor);
+StringRef TagOpen, TagClose;
+Tag::Kind Kind;
+
+ 

[llvm-branch-commits] [llvm] [llvm][mustache] Simplify debug logging (PR #159193)

2025-09-29 Thread Paul Kirth via llvm-branch-commits

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

>From 79eaa0a04f0b7925145d4032a4629901f23d6bfe Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Sat, 13 Sep 2025 23:21:07 -0700
Subject: [PATCH] [llvm][mustache] Simplify debug logging

---
 llvm/lib/Support/Mustache.cpp | 76 ---
 1 file changed, 43 insertions(+), 33 deletions(-)

diff --git a/llvm/lib/Support/Mustache.cpp b/llvm/lib/Support/Mustache.cpp
index 6275e5eccf03a..ba22cb75cbf5d 100644
--- a/llvm/lib/Support/Mustache.cpp
+++ b/llvm/lib/Support/Mustache.cpp
@@ -329,6 +329,36 @@ struct Tag {
   size_t StartPosition = StringRef::npos;
 };
 
+static const char *tagKindToString(Tag::Kind K) {
+  switch (K) {
+  case Tag::Kind::None:
+return "None";
+  case Tag::Kind::Normal:
+return "Normal";
+  case Tag::Kind::Triple:
+return "Triple";
+  }
+  llvm_unreachable("Unknown Tag::Kind");
+}
+
+static const char *jsonKindToString(json::Value::Kind K) {
+  switch (K) {
+  case json::Value::Kind::Null:
+return "JSON_KIND_NULL";
+  case json::Value::Kind::Boolean:
+return "JSON_KIND_BOOLEAN";
+  case json::Value::Kind::Number:
+return "JSON_KIND_NUMBER";
+  case json::Value::Kind::String:
+return "JSON_KIND_STRING";
+  case json::Value::Kind::Array:
+return "JSON_KIND_ARRAY";
+  case json::Value::Kind::Object:
+return "JSON_KIND_OBJECT";
+  }
+  llvm_unreachable("Unknown json::Value::Kind");
+}
+
 static Tag findNextTag(StringRef Template, size_t StartPos, StringRef Open,
StringRef Close) {
   const StringLiteral TripleOpen("{{{");
@@ -373,11 +403,10 @@ static Tag findNextTag(StringRef Template, size_t 
StartPos, StringRef Open,
 
 static std::optional>
 processTag(const Tag &T, SmallVectorImpl &Tokens) {
-  LLVM_DEBUG(dbgs() << "  Found tag: \"" << T.FullMatch << "\", Content: \""
-<< T.Content << "\"\n");
+  LLVM_DEBUG(dbgs() << "[Tag] " << T.FullMatch << ", Content: " << T.Content
+<< ", Kind: " << tagKindToString(T.TagKind) << "\n");
   if (T.TagKind == Tag::Kind::Triple) {
 Tokens.emplace_back(T.FullMatch.str(), "&" + T.Content.str(), '&');
-LLVM_DEBUG(dbgs() << "  Created UnescapeVariable token.\n");
 return std::nullopt;
   }
   StringRef Interpolated = T.Content;
@@ -385,7 +414,6 @@ processTag(const Tag &T, SmallVectorImpl &Tokens) {
   if (!Interpolated.trim().starts_with("=")) {
 char Front = Interpolated.empty() ? ' ' : Interpolated.trim().front();
 Tokens.emplace_back(RawBody, Interpolated.str(), Front);
-LLVM_DEBUG(dbgs() << "  Created tag token of type '" << Front << "'\n");
 return std::nullopt;
   }
   Tokens.emplace_back(RawBody, Interpolated.str(), '=');
@@ -395,8 +423,8 @@ processTag(const Tag &T, SmallVectorImpl &Tokens) {
   DelimSpec = DelimSpec.trim();
 
   std::pair Ret = DelimSpec.split(' ');
-  LLVM_DEBUG(dbgs() << "  Found Set Delimiter tag. NewOpen='" << Ret.first
-<< "', NewClose='" << Ret.second << "'\n");
+  LLVM_DEBUG(dbgs() << "[Set Delimiter] NewOpen: " << Ret.first
+<< ", NewClose: " << Ret.second << "\n");
   return Ret;
 }
 
@@ -405,14 +433,14 @@ processTag(const Tag &T, SmallVectorImpl &Tokens) {
 // but we don't support that here. An unescape variable
 // is represented only by {{& variable}}.
 static SmallVector tokenize(StringRef Template) {
-  LLVM_DEBUG(dbgs() << "Tokenizing template: \"" << Template << "\"\n");
+  LLVM_DEBUG(dbgs() << "[Tokenize Template] \"" << Template << "\"\n");
   SmallVector Tokens;
   SmallString<8> Open("{{");
   SmallString<8> Close("}}");
   size_t Start = 0;
 
   while (Start < Template.size()) {
-LLVM_DEBUG(dbgs() << "Loop start. Start=" << Start << ", Open='" << Open
+LLVM_DEBUG(dbgs() << "[Tokenize Loop] Start=" << Start << ", Open='" << 
Open
   << "', Close='" << Close << "'\n");
 Tag T = findNextTag(Template, Start, Open, Close);
 
@@ -428,7 +456,6 @@ static SmallVector tokenize(StringRef Template) {
 if (T.StartPosition > Start) {
   StringRef Text = Template.substr(Start, T.StartPosition - Start);
   Tokens.emplace_back(Text.str());
-  LLVM_DEBUG(dbgs() << "  Created Text token: \"" << Text << "\"\n");
 }
 
 if (auto NewDelims = processTag(T, Tokens)) {
@@ -479,7 +506,6 @@ static SmallVector tokenize(StringRef Template) {
 if ((!HasTextBehind && !HasTextAhead) || (!HasTextBehind && Idx == 
LastIdx))
   stripTokenBefore(Tokens, Idx, CurrentToken, CurrentType);
   }
-  LLVM_DEBUG(dbgs() << "Tokenizing finished.\n");
   return Tokens;
 }
 
@@ -545,7 +571,7 @@ class AddIndentationStringStream : public 
MustacheOutputStream {
 Indent.resize(Indentation, ' ');
 
 for (char C : Data) {
-  LLVM_DEBUG(dbgs() << "IndentationStream: NeedsIndent=" << NeedsIndent
+  LLVM_DEBUG(dbgs() << "[IndentationStream] NeedsIndent=" << NeedsIndent
 << ", C='" << C << "', I

[llvm-branch-commits] [llvm] [llvm][mustache] Use single pass when tokenizing (PR #159196)

2025-09-29 Thread Paul Kirth via llvm-branch-commits

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

>From 3e3e4ea5d3e855addcc661db7bc7999b301324e6 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Mon, 15 Sep 2025 23:27:50 -0700
Subject: [PATCH] [llvm][mustache] Use single pass when tokenizing

The old implementation used many string searches over the same portions
of the strings. This version sacrifices some API niceness for perf wins.

  Metric | Baseline | Single-Pass | Change
  -- |  | --- | ---
  Time (ms)  | 36.09| 35.78   | -0.86%
  Cycles | 35.3M| 35.0M   | -0.79%
  Instructions   | 86.7M| 85.8M   | -1.03%
  Branch Misses  | 116K | 114K| -1.91%
  Cache Misses   | 244K | 232K| -4.98%
---
 llvm/lib/Support/Mustache.cpp | 186 +-
 1 file changed, 73 insertions(+), 113 deletions(-)

diff --git a/llvm/lib/Support/Mustache.cpp b/llvm/lib/Support/Mustache.cpp
index 30ced31bd7c43..0053a425b758d 100644
--- a/llvm/lib/Support/Mustache.cpp
+++ b/llvm/lib/Support/Mustache.cpp
@@ -368,141 +368,101 @@ static const char *jsonKindToString(json::Value::Kind 
K) {
   llvm_unreachable("Unknown json::Value::Kind");
 }
 
-static Tag findNextTag(StringRef Template, size_t StartPos, StringRef Open,
-   StringRef Close) {
-  const StringLiteral TripleOpen("{{{");
-  const StringLiteral TripleClose("}}}");
-
-  size_t NormalOpenPos = Template.find(Open, StartPos);
-  size_t TripleOpenPos = Template.find(TripleOpen, StartPos);
-
-  Tag Result;
-
-  // Determine which tag comes first.
-  if (TripleOpenPos != StringRef::npos &&
-  (NormalOpenPos == StringRef::npos || TripleOpenPos <= NormalOpenPos)) {
-// Found a triple mustache tag.
-size_t EndPos =
-Template.find(TripleClose, TripleOpenPos + TripleOpen.size());
-if (EndPos == StringRef::npos)
-  return Result; // No closing tag found.
-
-Result.TagKind = Tag::Kind::Triple;
-Result.StartPosition = TripleOpenPos;
-size_t ContentStart = TripleOpenPos + TripleOpen.size();
-Result.Content = Template.substr(ContentStart, EndPos - ContentStart);
-Result.FullMatch = Template.substr(
-TripleOpenPos, (EndPos + TripleClose.size()) - TripleOpenPos);
-  } else if (NormalOpenPos != StringRef::npos) {
-// Found a normal mustache tag.
-size_t EndPos = Template.find(Close, NormalOpenPos + Open.size());
-if (EndPos == StringRef::npos)
-  return Result; // No closing tag found.
-
-Result.TagKind = Tag::Kind::Normal;
-Result.StartPosition = NormalOpenPos;
-size_t ContentStart = NormalOpenPos + Open.size();
-Result.Content = Template.substr(ContentStart, EndPos - ContentStart);
-Result.FullMatch =
-Template.substr(NormalOpenPos, (EndPos + Close.size()) - 
NormalOpenPos);
-  }
-
-  return Result;
-}
-
-static std::optional>
-processTag(const Tag &T, SmallVectorImpl &Tokens, MustacheContext &Ctx) 
{
-  LLVM_DEBUG(dbgs() << "[Tag] " << T.FullMatch << ", Content: " << T.Content
-<< ", Kind: " << tagKindToString(T.TagKind) << "\n");
-  if (T.TagKind == Tag::Kind::Triple) {
-Tokens.emplace_back(T.FullMatch, Ctx.Saver.save("&" + T.Content), '&', 
Ctx);
-return std::nullopt;
-  }
-  StringRef Interpolated = T.Content;
-  if (!Interpolated.trim().starts_with("=")) {
-char Front = Interpolated.empty() ? ' ' : Interpolated.trim().front();
-Tokens.emplace_back(T.FullMatch, Interpolated, Front, Ctx);
-return std::nullopt;
-  }
-  Tokens.emplace_back(T.FullMatch, Interpolated, '=', Ctx);
-  StringRef DelimSpec = Interpolated.trim();
-  DelimSpec = DelimSpec.drop_front(1);
-  DelimSpec = DelimSpec.take_until([](char C) { return C == '='; });
-  DelimSpec = DelimSpec.trim();
-
-  std::pair Ret = DelimSpec.split(' ');
-  LLVM_DEBUG(dbgs() << "[Set Delimiter] NewOpen: " << Ret.first
-<< ", NewClose: " << Ret.second << "\n");
-  return Ret;
-}
-
 // Simple tokenizer that splits the template into tokens.
-// The mustache spec allows {{{ }}} to unescape variables,
-// but we don't support that here. An unescape variable
-// is represented only by {{& variable}}.
 static SmallVector tokenize(StringRef Template, MustacheContext &Ctx) {
   LLVM_DEBUG(dbgs() << "[Tokenize Template] \"" << Template << "\"\n");
   SmallVector Tokens;
   SmallString<8> Open("{{");
   SmallString<8> Close("}}");
-  size_t Start = 0;
+  size_t Cursor = 0;
+  size_t TextStart = 0;
+
+  const StringLiteral TripleOpen("{{{");
+  const StringLiteral TripleClose("}}}");
 
-  while (Start < Template.size()) {
-LLVM_DEBUG(dbgs() << "[Tokenize Loop] Start=" << Start << ", Open='" << 
Open
-  << "', Close='" << Close << "'\n");
-Tag T = findNextTag(Template, Start, Open, Close);
+  while (Cursor < Template.size()) {
+StringRef TemplateSuffix = Template.substr(Cursor);
+StringRef TagOpen, TagClose;
+Tag::Kind Kind;
+
+ 

[llvm-branch-commits] [llvm] [llvm][mustache] Avoid extra allocations in parseSection (PR #159199)

2025-09-29 Thread Paul Kirth via llvm-branch-commits

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

>From 92378defe8a7a4e84589c80c663703055a025580 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Tue, 16 Sep 2025 09:40:04 -0700
Subject: [PATCH] [llvm][mustache] Avoid extra allocations in parseSection

We don't need to have extra allocations when concatenating raw bodies.
---
 llvm/lib/Support/Mustache.cpp | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Support/Mustache.cpp b/llvm/lib/Support/Mustache.cpp
index 8eebeaec11925..5bd3c8d7d0d6b 100644
--- a/llvm/lib/Support/Mustache.cpp
+++ b/llvm/lib/Support/Mustache.cpp
@@ -602,9 +602,16 @@ void Parser::parseSection(ASTNode *Parent, ASTNode::Type 
Ty,
   size_t Start = CurrentPtr;
   parseMustache(CurrentNode);
   const size_t End = CurrentPtr - 1;
+
+  size_t RawBodySize = 0;
+  for (size_t I = Start; I < End; ++I)
+RawBodySize += Tokens[I].RawBody.size();
+
   SmallString<128> RawBody;
-  for (std::size_t I = Start; I < End; I++)
+  RawBody.reserve(RawBodySize);
+  for (std::size_t I = Start; I < End; ++I)
 RawBody += Tokens[I].RawBody;
+
   CurrentNode->setRawBody(Ctx.Saver.save(StringRef(RawBody)));
   Parent->addChild(CurrentNode);
 }

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


[llvm-branch-commits] [llvm] [llvm][mustache] Avoid extra copy for json strings (PR #159195)

2025-09-29 Thread Paul Kirth via llvm-branch-commits

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

>From b9da248b3cb169ec2187b94ed489b9de4554 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Mon, 15 Sep 2025 19:54:34 -0700
Subject: [PATCH] [llvm][mustache] Avoid extra copy for json strings

---
 llvm/lib/Support/Mustache.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/llvm/lib/Support/Mustache.cpp b/llvm/lib/Support/Mustache.cpp
index eadf4c1f7cda9..30ced31bd7c43 100644
--- a/llvm/lib/Support/Mustache.cpp
+++ b/llvm/lib/Support/Mustache.cpp
@@ -698,8 +698,7 @@ static void toMustacheString(const json::Value &Data, 
raw_ostream &OS) {
 return;
   }
   case json::Value::String: {
-auto Str = *Data.getAsString();
-OS << Str.str();
+OS << *Data.getAsString();
 return;
   }
 

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


[llvm-branch-commits] [llvm] [llvm][mustache] Avoid extra allocations in parseSection (PR #159199)

2025-09-29 Thread Paul Kirth via llvm-branch-commits

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

>From baee14750289435743b141a067c716b65a859666 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Tue, 16 Sep 2025 09:40:04 -0700
Subject: [PATCH] [llvm][mustache] Avoid extra allocations in parseSection

We don't need to have extra allocations when concatenating raw bodies.
---
 llvm/lib/Support/Mustache.cpp | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Support/Mustache.cpp b/llvm/lib/Support/Mustache.cpp
index 8eebeaec11925..5bd3c8d7d0d6b 100644
--- a/llvm/lib/Support/Mustache.cpp
+++ b/llvm/lib/Support/Mustache.cpp
@@ -602,9 +602,16 @@ void Parser::parseSection(ASTNode *Parent, ASTNode::Type 
Ty,
   size_t Start = CurrentPtr;
   parseMustache(CurrentNode);
   const size_t End = CurrentPtr - 1;
+
+  size_t RawBodySize = 0;
+  for (size_t I = Start; I < End; ++I)
+RawBodySize += Tokens[I].RawBody.size();
+
   SmallString<128> RawBody;
-  for (std::size_t I = Start; I < End; I++)
+  RawBody.reserve(RawBodySize);
+  for (std::size_t I = Start; I < End; ++I)
 RawBody += Tokens[I].RawBody;
+
   CurrentNode->setRawBody(Ctx.Saver.save(StringRef(RawBody)));
   Parent->addChild(CurrentNode);
 }

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


[llvm-branch-commits] [llvm] [llvm][mustache] Avoid redundant saves in accessor splitting (PR #159197)

2025-09-29 Thread Paul Kirth via llvm-branch-commits

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

>From 1e2990f79e4d866bcc6fc3c0113db86db8a4ba2c Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Tue, 16 Sep 2025 00:11:47 -0700
Subject: [PATCH] [llvm][mustache] Avoid redundant saves in accessor splitting

The splitMustacheString function was saving StringRefs that
were already backed by an arena-allocated string. This was
unnecessary work. This change removes the redundant
Ctx.Saver.save() call.

This optimization provides a small but measurable performance
improvement on top of the single-pass tokenizer, most notably
reducing branch misses.

  Metric | Baseline | Optimized | Change
  -- |  | - | ---
  Time (ms)  | 35.77| 35.57 | -0.56%
  Cycles | 35.16M   | 34.91M| -0.71%
  Instructions   | 85.77M   | 85.54M| -0.27%
  Branch Misses  | 113.9K   | 111.9K| -1.76%
  Cache Misses   | 237.7K   | 242.1K| +1.85%
---
 llvm/lib/Support/Mustache.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Support/Mustache.cpp b/llvm/lib/Support/Mustache.cpp
index 0053a425b758d..4786242cdfba9 100644
--- a/llvm/lib/Support/Mustache.cpp
+++ b/llvm/lib/Support/Mustache.cpp
@@ -51,7 +51,7 @@ static Accessor splitMustacheString(StringRef Str, 
MustacheContext &Ctx) {
   std::tie(Part, Str) = Str.split('.');
   // Each part of the accessor needs to be saved to the arena
   // to ensure it has a stable address.
-  Tokens.push_back(Ctx.Saver.save(Part.trim()));
+  Tokens.push_back(Part.trim());
 }
   }
   // Now, allocate memory for the array of StringRefs in the arena.

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


[llvm-branch-commits] [llvm] [llvm][mustache] Simplify debug logging (PR #159193)

2025-09-29 Thread Petr Hosek via llvm-branch-commits


@@ -545,7 +571,7 @@ class AddIndentationStringStream : public 
MustacheOutputStream {
 Indent.resize(Indentation, ' ');
 
 for (char C : Data) {
-  LLVM_DEBUG(dbgs() << "IndentationStream: NeedsIndent=" << NeedsIndent
+  LLVM_DEBUG(dbgs() << "[IndentationStream] NeedsIndent=" << NeedsIndent

petrhosek wrote:

It's not clear to me where we use `FooBar` and when we use `Foo Bar` since 
there doesn't seem to be much consistency but it doesn't matter too much.

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


[llvm-branch-commits] [clang] [Clang] Introduce -fsanitize=alloc-token (PR #156839)

2025-09-29 Thread Marco Elver via llvm-branch-commits

https://github.com/melver updated 
https://github.com/llvm/llvm-project/pull/156839

>From b3653330c2c39ebaa094670f11afb0f9d36b9de2 Mon Sep 17 00:00:00 2001
From: Marco Elver 
Date: Thu, 4 Sep 2025 12:07:26 +0200
Subject: [PATCH] fixup! Insert AllocToken into index.rst

Created using spr 1.3.8-beta.1
---
 clang/docs/index.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/docs/index.rst b/clang/docs/index.rst
index be654af57f890..aa2b3a73dc11b 100644
--- a/clang/docs/index.rst
+++ b/clang/docs/index.rst
@@ -40,6 +40,7 @@ Using Clang as a Compiler
SanitizerCoverage
SanitizerStats
SanitizerSpecialCaseList
+   AllocToken
BoundsSafety
BoundsSafetyAdoptionGuide
BoundsSafetyImplPlans

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


[llvm-branch-commits] [llvm] [LoongArch] Make rotl/rotr custom for lsx/lasx (PR #161154)

2025-09-29 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-loongarch

Author: Zhaoxin Yang (ylzsx)


Changes



---

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


6 Files Affected:

- (modified) llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp (+60) 
- (modified) llvm/lib/Target/LoongArch/LoongArchISelLowering.h (+1) 
- (modified) llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td (+5) 
- (modified) llvm/lib/Target/LoongArch/LoongArchLSXInstrInfo.td (+5) 
- (modified) llvm/test/CodeGen/LoongArch/lasx/rotl-rotr.ll (+36-71) 
- (modified) llvm/test/CodeGen/LoongArch/lsx/rotl-rotr.ll (+34-71) 


``diff
diff --git a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp 
b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
index 94f53d5b85f10..073b2ddcd049e 100644
--- a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
@@ -346,6 +346,8 @@ LoongArchTargetLowering::LoongArchTargetLowering(const 
TargetMachine &TM,
   setOperationAction(ISD::SSUBSAT, VT, Legal);
   setOperationAction(ISD::UADDSAT, VT, Legal);
   setOperationAction(ISD::USUBSAT, VT, Legal);
+  setOperationAction(ISD::ROTL, VT, Custom);
+  setOperationAction(ISD::ROTR, VT, Custom);
 }
 for (MVT VT : {MVT::v16i8, MVT::v8i16, MVT::v4i32})
   setOperationAction(ISD::BITREVERSE, VT, Custom);
@@ -426,6 +428,8 @@ LoongArchTargetLowering::LoongArchTargetLowering(const 
TargetMachine &TM,
   setOperationAction(ISD::UADDSAT, VT, Legal);
   setOperationAction(ISD::USUBSAT, VT, Legal);
   setOperationAction(ISD::VECREDUCE_ADD, VT, Custom);
+  setOperationAction(ISD::ROTL, VT, Custom);
+  setOperationAction(ISD::ROTR, VT, Custom);
 }
 for (MVT VT : {MVT::v32i8, MVT::v16i16, MVT::v8i32})
   setOperationAction(ISD::BITREVERSE, VT, Custom);
@@ -580,6 +584,9 @@ SDValue LoongArchTargetLowering::LowerOperation(SDValue Op,
 return lowerBF16_TO_FP(Op, DAG);
   case ISD::VECREDUCE_ADD:
 return lowerVECREDUCE_ADD(Op, DAG);
+  case ISD::ROTL:
+  case ISD::ROTR:
+return lowerRotate(Op, DAG);
   case ISD::VECREDUCE_AND:
   case ISD::VECREDUCE_OR:
   case ISD::VECREDUCE_XOR:
@@ -753,6 +760,59 @@ SDValue LoongArchTargetLowering::lowerPREFETCH(SDValue Op,
   return Op;
 }
 
+SDValue LoongArchTargetLowering::lowerRotate(SDValue Op,
+ SelectionDAG &DAG) const {
+  MVT VT = Op.getSimpleValueType();
+  if (!VT.isVector())
+return Op;
+
+  SDLoc DL(Op);
+  SDValue R = Op.getOperand(0);
+  SDValue Amt = Op.getOperand(1);
+  unsigned Opcode = Op.getOpcode();
+  unsigned EltSizeInBits = VT.getScalarSizeInBits();
+
+  auto checkCstSplat = [](SDValue V, APInt &CstSplatValue) {
+if (V.getOpcode() != ISD::BUILD_VECTOR)
+  return false;
+if (SDValue SplatValue =
+cast(V.getNode())->getSplatValue()) {
+  if (auto *C = dyn_cast(SplatValue)) {
+CstSplatValue = C->getAPIntValue();
+return true;
+  }
+}
+return false;
+  };
+
+  // check for constant splat rotation amount.
+  APInt CstSplatValue;
+  bool IsCstSplat = checkCstSplat(Amt, CstSplatValue);
+  bool isROTL = Opcode == ISD::ROTL;
+
+  // Check for splat rotate by zero.
+  if (IsCstSplat && CstSplatValue.urem(EltSizeInBits) == 0)
+return R;
+
+  // LoongArch tagets always prefers ISD::ROTR.
+  if (isROTL) {
+SDValue Zero = DAG.getConstant(0, DL, VT);
+return DAG.getNode(ISD::ROTR, DL, VT, R,
+   DAG.getNode(ISD::SUB, DL, VT, Zero, Amt));
+  }
+
+  // Rotate by a immediate.
+  if (IsCstSplat) {
+// ISD::ROTR: Attemp to rotate by a positive immediate.
+SDValue Bits = DAG.getConstant(EltSizeInBits, DL, VT);
+if (SDValue Urem =
+DAG.FoldConstantArithmetic(ISD::UREM, DL, VT, {Amt, Bits}))
+  return DAG.getNode(Op.getOpcode(), DL, VT, R, Urem);
+  }
+
+  return Op;
+}
+
 // Return true if Val is equal to (setcc LHS, RHS, CC).
 // Return false if Val is the inverse of (setcc LHS, RHS, CC).
 // Otherwise, return std::nullopt.
diff --git a/llvm/lib/Target/LoongArch/LoongArchISelLowering.h 
b/llvm/lib/Target/LoongArch/LoongArchISelLowering.h
index 3c00296116ac2..d782498019914 100644
--- a/llvm/lib/Target/LoongArch/LoongArchISelLowering.h
+++ b/llvm/lib/Target/LoongArch/LoongArchISelLowering.h
@@ -411,6 +411,7 @@ class LoongArchTargetLowering : public TargetLowering {
   SDValue lowerVECREDUCE_ADD(SDValue Op, SelectionDAG &DAG) const;
   SDValue lowerVECREDUCE(SDValue Op, SelectionDAG &DAG) const;
   SDValue lowerConstantFP(SDValue Op, SelectionDAG &DAG) const;
+  SDValue lowerRotate(SDValue Op, SelectionDAG &DAG) const;
 
   bool isFPImmLegal(const APFloat &Imm, EVT VT,
 bool ForCodeSize) const override;
diff --git a/llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td 
b/llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td
index adfe990ba1234..bd6ab2a789b26 10

[llvm-branch-commits] [clang] [CIR] Upstream AddressSpace casting support (PR #161212)

2025-09-29 Thread David Rivera via llvm-branch-commits

RiverDave wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/161212?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#161212** https://app.graphite.dev/github/pr/llvm/llvm-project/161212?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/161212?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#161028** https://app.graphite.dev/github/pr/llvm/llvm-project/161028?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* `main`




This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn 
more about https://stacking.dev/?utm_source=stack-comment";>stacking.


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


[llvm-branch-commits] [clang] [CIR] Upstream AddressSpace casting support (PR #161212)

2025-09-29 Thread via llvm-branch-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff origin/main HEAD --extensions cpp,h -- 
clang/test/CIR/address-space-conversion.cpp 
clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h 
clang/include/clang/CIR/Dialect/IR/CIRTypes.h 
clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp clang/lib/CIR/CodeGen/CIRGenExpr.cpp 
clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp 
clang/lib/CIR/CodeGen/CIRGenFunction.h clang/lib/CIR/CodeGen/CIRGenModule.cpp 
clang/lib/CIR/CodeGen/CIRGenModule.h clang/lib/CIR/CodeGen/CIRGenTypes.cpp 
clang/lib/CIR/CodeGen/TargetInfo.cpp clang/lib/CIR/CodeGen/TargetInfo.h
``

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:





View the diff from clang-format here.


``diff
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.h 
b/clang/include/clang/CIR/Dialect/IR/CIRTypes.h
index 2f4191091..6a2b02ce4 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.h
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.h
@@ -19,8 +19,6 @@
 #include "clang/Basic/AddressSpaces.h"
 #include "clang/CIR/Dialect/IR/CIROpsEnums.h"
 #include "clang/CIR/Interfaces/CIRTypeInterfaces.h"
-#include "clang/CIR/Dialect/IR/CIROpsEnums.h"
-#include "clang/Basic/AddressSpaces.h"
 
 namespace cir {
 
diff --git a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
index 588f51be1..f65d502a1 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
@@ -1191,7 +1191,7 @@ LValue CIRGenFunction::emitCastLValue(const CastExpr *e) {
   case CK_ToUnion:
   case CK_BaseToDerived:
   case CK_AddressSpaceConversion: {
-LValue lv = emitLValue(e->getSubExpr());
+LValue lv = emitLValue(e->getSubExpr());
 QualType destTy = getContext().getPointerType(e->getType());
 cir::AddressSpace srcAS =
 cir::toCIRAddressSpace(e->getSubExpr()->getType().getAddressSpace());
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index ee9be0c9e..48ffaf977 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -1863,7 +1863,7 @@ mlir::Value ScalarExprEmitter::VisitCastExpr(CastExpr 
*ce) {
 return 
cgf.getBuilder().createBitcast(cgf.getLoc(subExpr->getSourceRange()),
   src, dstTy);
   }
-case CK_AddressSpaceConversion: {
+  case CK_AddressSpaceConversion: {
 Expr::EvalResult result;
 if (subExpr->EvaluateAsRValue(result, cgf.getContext()) &&
 result.Val.isNullPointer()) {
@@ -1872,7 +1872,8 @@ mlir::Value ScalarExprEmitter::VisitCastExpr(CastExpr 
*ce) {
   // eliminate the useless instructions emitted during translating E.
   if (result.HasSideEffects)
 Visit(subExpr);
-  return cgf.cgm.emitNullConstant(destTy, 
cgf.getLoc(subExpr->getExprLoc()));
+  return cgf.cgm.emitNullConstant(destTy,
+  cgf.getLoc(subExpr->getExprLoc()));
 }
 // Since target may map different address spaces in AST to the same address
 // space, an address space conversion may end up as a bitcast.
diff --git a/clang/lib/CIR/CodeGen/TargetInfo.h 
b/clang/lib/CIR/CodeGen/TargetInfo.h
index b07743890..0ba12ef7b 100644
--- a/clang/lib/CIR/CodeGen/TargetInfo.h
+++ b/clang/lib/CIR/CodeGen/TargetInfo.h
@@ -45,7 +45,7 @@ public:
   /// Returns ABI info helper for the target.
   const ABIInfo &getABIInfo() const { return *info; }
 
-/// Perform address space cast of an expression of pointer type.
+  /// Perform address space cast of an expression of pointer type.
   /// \param V is the value to be casted to another address space.
   /// \param SrcAddr is the CIR address space of \p V.
   /// \param DestAddr is the targeted CIR address space.

``




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


[llvm-branch-commits] [llvm] [LoongArch][DAGCombiner] Combine vxor (vand ..) to vandn (PR #161037)

2025-09-29 Thread via llvm-branch-commits


@@ -4939,6 +4939,86 @@ void LoongArchTargetLowering::ReplaceNodeResults(
   }
 }
 
+// Helper to attempt to return a cheaper, bit-inverted version of \p V.
+static SDValue isNOT(SDValue V, SelectionDAG &DAG) {
+  // TODO: don't always ignore oneuse constraints.
+  V = peekThroughBitcasts(V);
+  EVT VT = V.getValueType();
+
+  // Match not(xor X, -1) -> X.
+  if (V.getOpcode() == ISD::XOR &&
+  (ISD::isBuildVectorAllOnes(V.getOperand(1).getNode()) ||
+   isAllOnesConstant(V.getOperand(1
+return V.getOperand(0);
+
+  // Match not(extract_subvector(not(X)) -> extract_subvector(X).
+  if (V.getOpcode() == ISD::EXTRACT_SUBVECTOR &&
+  (isNullConstant(V.getOperand(1)) || V.getOperand(0).hasOneUse())) {
+if (SDValue Not = isNOT(V.getOperand(0), DAG)) {
+  Not = DAG.getBitcast(V.getOperand(0).getValueType(), Not);
+  return DAG.getNode(ISD::EXTRACT_SUBVECTOR, SDLoc(Not), VT, Not,
+ V.getOperand(1));
+}
+  }
+
+  // Match not(SplatVector(not(X)) -> SplatVector(X).
+  if (V.getOpcode() == ISD::BUILD_VECTOR) {
+if (SDValue SplatValue =
+cast(V.getNode())->getSplatValue()) {
+  if (!V->isOnlyUserOf(SplatValue.getNode()))
+return SDValue();
+
+  if (SDValue Not = isNOT(SplatValue, DAG)) {
+Not = DAG.getBitcast(V.getOperand(0).getValueType(), Not);
+return DAG.getSplat(VT, SDLoc(Not), Not);
+  }
+}
+  }
+
+  // Match not(or(not(X),not(Y))) -> and(X, Y).
+  if (V.getOpcode() == ISD::OR && DAG.getTargetLoweringInfo().isTypeLegal(VT) 
&&
+  V.getOperand(0).hasOneUse() && V.getOperand(1).hasOneUse()) {

heiher wrote:

and this one.

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


[llvm-branch-commits] [llvm] [LoongArch] Custom legalize vector_shuffle to `xvinsve0.{w/d}` when possible (PR #161156)

2025-09-29 Thread via llvm-branch-commits

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


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


[llvm-branch-commits] [clang] [Clang] Introduce -fsanitize=alloc-token (PR #156839)

2025-09-29 Thread Hans Wennborg via llvm-branch-commits


@@ -0,0 +1,45 @@
+// RUN: %clang_cc1-fsanitize=alloc-token -falloc-token-max=2147483647 
-triple x86_64-linux-gnu -x c -emit-llvm %s -o - | FileCheck %s

zmodem wrote:

I can sympathize with wanting to test the end-to-end behavior, but maybe that 
could be put in a separate test, and use only one or two allocator variants? 
The point is mainly to check that the pass pipeline is set up right both for 
-O0 and higher, right?

The current version of the patch, which combines -O0, -O, and 
-disable-llvm-passes with all the different allocators, and uses generated 
checks, makes it very hard to see what behavior it's actually testing for.

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


[llvm-branch-commits] [llvm] [AMDGPU][MC] Avoid creating lit64() operands unless asked or needed. (PR #161191)

2025-09-29 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-amdgpu

Author: Ivan Kosarev (kosarev)


Changes

There should normally be no need to generate implicit lit64()
modifiers on the assembler side. It's the encoder's responsibility
to recognise literals that are implicitly 64 bits wide.

The exceptions are where we rewrite floating-point operand values
as integer ones, which would not be assembled back to the original
values unless wrapped into lit64().

Respect explicit lit() modifiers for non-inline values as
necessary to avoid regressions in MC tests. This change still
doesn't prevent use of inline constants where lit()/lit64 is
specified; subject to a separate patch.

On disassembling, only create lit64() operands where necessary for
correct round-tripping.

Add round-tripping tests where useful and feasible.

---

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


24 Files Affected:

- (modified) llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp (+47-25) 
- (modified) llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp (+5-5) 
- (modified) llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCCodeEmitter.cpp (+6-3) 
- (modified) llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp (+2-2) 
- (modified) llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h (+1-1) 
- (modified) llvm/test/MC/AMDGPU/gfx1250_asm_salu_lit64.s (+28-22) 
- (modified) llvm/test/MC/AMDGPU/gfx1250_asm_sop1.s (+14-12) 
- (modified) llvm/test/MC/AMDGPU/gfx1250_asm_valu_lit64.s (+71-69) 
- (modified) llvm/test/MC/AMDGPU/gfx1250_asm_vop1-fake16.s (+1-1) 
- (modified) llvm/test/MC/AMDGPU/gfx1250_asm_vop1.s (+1-1) 
- (modified) llvm/test/MC/AMDGPU/gfx1250_asm_vop2.s (+18-16) 
- (modified) llvm/test/MC/AMDGPU/gfx12_asm_sop1.s (+34-33) 
- (modified) llvm/test/MC/AMDGPU/gfx12_asm_sop2.s (+34-33) 
- (modified) llvm/test/MC/AMDGPU/gfx12_asm_sopc.s (+3-2) 
- (modified) llvm/test/MC/AMDGPU/literals.s (+4-4) 
- (modified) llvm/test/MC/AMDGPU/vop3-literal.s (+2-1) 
- (modified) llvm/test/MC/Disassembler/AMDGPU/gfx1250_dasm_salu_lit64.txt 
(+18-18) 
- (modified) llvm/test/MC/Disassembler/AMDGPU/gfx1250_dasm_sop1.txt (+1-1) 
- (modified) llvm/test/MC/Disassembler/AMDGPU/gfx1250_dasm_valu_lit64.txt 
(+69-69) 
- (modified) llvm/test/MC/Disassembler/AMDGPU/gfx1250_dasm_vop1.txt (+1-1) 
- (modified) llvm/test/MC/Disassembler/AMDGPU/gfx1250_dasm_vop2.txt (+13-13) 
- (modified) llvm/test/MC/Disassembler/AMDGPU/gfx12_dasm_sop1.txt (+24-24) 
- (modified) llvm/test/MC/Disassembler/AMDGPU/gfx12_dasm_sop2.txt (+29-29) 
- (modified) llvm/test/MC/Disassembler/AMDGPU/gfx12_dasm_sopc.txt (+2-2) 


``diff
diff --git a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp 
b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
index a67a7bedf19a3..f7e7e39f70610 100644
--- a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
+++ b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
@@ -2330,6 +2330,7 @@ void AMDGPUOperand::addLiteralImmOperand(MCInst &Inst, 
int64_t Val, bool ApplyMo
   bool CanUse64BitLiterals =
   AsmParser->has64BitLiterals() &&
   !(InstDesc.TSFlags & (SIInstrFlags::VOP3 | SIInstrFlags::VOP3P));
+  LitModifier Lit = getModifiers().Lit;
   MCContext &Ctx = AsmParser->getContext();
 
   if (Imm.IsFPImm) { // We got fp literal token
@@ -2363,10 +2364,23 @@ void AMDGPUOperand::addLiteralImmOperand(MCInst &Inst, 
int64_t Val, bool ApplyMo
 
 if ((OpTy == AMDGPU::OPERAND_REG_IMM_FP64 ||
  OpTy == AMDGPU::OPERAND_REG_INLINE_C_FP64 ||
- OpTy == AMDGPU::OPERAND_REG_INLINE_AC_FP64) &&
-CanUse64BitLiterals && Lo_32(Val) != 0) {
-  Inst.addOperand(MCOperand::createExpr(
-  AMDGPUMCExpr::createLit(LitModifier::Lit64, Val, Ctx)));
+ OpTy == AMDGPU::OPERAND_REG_INLINE_AC_FP64)) {
+  if (CanUse64BitLiterals && Lit == LitModifier::None &&
+  (isInt<32>(Val) || isUInt<32>(Val))) {
+// The floating-point operand will be verbalized as an
+// integer one. If that integer happens to fit 32 bits, on
+// re-assembling it will be intepreted as the high half of
+// the actual value, so we have to wrap it into lit64().
+Lit = LitModifier::Lit64;
+  } else if (Lit == LitModifier::Lit) {
+// For FP64 operands lit() specifies the high half of the value.
+Val = Hi_32(Val);
+  }
+}
+
+if (Lit != LitModifier::None) {
+  Inst.addOperand(
+  MCOperand::createExpr(AMDGPUMCExpr::createLit(Lit, Val, Ctx)));
 } else {
   Inst.addOperand(MCOperand::createImm(Val));
 }
@@ -2379,9 +2393,13 @@ void AMDGPUOperand::addLiteralImmOperand(MCInst &Inst, 
int64_t Val, bool ApplyMo
   llvm_unreachable("fp literal in 64-bit integer instruction.");
 
 case AMDGPU::OPERAND_KIMM64:
-  if (CanUse64BitLiterals && Lo_32(Val) != 0) {
-Inst.addOperand(MCOperand

[llvm-branch-commits] [llvm] [AArch64][SME] Support split ZPR and PPR area allocation (PR #142392)

2025-09-29 Thread Sander de Smalen via llvm-branch-commits


@@ -1405,111 +1432,186 @@ void AArch64EpilogueEmitter::emitEpilogue() {
   NumBytes -= PrologueSaveSize;
   assert(NumBytes >= 0 && "Negative stack allocation size!?");
 
-  // Process the SVE callee-saves to determine what space needs to be
-  // deallocated.
-  StackOffset DeallocateBefore = {}, DeallocateAfter = SVEStackSize;
-  MachineBasicBlock::iterator RestoreBegin = FirstGPRRestoreI,
-  RestoreEnd = FirstGPRRestoreI;
-  int64_t ZPRCalleeSavedSize = AFI->getZPRCalleeSavedStackSize();
-  int64_t PPRCalleeSavedSize = AFI->getPPRCalleeSavedStackSize();
-  int64_t SVECalleeSavedSize = ZPRCalleeSavedSize + PPRCalleeSavedSize;
-
-  if (SVECalleeSavedSize) {
-if (FPAfterSVECalleeSaves)
-  RestoreEnd = MBB.getFirstTerminator();
-
-RestoreBegin = std::prev(RestoreEnd);
-while (RestoreBegin != MBB.begin() &&
-   isPartOfSVECalleeSaves(std::prev(RestoreBegin)))
-  --RestoreBegin;
-
-assert(isPartOfSVECalleeSaves(RestoreBegin) &&
-   isPartOfSVECalleeSaves(std::prev(RestoreEnd)) &&
-   "Unexpected instruction");
-
-StackOffset CalleeSavedSizeAsOffset =
-StackOffset::getScalable(SVECalleeSavedSize);
-DeallocateBefore = SVEStackSize - CalleeSavedSizeAsOffset;
-DeallocateAfter = CalleeSavedSizeAsOffset;
-  }
+  if (!AFI->hasSplitSVEObjects()) {
+// Process the SVE callee-saves to determine what space needs to be
+// deallocated.
+StackOffset DeallocateBefore = {}, DeallocateAfter = SVEStackSize;
+MachineBasicBlock::iterator RestoreBegin = FirstGPRRestoreI,
+RestoreEnd = FirstGPRRestoreI;
+int64_t ZPRCalleeSavedSize = AFI->getZPRCalleeSavedStackSize();
+int64_t PPRCalleeSavedSize = AFI->getPPRCalleeSavedStackSize();
+int64_t SVECalleeSavedSize = ZPRCalleeSavedSize + PPRCalleeSavedSize;
+
+if (SVECalleeSavedSize) {
+  if (FPAfterSVECalleeSaves)
+RestoreEnd = MBB.getFirstTerminator();
+
+  RestoreBegin = std::prev(RestoreEnd);
+  while (RestoreBegin != MBB.begin() &&
+ isPartOfSVECalleeSaves(std::prev(RestoreBegin)))
+--RestoreBegin;
+
+  assert(isPartOfSVECalleeSaves(RestoreBegin) &&
+ isPartOfSVECalleeSaves(std::prev(RestoreEnd)) &&
+ "Unexpected instruction");
 
-  // Deallocate the SVE area.
-  if (FPAfterSVECalleeSaves) {
-// If the callee-save area is before FP, restoring the FP implicitly
-// deallocates non-callee-save SVE allocations.  Otherwise, deallocate
-// them explicitly.
-if (!AFI->isStackRealigned() && !MFI.hasVarSizedObjects()) {
-  emitFrameOffset(MBB, FirstGPRRestoreI, DL, AArch64::SP, AArch64::SP,
-  DeallocateBefore, TII, MachineInstr::FrameDestroy, false,
-  NeedsWinCFI, &HasWinCFI);
+  StackOffset CalleeSavedSizeAsOffset =
+  StackOffset::getScalable(SVECalleeSavedSize);
+  DeallocateBefore = SVEStackSize - CalleeSavedSizeAsOffset;
+  DeallocateAfter = CalleeSavedSizeAsOffset;
 }
 
-// Deallocate callee-save non-SVE registers.
-emitFrameOffset(MBB, RestoreBegin, DL, AArch64::SP, AArch64::SP,
-StackOffset::getFixed(AFI->getCalleeSavedStackSize()), TII,
-MachineInstr::FrameDestroy, false, NeedsWinCFI, 
&HasWinCFI);
-
-// Deallocate fixed objects.
-emitFrameOffset(MBB, RestoreEnd, DL, AArch64::SP, AArch64::SP,
-StackOffset::getFixed(FixedObject), TII,
-MachineInstr::FrameDestroy, false, NeedsWinCFI, 
&HasWinCFI);
-
-// Deallocate callee-save SVE registers.
-emitFrameOffset(MBB, RestoreEnd, DL, AArch64::SP, AArch64::SP,
-DeallocateAfter, TII, MachineInstr::FrameDestroy, false,
-NeedsWinCFI, &HasWinCFI);
-  } else if (SVEStackSize) {
-int64_t SVECalleeSavedSize = AFI->getSVECalleeSavedStackSize();
-// If we have stack realignment or variable-sized objects we must use the
-// FP to restore SVE callee saves (as there is an unknown amount of
-// data/padding between the SP and SVE CS area).
-Register BaseForSVEDealloc =
-(AFI->isStackRealigned() || MFI.hasVarSizedObjects()) ? AArch64::FP
-  : AArch64::SP;
-if (SVECalleeSavedSize && BaseForSVEDealloc == AArch64::FP) {
-  Register CalleeSaveBase = AArch64::FP;
-  if (int64_t CalleeSaveBaseOffset =
-  AFI->getCalleeSaveBaseToFrameRecordOffset()) {
-// If we have have an non-zero offset to the non-SVE CS base we need to
-// compute the base address by subtracting the offest in a temporary
-// register first (to avoid briefly deallocating the SVE CS).
-CalleeSaveBase =
-MF.getRegInfo().createVirtualRegister(&AArch64::GPR64RegClass);
-emitFrameOffset(MBB, RestoreBegin, DL, CalleeSaveBase, AArch64::FP,
-Stack

[llvm-branch-commits] [llvm] [llvm][mustache] Simplify debug logging (PR #159193)

2025-09-29 Thread Paul Kirth via llvm-branch-commits

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

>From f153c6a4f81738c9777af5505294e4c83b817bf4 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Sat, 13 Sep 2025 23:21:07 -0700
Subject: [PATCH] [llvm][mustache] Simplify debug logging

---
 llvm/lib/Support/Mustache.cpp | 76 ---
 1 file changed, 43 insertions(+), 33 deletions(-)

diff --git a/llvm/lib/Support/Mustache.cpp b/llvm/lib/Support/Mustache.cpp
index e72c801d72fe8..c152cedce16c5 100644
--- a/llvm/lib/Support/Mustache.cpp
+++ b/llvm/lib/Support/Mustache.cpp
@@ -329,6 +329,36 @@ struct Tag {
   size_t StartPosition = StringRef::npos;
 };
 
+static const char *tagKindToString(Tag::Kind K) {
+  switch (K) {
+  case Tag::Kind::None:
+return "None";
+  case Tag::Kind::Normal:
+return "Normal";
+  case Tag::Kind::Triple:
+return "Triple";
+  }
+  llvm_unreachable("Unknown Tag::Kind");
+}
+
+static const char *jsonKindToString(json::Value::Kind K) {
+  switch (K) {
+  case json::Value::Kind::Null:
+return "JSON_KIND_NULL";
+  case json::Value::Kind::Boolean:
+return "JSON_KIND_BOOLEAN";
+  case json::Value::Kind::Number:
+return "JSON_KIND_NUMBER";
+  case json::Value::Kind::String:
+return "JSON_KIND_STRING";
+  case json::Value::Kind::Array:
+return "JSON_KIND_ARRAY";
+  case json::Value::Kind::Object:
+return "JSON_KIND_OBJECT";
+  }
+  llvm_unreachable("Unknown json::Value::Kind");
+}
+
 static Tag findNextTag(StringRef Template, size_t StartPos, StringRef Open,
StringRef Close) {
   const StringLiteral TripleOpen("{{{");
@@ -373,11 +403,10 @@ static Tag findNextTag(StringRef Template, size_t 
StartPos, StringRef Open,
 
 static std::optional>
 processTag(const Tag &T, SmallVectorImpl &Tokens) {
-  LLVM_DEBUG(dbgs() << "  Found tag: \"" << T.FullMatch << "\", Content: \""
-<< T.Content << "\"\n");
+  LLVM_DEBUG(dbgs() << "[Tag] " << T.FullMatch << ", Content: " << T.Content
+<< ", Kind: " << tagKindToString(T.TagKind) << "\n");
   if (T.TagKind == Tag::Kind::Triple) {
 Tokens.emplace_back(T.FullMatch.str(), "&" + T.Content.str(), '&');
-LLVM_DEBUG(dbgs() << "  Created UnescapeVariable token.\n");
 return std::nullopt;
   }
   StringRef Interpolated = T.Content;
@@ -385,7 +414,6 @@ processTag(const Tag &T, SmallVectorImpl &Tokens) {
   if (!Interpolated.trim().starts_with("=")) {
 char Front = Interpolated.empty() ? ' ' : Interpolated.trim().front();
 Tokens.emplace_back(RawBody, Interpolated.str(), Front);
-LLVM_DEBUG(dbgs() << "  Created tag token of type '" << Front << "'\n");
 return std::nullopt;
   }
   Tokens.emplace_back(RawBody, Interpolated.str(), '=');
@@ -395,8 +423,8 @@ processTag(const Tag &T, SmallVectorImpl &Tokens) {
   DelimSpec = DelimSpec.trim();
 
   std::pair Ret = DelimSpec.split(' ');
-  LLVM_DEBUG(dbgs() << "  Found Set Delimiter tag. NewOpen='" << Ret.first
-<< "', NewClose='" << Ret.second << "'\n");
+  LLVM_DEBUG(dbgs() << "[Set Delimiter] NewOpen: " << Ret.first
+<< ", NewClose: " << Ret.second << "\n");
   return Ret;
 }
 
@@ -405,14 +433,14 @@ processTag(const Tag &T, SmallVectorImpl &Tokens) {
 // but we don't support that here. An unescape variable
 // is represented only by {{& variable}}.
 static SmallVector tokenize(StringRef Template) {
-  LLVM_DEBUG(dbgs() << "Tokenizing template: \"" << Template << "\"\n");
+  LLVM_DEBUG(dbgs() << "[Tokenize Template] \"" << Template << "\"\n");
   SmallVector Tokens;
   SmallString<8> Open("{{");
   SmallString<8> Close("}}");
   size_t Start = 0;
 
   while (Start < Template.size()) {
-LLVM_DEBUG(dbgs() << "Loop start. Start=" << Start << ", Open='" << Open
+LLVM_DEBUG(dbgs() << "[Tokenize Loop] Start=" << Start << ", Open='" << 
Open
   << "', Close='" << Close << "'\n");
 Tag T = findNextTag(Template, Start, Open, Close);
 
@@ -428,7 +456,6 @@ static SmallVector tokenize(StringRef Template) {
 if (T.StartPosition > Start) {
   StringRef Text = Template.substr(Start, T.StartPosition - Start);
   Tokens.emplace_back(Text.str());
-  LLVM_DEBUG(dbgs() << "  Created Text token: \"" << Text << "\"\n");
 }
 
 if (auto NewDelims = processTag(T, Tokens)) {
@@ -479,7 +506,6 @@ static SmallVector tokenize(StringRef Template) {
 if ((!HasTextBehind && !HasTextAhead) || (!HasTextBehind && Idx == 
LastIdx))
   stripTokenBefore(Tokens, Idx, CurrentToken, CurrentType);
   }
-  LLVM_DEBUG(dbgs() << "Tokenizing finished.\n");
   return Tokens;
 }
 
@@ -530,7 +556,7 @@ class AddIndentationStringStream : public 
MustacheOutputStream {
 Indent.resize(Indentation, ' ');
 
 for (char C : Data) {
-  LLVM_DEBUG(dbgs() << "IndentationStream: NeedsIndent=" << NeedsIndent
+  LLVM_DEBUG(dbgs() << "[IndentationStream] NeedsIndent=" << NeedsIndent
 << ", C='" << C << "', I

[llvm-branch-commits] [llvm] [llvm][mustache] Avoid redundant saves in accessor splitting (PR #159197)

2025-09-29 Thread Paul Kirth via llvm-branch-commits

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

>From cb29414d1ecc2f15760041072bf8428e8b691bd3 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Tue, 16 Sep 2025 00:11:47 -0700
Subject: [PATCH] [llvm][mustache] Avoid redundant saves in accessor splitting

The splitMustacheString function was saving StringRefs that
were already backed by an arena-allocated string. This was
unnecessary work. This change removes the redundant
Ctx.Saver.save() call.

This optimization provides a small but measurable performance
improvement on top of the single-pass tokenizer, most notably
reducing branch misses.

  Metric | Baseline | Optimized | Change
  -- |  | - | ---
  Time (ms)  | 35.77| 35.57 | -0.56%
  Cycles | 35.16M   | 34.91M| -0.71%
  Instructions   | 85.77M   | 85.54M| -0.27%
  Branch Misses  | 113.9K   | 111.9K| -1.76%
  Cache Misses   | 237.7K   | 242.1K| +1.85%
---
 llvm/lib/Support/Mustache.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Support/Mustache.cpp b/llvm/lib/Support/Mustache.cpp
index 87e25ac68ada0..7b68f753b8802 100644
--- a/llvm/lib/Support/Mustache.cpp
+++ b/llvm/lib/Support/Mustache.cpp
@@ -51,7 +51,7 @@ static Accessor splitMustacheString(StringRef Str, 
MustacheContext &Ctx) {
   std::tie(Part, Str) = Str.split('.');
   // Each part of the accessor needs to be saved to the arena
   // to ensure it has a stable address.
-  Tokens.push_back(Ctx.Saver.save(Part.trim()));
+  Tokens.push_back(Part.trim());
 }
   }
   // Now, allocate memory for the array of StringRefs in the arena.

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


[llvm-branch-commits] ELF: Use preprocessed relocations for EhInputSection scanning (PR #161091)

2025-09-29 Thread Peter Smith via llvm-branch-commits

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

LGTM. Thanks for the update.

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


[llvm-branch-commits] ELF: Use preprocessed relocations for EhInputSection scanning (PR #161091)

2025-09-29 Thread Fangrui Song via llvm-branch-commits


@@ -473,6 +467,9 @@ class RelocationScanner {
 
   template 
   void scanOne(typename Relocs::const_iterator &i);
+  template 

MaskRay wrote:

Created #161229 to rewrite the file-level comment and give an overview.

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


[llvm-branch-commits] ELF: Use preprocessed relocations for EhInputSection scanning (PR #161091)

2025-09-29 Thread Fangrui Song via llvm-branch-commits

https://github.com/MaskRay updated 
https://github.com/llvm/llvm-project/pull/161091


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