[clang] Extend life of variables in `DiagComparison` in `ExprConstant` (PR #79522)

2024-01-26 Thread via cfe-commits

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

We need to understand what's going on here.
I suspect something gets tripped by the ternary.
A temporary fix might be to  assign 

```cpp
std::string first  = Reversed ? RHS : LHS;
std::string second  = Reversed ? LHS : RHS;
```
And use that in the diag.

We should also add a `std::string&&` overload to the diagnostic engine's 
`operator <<` to avoid extra copies, although that's mostly a luxury

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


[clang] [clang][analyzer] Simplify code of StreamChecker (NFC). (PR #79312)

2024-01-26 Thread Balázs Kéri via cfe-commits

balazske wrote:

For clarification, the `evalRWCommon` new function is not planned to be used in 
the same way as other `eval*` calls, the name may be misleading. This function 
contains a "generic algorithm" that is called from the other `eval*` calls, but 
not used directly in `CallDescriptionMap`. The old `eval*` calls and the 
`evalRWCommon` are not meant to be called from each other, except 
`evalRWCommon` from other `eval*` calls. I agree that using lambdas makes 
debugging more difficult and lambdas are not ideal for big parts of code and 
code formatting is not nice either.

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


[clang] [clang-tools-extra] [llvm] Add clang-tidy check to suggest replacement of conditional statement with std::min/std::max (PR #77816)

2024-01-26 Thread Bhuminjay Soni via cfe-commits


@@ -0,0 +1,189 @@
+//===--- UseStdMinMaxCheck.cpp - clang-tidy 
---===//
+//
+// 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 "UseStdMinMaxCheck.h"
+#include "../utils/ASTUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Preprocessor.h"
+#include 
+using namespace std;
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+class ExprVisitor : public clang::RecursiveASTVisitor {
+public:
+  explicit ExprVisitor(clang::ASTContext *Context) : Context(Context) {}
+  bool visitStmt(const clang::Stmt *S, bool &found,
+ clang::QualType &GlobalImplicitCastType) {
+
+if (isa(S) && !found) {
+  found = true;
+  const clang::ImplicitCastExpr *ImplicitCast =
+  cast(S);
+  GlobalImplicitCastType = ImplicitCast->getType();
+  // Stop visiting children.
+  return false;
+}
+// Continue visiting children.
+for (const clang::Stmt *Child : S->children()) {
+  if (Child) {
+this->visitStmt(Child, found, GlobalImplicitCastType);
+  }
+}
+
+return true; // Continue visiting other nodes.
+  }
+
+private:
+  clang::ASTContext *Context;

11happy wrote:

Not able to remove it , actually its been used, sorry If I misunderstood 
anything can you please explain it.

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


[clang-tools-extra] [clangd] Allow specifying what headers are always included via "" or <> (PR #67749)

2024-01-26 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

Sorry, I'm still struggling with Github reviews compared to Phabricator... how 
do I get to an interdiff showing the latest version of the patch compared to 
the version I reviewed?

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


[clang] [llvm] [clang-tools-extra] [Clang] Fix : More Detailed "No expected directives found" (PR #78338)

2024-01-26 Thread Shourya Goel via cfe-commits


@@ -1098,7 +1098,13 @@ void VerifyDiagnosticConsumer::CheckDiagnostics() {
 // Produce an error if no expected-* directives could be found in the
 // source file(s) processed.
 if (Status == HasNoDirectives) {
-  Diags.Report(diag::err_verify_no_directives).setForceEmit();
+  std::string directives;
+  if (Diags.getDiagnosticOptions().VerifyPrefixes.empty()) {
+directives = "expected";

Sh0g0-1758 wrote:

Considering this as resolved then. 

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


[clang-tools-extra] [clang] [llvm] [Clang] Fix : More Detailed "No expected directives found" (PR #78338)

2024-01-26 Thread Shourya Goel via cfe-commits


@@ -1098,7 +1098,16 @@ void VerifyDiagnosticConsumer::CheckDiagnostics() {
 // Produce an error if no expected-* directives could be found in the
 // source file(s) processed.
 if (Status == HasNoDirectives) {
-  Diags.Report(diag::err_verify_no_directives).setForceEmit();
+  std::string directives;
+  for (auto &Prefix : Diags.getDiagnosticOptions().VerifyPrefixes) {
+directives = directives + Prefix + ",";
+  }

Sh0g0-1758 wrote:

Considering this as resolved. 

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


[clang-tools-extra] [clang] [llvm] [Clang] Fix : More Detailed "No expected directives found" (PR #78338)

2024-01-26 Thread Shourya Goel via cfe-commits

https://github.com/Sh0g0-1758 updated 
https://github.com/llvm/llvm-project/pull/78338

>From b98f02d4c155b5be9bd4f5b2e4bf73720a81f39a Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 
Date: Wed, 17 Jan 2024 01:24:17 +0530
Subject: [PATCH 01/11] Fix : more detailed no expected directive message

---
 clang-tools-extra/clangd/test/indexer.test   | 2 +-
 clang/include/clang/Basic/Diagnostic.h   | 4 +++-
 clang/include/clang/Basic/DiagnosticFrontendKinds.td | 2 +-
 clang/lib/AST/ASTContext.cpp | 2 +-
 clang/lib/Frontend/VerifyDiagnosticConsumer.cpp  | 4 +++-
 clang/test/ARCMT/verify.m| 2 +-
 clang/test/Frontend/verify.c | 2 +-
 clang/test/Frontend/verify2.c| 2 +-
 clang/test/Frontend/verify3.c| 4 ++--
 9 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/clang-tools-extra/clangd/test/indexer.test 
b/clang-tools-extra/clangd/test/indexer.test
index 2f01f6c557a7de..213d33f8e2d6a5 100644
--- a/clang-tools-extra/clangd/test/indexer.test
+++ b/clang-tools-extra/clangd/test/indexer.test
@@ -5,5 +5,5 @@
 # `.ii` file and `-verify` triggers extra diagnostics generation. Clangd should
 # strip those.
 # RUN: clangd-indexer %t.cpp -- -Xclang -verify --save-temps -- 2>&1 | 
FileCheck %s
-# CHECK-NOT: error: no expected directives found: consider use of 
'expected-no-diagnostics'
+# CHECK-NOT: error: no expected directives found: consider use of 
{{.*}}-no-diagnostics
 # RUN: not ls %t.ii
diff --git a/clang/include/clang/Basic/Diagnostic.h 
b/clang/include/clang/Basic/Diagnostic.h
index 0c7836c2ea569c..a185c75e418b58 100644
--- a/clang/include/clang/Basic/Diagnostic.h
+++ b/clang/include/clang/Basic/Diagnostic.h
@@ -9,7 +9,9 @@
 /// \file
 /// Defines the Diagnostic-related interfaces.
 //
-//===--===//
+//===--===//]
+
+// look into this file as well
 
 #ifndef LLVM_CLANG_BASIC_DIAGNOSTIC_H
 #define LLVM_CLANG_BASIC_DIAGNOSTIC_H
diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 568000106a84dc..42d2767af6b708 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -179,7 +179,7 @@ def err_verify_invalid_no_diags : Error<
 "%select{expected|'expected-no-diagnostics'}0 directive cannot follow "
 "%select{'expected-no-diagnostics' directive|other expected directives}0">;
 def err_verify_no_directives : Error<
-"no expected directives found: consider use of 'expected-no-diagnostics'">;
+"no expected directives found: consider use of '%0'-no-diagnostics">;
 def err_verify_nonconst_addrspace : Error<
   "qualifier 'const' is needed for variables in address space '%0'">;
 
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index b60dcfaabfd1a4..0997ac9fa7df04 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1404,7 +1404,7 @@ void ASTContext::InitBuiltinTypes(const TargetInfo 
&Target,
 getTranslationUnitDecl()->addDecl(MSGuidTagDecl);
   }
 }
-
+// maybe change here also. 
 DiagnosticsEngine &ASTContext::getDiagnostics() const {
   return SourceMgr.getDiagnostics();
 }
diff --git a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp 
b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
index 8a3d2286cd168c..9a26905a76d46b 100644
--- a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
+++ b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
@@ -1098,7 +1098,9 @@ void VerifyDiagnosticConsumer::CheckDiagnostics() {
 // Produce an error if no expected-* directives could be found in the
 // source file(s) processed.
 if (Status == HasNoDirectives) {
-  Diags.Report(diag::err_verify_no_directives).setForceEmit();
+  // change here
+  std::string directives = 
*Diags.getDiagnosticOptions().VerifyPrefixes.begin();
+  Diags.Report(diag::err_verify_no_directives).setForceEmit() << 
directives;
   ++NumErrors;
   Status = HasNoDirectivesReported;
 }
diff --git a/clang/test/ARCMT/verify.m b/clang/test/ARCMT/verify.m
index 7d245fe80575e5..13fd599f530fbe 100644
--- a/clang/test/ARCMT/verify.m
+++ b/clang/test/ARCMT/verify.m
@@ -11,7 +11,7 @@
 #error
 // expected-error@-1 {{}}
 
-//  CHECK: error: no expected directives found: consider use of 
'expected-no-diagnostics'
+//  CHECK: error: no expected directives found: consider use of 
{{.*}}-no-diagnostics
 // CHECK-NEXT: error: 'expected-error' diagnostics seen but not expected:
 // CHECK-NEXT:   (frontend): error reading '{{.*}}verify.m.tmp.invalid'
 // CHECK-NEXT: 2 errors generated.
diff --git a/clang/test/Frontend/verify.c b/clang/test/Frontend/verify.c
index 221b715c19e416..657a9d3f2bf6bb 100644
--- a/clang/test/Frontend/verify.c
+++ b/clang/test/F

[clang-tools-extra] [clang] [llvm] [Clang] Fix : More Detailed "No expected directives found" (PR #78338)

2024-01-26 Thread Shourya Goel via cfe-commits

Sh0g0-1758 wrote:

@asl @tbaederr @AaronBallman, can you please review this PR and merge it if 
everything seems fine.  

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


[lld] [clang] [llvm] [SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used together by decoupling the handling of the two features. (PR #74128)

2024-01-26 Thread Aiden Grossman via cfe-commits

https://github.com/boomanaiden154 edited 
https://github.com/llvm/llvm-project/pull/74128
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lld] [llvm] [SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used together by decoupling the handling of the two features. (PR #74128)

2024-01-26 Thread Aiden Grossman via cfe-commits

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

Just nits/minor questions from me, code otherwise LGTM.

Sorry for the delay in review. I didn't realize you explicitly wanted me to 
review portions of the code.

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


[llvm] [lld] [clang] [SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used together by decoupling the handling of the two features. (PR #74128)

2024-01-26 Thread Aiden Grossman via cfe-commits


@@ -1693,24 +1750,21 @@ disassembleObject(ObjectFile &Obj, const ObjectFile 
&DbgObj,
 
   LLVM_DEBUG(LVP.dump());
 
-  std::unordered_map AddrToBBAddrMap;
-  std::unordered_map AddrToPGOAnalysisMap;
+  BBAddrMapInfo FullAddrMap;
   auto ReadBBAddrMap = [&](std::optional SectionIndex =
std::nullopt) {
-AddrToBBAddrMap.clear();
+FullAddrMap.clear();
 if (const auto *Elf = dyn_cast(&Obj)) {
   std::vector PGOAnalyses;
   auto BBAddrMapsOrErr = Elf->readBBAddrMap(SectionIndex, &PGOAnalyses);
   if (!BBAddrMapsOrErr) {
 reportWarning(toString(BBAddrMapsOrErr.takeError()), 
Obj.getFileName());
 return;
   }
-  for (const auto &[FunctionBBAddrMap, FunctionPGOAnalysis] :
+  for (auto &&[FunctionBBAddrMap, FunctionPGOAnalysis] :

boomanaiden154 wrote:

Looks like this is still here since this hasn't been rebased/main hasn't been 
merged in recently?

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


[clang] [llvm] [lld] [SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used together by decoupling the handling of the two features. (PR #74128)

2024-01-26 Thread Aiden Grossman via cfe-commits


@@ -172,6 +172,105 @@ class OtoolOptTable : public CommonOptTable {
"Mach-O object file displaying tool") {}
 };
 
+struct BBAddrMapLabel {
+  std::string BlockLabel;
+  std::string PGOAnalysis;
+};
+
+// This class represents the BBAddrMap and PGOMap associated with a single
+// function.
+class BBAddrMapFunctionEntry {
+public:
+  BBAddrMapFunctionEntry(BBAddrMap AddrMap, PGOAnalysisMap PGOMap)
+  : AddrMap(std::move(AddrMap)), PGOMap(std::move(PGOMap)) {}
+
+  const BBAddrMap &getAddrMap() const { return AddrMap; }
+
+  // Returns the PGO string associated with the entry of index 
`PGOBBEntryIndex`
+  // in `PGOMap`.
+  std::string constructPGOLabelString(size_t PGOBBEntryIndex) const {
+if (!PGOMap.FeatEnable.hasPGOAnalysis())
+  return "";
+std::string PGOString;
+raw_string_ostream PGOSS(PGOString);
+
+PGOSS << " (";
+if (PGOMap.FeatEnable.FuncEntryCount && PGOBBEntryIndex == 0) {
+  PGOSS << "Entry count: " << Twine(PGOMap.FuncEntryCount);
+  if (PGOMap.FeatEnable.hasPGOAnalysisBBData()) {
+PGOSS << ", ";
+  }
+}
+
+if (PGOMap.FeatEnable.hasPGOAnalysisBBData()) {
+
+  assert(PGOBBEntryIndex < PGOMap.BBEntries.size() &&
+ "Expected PGOAnalysisMap and BBAddrMap to have the same entires");

boomanaiden154 wrote:

`/s/entires/entries`

Looks like a typo carried over from my `llvm-objdump` patch adding in support 
for symbolizing PGO Analysis data.

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


[llvm] [lld] [clang] [SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used together by decoupling the handling of the two features. (PR #74128)

2024-01-26 Thread Aiden Grossman via cfe-commits


@@ -172,6 +172,105 @@ class OtoolOptTable : public CommonOptTable {
"Mach-O object file displaying tool") {}
 };
 
+struct BBAddrMapLabel {
+  std::string BlockLabel;
+  std::string PGOAnalysis;
+};
+
+// This class represents the BBAddrMap and PGOMap associated with a single
+// function.
+class BBAddrMapFunctionEntry {
+public:
+  BBAddrMapFunctionEntry(BBAddrMap AddrMap, PGOAnalysisMap PGOMap)
+  : AddrMap(std::move(AddrMap)), PGOMap(std::move(PGOMap)) {}
+
+  const BBAddrMap &getAddrMap() const { return AddrMap; }
+
+  // Returns the PGO string associated with the entry of index 
`PGOBBEntryIndex`
+  // in `PGOMap`.
+  std::string constructPGOLabelString(size_t PGOBBEntryIndex) const {
+if (!PGOMap.FeatEnable.hasPGOAnalysis())
+  return "";
+std::string PGOString;
+raw_string_ostream PGOSS(PGOString);
+
+PGOSS << " (";
+if (PGOMap.FeatEnable.FuncEntryCount && PGOBBEntryIndex == 0) {
+  PGOSS << "Entry count: " << Twine(PGOMap.FuncEntryCount);
+  if (PGOMap.FeatEnable.hasPGOAnalysisBBData()) {
+PGOSS << ", ";
+  }
+}
+
+if (PGOMap.FeatEnable.hasPGOAnalysisBBData()) {
+
+  assert(PGOBBEntryIndex < PGOMap.BBEntries.size() &&
+ "Expected PGOAnalysisMap and BBAddrMap to have the same entires");
+  const PGOAnalysisMap::PGOBBEntry &PGOBBEntry =
+  PGOMap.BBEntries[PGOBBEntryIndex];
+
+  if (PGOMap.FeatEnable.BBFreq) {
+PGOSS << "Frequency: " << Twine(PGOBBEntry.BlockFreq.getFrequency());
+if (PGOMap.FeatEnable.BrProb && PGOBBEntry.Successors.size() > 0) {
+  PGOSS << ", ";
+}
+  }
+  if (PGOMap.FeatEnable.BrProb && PGOBBEntry.Successors.size() > 0) {
+PGOSS << "Successors: ";
+interleaveComma(
+PGOBBEntry.Successors, PGOSS,
+[&PGOSS](const PGOAnalysisMap::PGOBBEntry::SuccessorEntry &SE) {
+  PGOSS << "BB" << SE.ID << ":";
+  PGOSS.write_hex(SE.Prob.getNumerator());
+});
+  }
+}
+PGOSS << ")";
+
+return PGOString;
+  }
+
+private:
+  const BBAddrMap AddrMap;
+  const PGOAnalysisMap PGOMap;
+};
+
+// This class represents the BBAddrMap and PGOMap of potentially multiple
+// functions in a section.
+class BBAddrMapInfo {
+public:
+  void clear() {
+FunctionAddrToMap.clear();
+RangeBaseAddrToFunctionAddr.clear();
+  }
+  bool empty() const { return FunctionAddrToMap.empty(); }
+
+  void AddFunctionEntry(BBAddrMap AddrMap, PGOAnalysisMap PGOMap) {
+uint64_t FunctionAddr = AddrMap.getFunctionAddress();
+for (size_t I = 1; I < AddrMap.BBRanges.size(); ++I)
+  RangeBaseAddrToFunctionAddr.emplace(AddrMap.BBRanges[I].BaseAddress,
+  FunctionAddr);
+[[maybe_unused]] auto R = FunctionAddrToMap.try_emplace(
+FunctionAddr, std::move(AddrMap), std::move(PGOMap));
+assert(R.second && "duplicate function address");
+  }
+
+  const BBAddrMapFunctionEntry *getEntryForAddress(uint64_t BaseAddress) const 
{

boomanaiden154 wrote:

I'm assuming this is returning a pointer rather than a `std::optional` due to 
the inability to return an optional reference without something like a 
`std::reference_wrapper`?

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


[lld] [clang] [llvm] [SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used together by decoupling the handling of the two features. (PR #74128)

2024-01-26 Thread Aiden Grossman via cfe-commits


@@ -73,68 +83,89 @@ FileHeader:
 Sections:
   - Name:.text.foo
 Type:SHT_PROGBITS
-Address: [[FOO_ADDR]]
+Address: 0x4000
 Flags:   [SHF_ALLOC, SHF_EXECINSTR]
-Content: '503b050520907d02ebf5c3'
+Content: '503b050530907d08ebf50f8dee1fc3'
   - Name:.text.bar
 Type:SHT_PROGBITS
-Address: [[BAR_ADDR]]
+Address: 0x5000
 Flags:   [SHF_ALLOC, SHF_EXECINSTR]
 Content: '5089d0740231f6e8f4ffc3'
+  - Name:.text.split
+Type:SHT_PROGBITS
+Address: 0x6000
+Flags:   [SHF_ALLOC, SHF_EXECINSTR]
+Content: 'c3'
   - Name:.data
 Type:SHT_PROGBITS
 Flags:   [SHF_ALLOC, SHF_WRITE]
-Address: 0x6000
+Address: 0x7000
   - Name:   .llvm_bb_addr_map.foo
 Type:   SHT_LLVM_BB_ADDR_MAP
 Link:   .text.foo
 Entries:
   - Version: 2
-Address: [[FOO_ADDR]]
-BBEntries:
-  - ID:3
-AddressOffset: 0x0
-Size:  0x1
-Metadata:  0x1
-  - ID:1
-AddressOffset: 0x0
-Size:  0x6
-Metadata:  0x0
-  - ID:2
-AddressOffset: 0x1
-Size:  0x4
-Metadata:  0x0
-  - ID:5
-AddressOffset: 0x0
-Size:  0x1
-Metadata:  0x2
+Feature: 0x8
+BBRanges:
+  - BaseAddress: 0x4000
+BBEntries:
+ - ID:3
+   AddressOffset: 0x0

boomanaiden154 wrote:

Why do all of these BBs except for one have an address offset of zero? The 
symbolization seems fine, but given the address offset is relative to the base 
address of the range, it seems like these should all map to the same object? 
Unless the code in `yaml2obj` automatically takes into account the size and the 
AddressOffset is additional?

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


[clang-tools-extra] [llvm] [clang] [SeperateConstOffsetFromGEP] Handle `or disjoint` flags (PR #76997)

2024-01-26 Thread Matt Arsenault via cfe-commits

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


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


[clang-tools-extra] [llvm] [clang] [SeperateConstOffsetFromGEP] Handle `or disjoint` flags (PR #76997)

2024-01-26 Thread Matt Arsenault via cfe-commits

arsenm wrote:

Not sure if we need additional negative tests for missing disjoints 

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


[clang] f6290e0 - [NFC][FMV] Add tests to demonstrate feature priorities. (#79455)

2024-01-26 Thread via cfe-commits

Author: Alexandros Lamprineas
Date: 2024-01-26T09:27:28Z
New Revision: f6290e0daf5aff7132cab097fb13aad8a20ad070

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

LOG: [NFC][FMV] Add tests to demonstrate feature priorities. (#79455)

Adds tests showing that we select function version according to the
highest feature priority. This will make the changes introduced by
#79316 more evident.

Added: 


Modified: 
clang/test/CodeGen/attr-target-version.c

Removed: 




diff  --git a/clang/test/CodeGen/attr-target-version.c 
b/clang/test/CodeGen/attr-target-version.c
index 89279852a8c91d..feb6c094ab62b1 100644
--- a/clang/test/CodeGen/attr-target-version.c
+++ b/clang/test/CodeGen/attr-target-version.c
@@ -36,6 +36,10 @@ inline int 
__attribute__((target_version("sve2-aes+sve2-sha3"))) fmv_inline(void
 inline int __attribute__((target_version("sve2+sve2-pmull128+sve2-bitperm"))) 
fmv_inline(void) { return 9; }
 inline int __attribute__((target_version("sve2-sm4+memtag2"))) 
fmv_inline(void) { return 10; }
 inline int __attribute__((target_version("memtag3+rcpc3+mops"))) 
fmv_inline(void) { return 11; }
+inline int __attribute__((target_version("aes+dotprod"))) fmv_inline(void) { 
return 13; }
+inline int __attribute__((target_version("simd+fp16fml"))) fmv_inline(void) { 
return 14; }
+inline int __attribute__((target_version("fp+sm4"))) fmv_inline(void) { return 
15; }
+inline int __attribute__((target_version("lse+rdm"))) fmv_inline(void) { 
return 16; }
 inline int __attribute__((target_version("default"))) fmv_inline(void) { 
return 3; }
 
 __attribute__((target_version("ls64"))) int fmv_e(void);
@@ -359,6 +363,38 @@ int hoo(void) {
 // CHECK:   resolver_return21:
 // CHECK-NEXT:ret ptr @fmv_inline._Mdpb2Mjscvt
 // CHECK:   resolver_else22:
+// CHECK-NEXT:[[TMP48:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
+// CHECK-NEXT:[[TMP49:%.*]] = and i64 [[TMP48]], 16400
+// CHECK-NEXT:[[TMP50:%.*]] = icmp eq i64 [[TMP49]], 16400
+// CHECK-NEXT:[[TMP51:%.*]] = and i1 true, [[TMP50]]
+// CHECK-NEXT:br i1 [[TMP51]], label [[RESOLVER_RETURN23:%.*]], label 
[[RESOLVER_ELSE24:%.*]]
+// CHECK:   resolver_return23:
+// CHECK-NEXT:ret ptr @fmv_inline._MdotprodMaes
+// CHECK:   resolver_else24:
+// CHECK-NEXT:[[TMP52:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
+// CHECK-NEXT:[[TMP53:%.*]] = and i64 [[TMP52]], 8
+// CHECK-NEXT:[[TMP54:%.*]] = icmp eq i64 [[TMP53]], 8
+// CHECK-NEXT:[[TMP55:%.*]] = and i1 true, [[TMP54]]
+// CHECK-NEXT:br i1 [[TMP55]], label [[RESOLVER_RETURN25:%.*]], label 
[[RESOLVER_ELSE26:%.*]]
+// CHECK:   resolver_return25:
+// CHECK-NEXT:ret ptr @fmv_inline._Mfp16fmlMsimd
+// CHECK:   resolver_else26:
+// CHECK-NEXT:[[TMP56:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
+// CHECK-NEXT:[[TMP57:%.*]] = and i64 [[TMP56]], 32
+// CHECK-NEXT:[[TMP58:%.*]] = icmp eq i64 [[TMP57]], 32
+// CHECK-NEXT:[[TMP59:%.*]] = and i1 true, [[TMP58]]
+// CHECK-NEXT:br i1 [[TMP59]], label [[RESOLVER_RETURN27:%.*]], label 
[[RESOLVER_ELSE28:%.*]]
+// CHECK:   resolver_return27:
+// CHECK-NEXT:ret ptr @fmv_inline._Msm4Mfp
+// CHECK:   resolver_else28:
+// CHECK-NEXT:[[TMP60:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
+// CHECK-NEXT:[[TMP61:%.*]] = and i64 [[TMP60]], 192
+// CHECK-NEXT:[[TMP62:%.*]] = icmp eq i64 [[TMP61]], 192
+// CHECK-NEXT:[[TMP63:%.*]] = and i1 true, [[TMP62]]
+// CHECK-NEXT:br i1 [[TMP63]], label [[RESOLVER_RETURN29:%.*]], label 
[[RESOLVER_ELSE30:%.*]]
+// CHECK:   resolver_return29:
+// CHECK-NEXT:ret ptr @fmv_inline._MrdmMlse
+// CHECK:   resolver_else30:
 // CHECK-NEXT:ret ptr @fmv_inline.default
 //
 //
@@ -616,6 +652,34 @@ int hoo(void) {
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MdotprodMaes
+// CHECK-SAME: () #[[ATTR6]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 13
+//
+//
+// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._Mfp16fmlMsimd
+// CHECK-SAME: () #[[ATTR7]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 14
+//
+//
+// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._Msm4Mfp
+// CHECK-SAME: () #[[ATTR24:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 15
+//
+//
+// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MrdmMlse
+// CHECK-SAME: () #[[ATTR25:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 16
+//
+//
+// CHECK: Function Attrs: noinline nounwind optnone
 // CHECK-LABEL: define {{[^@]+}}@fmv_inline.default
 // CHECK-SAME: () #[[AT

[clang] [NFC][FMV] Add tests to demonstrate feature priorities. (PR #79455)

2024-01-26 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea closed 
https://github.com/llvm/llvm-project/pull/79455
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema] Substitute parameter packs when deduced from function arguments (PR #79371)

2024-01-26 Thread Gábor Spaits via cfe-commits

spaits wrote:

It looks like libc++ test suites are failing. Looking at the logs from the CI I 
can not really figure out what is the exact reason.
I could only deduce that the failing test case is 
`libcxx/gdb/gdb_pretty_printer_test.sh.cpp`. This case seems to be related to 
`libcxx/selftest/convenience_substitutions/build_run.sh.cpp`. I will try to 
figure out how to set up my environment to run these tests.

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


[clang-tools-extra] [llvm] ValueTracking: Merge fcmpImpliesClass and fcmpToClassTest (PR #66522)

2024-01-26 Thread Matt Arsenault via cfe-commits

https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/66522

>From 076ab2374d84c4112e0bf3fb11ecda2f5774785e Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Mon, 11 Sep 2023 10:56:40 +0300
Subject: [PATCH 1/2] ValueTracking: Merge fcmpImpliesClass and fcmpToClassTest

---
 llvm/include/llvm/Analysis/ValueTracking.h |  13 +-
 llvm/lib/Analysis/ValueTracking.cpp| 250 -
 2 files changed, 147 insertions(+), 116 deletions(-)

diff --git a/llvm/include/llvm/Analysis/ValueTracking.h 
b/llvm/include/llvm/Analysis/ValueTracking.h
index c25dcad5e2242a..ce2571cccf77cf 100644
--- a/llvm/include/llvm/Analysis/ValueTracking.h
+++ b/llvm/include/llvm/Analysis/ValueTracking.h
@@ -214,8 +214,10 @@ std::pair 
fcmpToClassTest(CmpInst::Predicate Pred,
 const APFloat *ConstRHS,
 bool LookThroughSrc = true);
 
-/// Compute the possible floating-point classes that \p LHS could be based on 
an
-/// fcmp returning true. Returns { TestedValue, ClassesIfTrue, ClassesIfFalse }
+/// Compute the possible floating-point classes that \p LHS could be based on
+/// fcmp \Pred \p LHS, \p RHS.
+///
+/// Returns { TestedValue, ClassesIfTrue, ClassesIfFalse }
 ///
 /// If the compare returns an exact class test, ClassesIfTrue == 
~ClassesIfFalse
 ///
@@ -230,10 +232,13 @@ std::pair 
fcmpToClassTest(CmpInst::Predicate Pred,
 ///
 std::tuple
 fcmpImpliesClass(CmpInst::Predicate Pred, const Function &F, Value *LHS,
- const APFloat *ConstRHS, bool LookThroughSrc = true);
+ Value *RHS, bool LookThroughSrc = true);
 std::tuple
 fcmpImpliesClass(CmpInst::Predicate Pred, const Function &F, Value *LHS,
- Value *RHS, bool LookThroughSrc = true);
+ FPClassTest RHS, bool LookThroughSrc = true);
+std::tuple
+fcmpImpliesClass(CmpInst::Predicate Pred, const Function &F, Value *LHS,
+ const APFloat &RHS, bool LookThroughSrc = true);
 
 struct KnownFPClass {
   /// Floating-point classes the value could be one of.
diff --git a/llvm/lib/Analysis/ValueTracking.cpp 
b/llvm/lib/Analysis/ValueTracking.cpp
index 1f09d912f7339f..d1c453807cea5e 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -3948,67 +3948,104 @@ std::pair 
llvm::fcmpToClassTest(FCmpInst::Predicate Pred,
 std::pair
 llvm::fcmpToClassTest(FCmpInst::Predicate Pred, const Function &F, Value *LHS,
   const APFloat *ConstRHS, bool LookThroughSrc) {
+
+  auto [Src, ClassIfTrue, ClassIfFalse] =
+  fcmpImpliesClass(Pred, F, LHS, *ConstRHS, LookThroughSrc);
+  if (Src && ClassIfTrue == ~ClassIfFalse)
+return {Src, ClassIfTrue};
+  return {nullptr, fcAllFlags};
+}
+
+/// Return the return value for fcmpImpliesClass for a compare that produces an
+/// exact class test.
+static std::tuple exactClass(Value *V,
+FPClassTest M) 
{
+  return {V, M, ~M};
+}
+
+std::tuple
+llvm::fcmpImpliesClass(CmpInst::Predicate Pred, const Function &F, Value *LHS,
+   FPClassTest RHSClass, bool LookThroughSrc) {
+  assert(RHSClass != fcNone);
+
+  const FPClassTest OrigClass = RHSClass;
+
+  Value *Src = LHS;
+  const bool IsNegativeRHS = (RHSClass & fcNegative) == RHSClass;
+  const bool IsPositiveRHS = (RHSClass & fcPositive) == RHSClass;
+  const bool IsNaN = (RHSClass & ~fcNan) == fcNone;
+
+  if (IsNaN) {
+// fcmp o__ x, nan -> false
+// fcmp u__ x, nan -> true
+return exactClass(Src, CmpInst::isOrdered(Pred) ? fcNone : fcAllFlags);
+  }
+
   // fcmp ord x, zero|normal|subnormal|inf -> ~fcNan
-  if (Pred == FCmpInst::FCMP_ORD && !ConstRHS->isNaN())
-return {LHS, ~fcNan};
+  if (Pred == FCmpInst::FCMP_ORD)
+return {Src, ~fcNan, fcNan};
 
   // fcmp uno x, zero|normal|subnormal|inf -> fcNan
-  if (Pred == FCmpInst::FCMP_UNO && !ConstRHS->isNaN())
-return {LHS, fcNan};
+  if (Pred == FCmpInst::FCMP_UNO)
+return {Src, fcNan, ~fcNan};
+
+  const bool IsFabs = LookThroughSrc && match(LHS, m_FAbs(m_Value(Src)));
+  if (IsFabs)
+RHSClass = llvm::inverse_fabs(RHSClass);
 
-  if (ConstRHS->isZero()) {
+  const bool IsZero = (OrigClass & fcZero) == OrigClass;
+  if (IsZero) {
 // Compares with fcNone are only exactly equal to fcZero if input denormals
 // are not flushed.
 // TODO: Handle DAZ by expanding masks to cover subnormal cases.
 if (Pred != FCmpInst::FCMP_ORD && Pred != FCmpInst::FCMP_UNO &&
 !inputDenormalIsIEEE(F, LHS->getType()))
-  return {nullptr, fcAllFlags};
+  return {nullptr, fcAllFlags, fcAllFlags};
 
 switch (Pred) {
 case FCmpInst::FCMP_OEQ: // Match x == 0.0
-  return {LHS, fcZero};
+  return exactClass(Src, fcZero);
 case FCmpInst::FCMP_UEQ: // Match isnan(x) || (x == 0.0)
-  return {LHS, fcZero | fcNan};
+  return exactClass(Src, fcZero | fcN

[clang] [WIP] Try to fix GH73418 (PR #79568)

2024-01-26 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 created 
https://github.com/llvm/llvm-project/pull/79568

For the purpose of poking the libc++ CI.

>From 212a4efbc65c437f652dc08c75ed4a836167fe70 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 26 Jan 2024 18:03:37 +0800
Subject: [PATCH] [clang][Sema] fixup

---
 clang/lib/Sema/SemaConcept.cpp | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index acfc00f41254074..3d77125106b05d1 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -612,8 +612,10 @@ bool Sema::SetupConstraintScope(
 
 // If this is a member function, make sure we get the parameters that
 // reference the original primary template.
-if (const auto *FromMemTempl =
-PrimaryTemplate->getInstantiatedFromMemberTemplate()) {
+for (FunctionTemplateDecl *FromMemTempl =
+ PrimaryTemplate->getInstantiatedFromMemberTemplate();
+ FromMemTempl;
+ FromMemTempl = FromMemTempl->getInstantiatedFromMemberTemplate()) {
   if (addInstantiatedParametersToScope(FD, 
FromMemTempl->getTemplatedDecl(),
Scope, MLTAL))
 return true;

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


[clang-tools-extra] [flang] [llvm] [libcxx] [clang] [libcxxabi] [compiler-rt] [libc] [lldb] [lld] [libclc] [VPlan] Add new VPScalarCastRecipe, use for IV & step trunc. (PR #78113)

2024-01-26 Thread Florian Hahn via cfe-commits

https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/78113

>From 36b085f21b76d7bf7c9965a86a09d1cef4fe9329 Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Sun, 14 Jan 2024 14:13:08 +
Subject: [PATCH 1/9] [VPlan] Add new VPUniformPerUFRecipe, use for step
 truncation.

Add a new recipe to model uniform-per-UF instructions, without relying
on an underlying instruction. Initially, it supports uniform cast-ops
and is therefore storing the result type.

Not relying on an underlying instruction (like the current
VPReplicateRecipe) allows to create instances without a corresponding
instruction.

In the future, to plan is to extend this recipe to handle all opcodes
needed to replace the uniform part of VPReplicateRecipe.
---
 llvm/lib/Transforms/Vectorize/VPlan.h | 30 
 .../Transforms/Vectorize/VPlanAnalysis.cpp|  6 ++-
 .../lib/Transforms/Vectorize/VPlanRecipes.cpp | 49 ---
 .../Transforms/Vectorize/VPlanTransforms.cpp  |  9 
 llvm/lib/Transforms/Vectorize/VPlanValue.h|  1 +
 .../LoopVectorize/cast-induction.ll   |  4 +-
 .../interleave-and-scalarize-only.ll  |  3 +-
 .../pr46525-expander-insertpoint.ll   |  2 +-
 8 files changed, 93 insertions(+), 11 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h 
b/llvm/lib/Transforms/Vectorize/VPlan.h
index 4b4f4911eb6415e..d5985224488 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -1945,6 +1945,36 @@ class VPReplicateRecipe : public VPRecipeWithIRFlags, 
public VPValue {
   }
 };
 
+/// VPUniformPerUFRecipe represents an instruction with Opcode that is uniform
+/// per UF, i.e. it generates a single scalar instance per UF.
+/// TODO: at the moment, only Cast opcodes are supported, extend to support
+///   missing opcodes to replace uniform part of VPReplicateRecipe.
+class VPUniformPerUFRecipe : public VPRecipeBase, public VPValue {
+  unsigned Opcode;
+
+  /// Result type for the cast.
+  Type *ResultTy;
+
+  Value *generate(VPTransformState &State, unsigned Part);
+
+public:
+  VPUniformPerUFRecipe(Instruction::CastOps Opcode, VPValue *Op, Type 
*ResultTy)
+  : VPRecipeBase(VPDef::VPUniformPerUFSC, {Op}), VPValue(this),
+Opcode(Opcode), ResultTy(ResultTy) {}
+
+  ~VPUniformPerUFRecipe() override = default;
+
+  VP_CLASSOF_IMPL(VPDef::VPWidenIntOrFpInductionSC)
+
+  void execute(VPTransformState &State) override;
+
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  /// Print the recipe.
+  void print(raw_ostream &O, const Twine &Indent,
+ VPSlotTracker &SlotTracker) const override;
+#endif
+};
+
 /// A recipe for generating conditional branches on the bits of a mask.
 class VPBranchOnMaskRecipe : public VPRecipeBase {
 public:
diff --git a/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp 
b/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp
index 97a8a1803bbf5a5..d71b07039944500 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp
@@ -230,7 +230,11 @@ Type *VPTypeAnalysis::inferScalarType(const VPValue *V) {
 return V->getUnderlyingValue()->getType();
   })
   .Case(
-  [](const VPWidenCastRecipe *R) { return R->getResultType(); });
+  [](const VPWidenCastRecipe *R) { return R->getResultType(); })
+  .Case([](const VPExpandSCEVRecipe *R) {
+return R->getSCEV()->getType();
+  });
+
   assert(ResultTy && "could not infer type for the given VPValue");
   CachedTypes[V] = ResultTy;
   return ResultTy;
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp 
b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index 1f844bce23102e2..423504e8f7e05e7 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -164,6 +164,8 @@ bool VPRecipeBase::mayHaveSideEffects() const {
 auto *R = cast(this);
 return R->getUnderlyingInstr()->mayHaveSideEffects();
   }
+  case VPUniformPerUFSC:
+return false;
   default:
 return true;
   }
@@ -1117,13 +1119,7 @@ void VPScalarIVStepsRecipe::execute(VPTransformState 
&State) {
 
   // Ensure step has the same type as that of scalar IV.
   Type *BaseIVTy = BaseIV->getType()->getScalarType();
-  if (BaseIVTy != Step->getType()) {
-// TODO: Also use VPDerivedIVRecipe when only the step needs truncating, to
-// avoid separate truncate here.
-assert(Step->getType()->isIntegerTy() &&
-   "Truncation requires an integer step");
-Step = State.Builder.CreateTrunc(Step, BaseIVTy);
-  }
+  assert(BaseIVTy == Step->getType());
 
   // We build scalar steps for both integer and floating-point induction
   // variables. Here, we determine the kind of arithmetic we will perform.
@@ -1469,6 +1465,45 @@ void VPReplicateRecipe::print(raw_ostream &O, const 
Twine &Indent,
 }
 #endif
 
+Value *VPUniformPerUFRecipe ::generate(VPTransform

[clang-tools-extra] [flang] [llvm] [libcxx] [clang] [libcxxabi] [compiler-rt] [libc] [lldb] [lld] [libclc] [VPlan] Add new VPScalarCastRecipe, use for IV & step trunc. (PR #78113)

2024-01-26 Thread Florian Hahn via cfe-commits


@@ -491,17 +491,38 @@ void VPlanTransforms::removeDeadRecipes(VPlan &Plan) {
 
 static VPValue *createScalarIVSteps(VPlan &Plan, const InductionDescriptor &ID,
 ScalarEvolution &SE, Instruction *TruncI,
-Type *IVTy, VPValue *StartV,
-VPValue *Step) {
+VPValue *StartV, VPValue *Step) {
   VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion()->getEntryBasicBlock();
   auto IP = HeaderVPBB->getFirstNonPhi();
   VPCanonicalIVPHIRecipe *CanonicalIV = Plan.getCanonicalIV();
-  Type *TruncTy = TruncI ? TruncI->getType() : IVTy;
-  VPValue *BaseIV = CanonicalIV;
-  if (!CanonicalIV->isCanonical(ID.getKind(), StartV, Step, TruncTy)) {
-BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step,
-   TruncI ? TruncI->getType() : nullptr);
-HeaderVPBB->insert(BaseIV->getDefiningRecipe(), IP);
+  VPSingleDefRecipe *BaseIV = CanonicalIV;
+  if (!CanonicalIV->isCanonical(ID.getKind(), StartV, Step)) {
+BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step);
+HeaderVPBB->insert(BaseIV, IP);
+  }
+
+  // Truncate base induction if needed.
+  VPTypeAnalysis TypeInfo(SE.getContext());
+  Type *ResultTy = TypeInfo.inferScalarType(BaseIV);
+  if (TruncI) {
+Type *TruncTy = TruncI->getType();
+assert(ResultTy->getScalarSizeInBits() > TruncTy->getScalarSizeInBits() &&
+   "Not truncating.");
+assert(ResultTy->isIntegerTy() && "Truncation requires an integer type");
+BaseIV = new VPScalarCastRecipe(Instruction::Trunc, BaseIV, TruncTy);

fhahn wrote:

Argh, sent the update too early (or too late in the day)! Should be fixed now., 
there were a number of test failures.

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


[flang] [compiler-rt] [lld] [llvm] [libc] [libclc] [libcxx] [clang] [libcxxabi] [lldb] [clang-tools-extra] [VPlan] Add new VPScalarCastRecipe, use for IV & step trunc. (PR #78113)

2024-01-26 Thread via cfe-commits

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

Looks good to me, thanks!
Adding a last minor nit.

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


[libc] [libclc] [flang] [lldb] [libcxx] [compiler-rt] [libcxxabi] [clang] [lld] [clang-tools-extra] [llvm] [VPlan] Add new VPScalarCastRecipe, use for IV & step trunc. (PR #78113)

2024-01-26 Thread via cfe-commits


@@ -491,17 +491,39 @@ void VPlanTransforms::removeDeadRecipes(VPlan &Plan) {
 
 static VPValue *createScalarIVSteps(VPlan &Plan, const InductionDescriptor &ID,
 ScalarEvolution &SE, Instruction *TruncI,
-Type *IVTy, VPValue *StartV,
-VPValue *Step) {
+VPValue *StartV, VPValue *Step) {
   VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion()->getEntryBasicBlock();
   auto IP = HeaderVPBB->getFirstNonPhi();
   VPCanonicalIVPHIRecipe *CanonicalIV = Plan.getCanonicalIV();
-  Type *TruncTy = TruncI ? TruncI->getType() : IVTy;
-  VPValue *BaseIV = CanonicalIV;
-  if (!CanonicalIV->isCanonical(ID.getKind(), StartV, Step, TruncTy)) {
-BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step,
-   TruncI ? TruncI->getType() : nullptr);
-HeaderVPBB->insert(BaseIV->getDefiningRecipe(), IP);
+  VPSingleDefRecipe *BaseIV = CanonicalIV;
+  if (!CanonicalIV->isCanonical(ID.getKind(), StartV, Step)) {
+BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step);
+HeaderVPBB->insert(BaseIV, IP);
+  }
+
+  // Truncate base induction if needed.
+  VPTypeAnalysis TypeInfo(SE.getContext());
+  Type *ResultTy = TypeInfo.inferScalarType(BaseIV);
+  if (TruncI) {
+Type *TruncTy = TruncI->getType();
+assert(ResultTy->getScalarSizeInBits() > TruncTy->getScalarSizeInBits() &&
+   "Not truncating.");
+assert(ResultTy->isIntegerTy() && "Truncation requires an integer type");
+BaseIV = new VPScalarCastRecipe(Instruction::Trunc, BaseIV, TruncTy);
+HeaderVPBB->insert(BaseIV, IP);
+ResultTy = TruncTy;
+  }
+
+  // Truncate step if needed.
+  Type *StepTy = TypeInfo.inferScalarType(Step);
+  if (ResultTy != StepTy) {
+assert(StepTy->getScalarSizeInBits() > ResultTy->getScalarSizeInBits() &&
+   "Not truncating.");
+assert(StepTy->isIntegerTy() && "Truncation requires an integer type");
+Step = new VPScalarCastRecipe(Instruction::Trunc, Step, ResultTy);
+auto *VecPreheader =
+cast(Plan.getVectorLoopRegion()->getSinglePredecessor());

ayalz wrote:

```suggestion
auto *VecPreheader =
cast(HeaderVPBB->getSingleHierarchicalPredecessor());
```
?

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


[libclc] [clang] [compiler-rt] [llvm] [flang] [libcxx] [lld] [clang-tools-extra] [lldb] [libcxxabi] [libc] [VPlan] Add new VPScalarCastRecipe, use for IV & step trunc. (PR #78113)

2024-01-26 Thread via cfe-commits

https://github.com/ayalz edited https://github.com/llvm/llvm-project/pull/78113
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [llvm] ValueTracking: Merge fcmpImpliesClass and fcmpToClassTest (PR #66522)

2024-01-26 Thread Matt Arsenault via cfe-commits

https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/66522

>From 076ab2374d84c4112e0bf3fb11ecda2f5774785e Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Mon, 11 Sep 2023 10:56:40 +0300
Subject: [PATCH 1/6] ValueTracking: Merge fcmpImpliesClass and fcmpToClassTest

---
 llvm/include/llvm/Analysis/ValueTracking.h |  13 +-
 llvm/lib/Analysis/ValueTracking.cpp| 250 -
 2 files changed, 147 insertions(+), 116 deletions(-)

diff --git a/llvm/include/llvm/Analysis/ValueTracking.h 
b/llvm/include/llvm/Analysis/ValueTracking.h
index c25dcad5e2242a7..ce2571cccf77cf1 100644
--- a/llvm/include/llvm/Analysis/ValueTracking.h
+++ b/llvm/include/llvm/Analysis/ValueTracking.h
@@ -214,8 +214,10 @@ std::pair 
fcmpToClassTest(CmpInst::Predicate Pred,
 const APFloat *ConstRHS,
 bool LookThroughSrc = true);
 
-/// Compute the possible floating-point classes that \p LHS could be based on 
an
-/// fcmp returning true. Returns { TestedValue, ClassesIfTrue, ClassesIfFalse }
+/// Compute the possible floating-point classes that \p LHS could be based on
+/// fcmp \Pred \p LHS, \p RHS.
+///
+/// Returns { TestedValue, ClassesIfTrue, ClassesIfFalse }
 ///
 /// If the compare returns an exact class test, ClassesIfTrue == 
~ClassesIfFalse
 ///
@@ -230,10 +232,13 @@ std::pair 
fcmpToClassTest(CmpInst::Predicate Pred,
 ///
 std::tuple
 fcmpImpliesClass(CmpInst::Predicate Pred, const Function &F, Value *LHS,
- const APFloat *ConstRHS, bool LookThroughSrc = true);
+ Value *RHS, bool LookThroughSrc = true);
 std::tuple
 fcmpImpliesClass(CmpInst::Predicate Pred, const Function &F, Value *LHS,
- Value *RHS, bool LookThroughSrc = true);
+ FPClassTest RHS, bool LookThroughSrc = true);
+std::tuple
+fcmpImpliesClass(CmpInst::Predicate Pred, const Function &F, Value *LHS,
+ const APFloat &RHS, bool LookThroughSrc = true);
 
 struct KnownFPClass {
   /// Floating-point classes the value could be one of.
diff --git a/llvm/lib/Analysis/ValueTracking.cpp 
b/llvm/lib/Analysis/ValueTracking.cpp
index 1f09d912f7339f7..d1c453807cea5ee 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -3948,67 +3948,104 @@ std::pair 
llvm::fcmpToClassTest(FCmpInst::Predicate Pred,
 std::pair
 llvm::fcmpToClassTest(FCmpInst::Predicate Pred, const Function &F, Value *LHS,
   const APFloat *ConstRHS, bool LookThroughSrc) {
+
+  auto [Src, ClassIfTrue, ClassIfFalse] =
+  fcmpImpliesClass(Pred, F, LHS, *ConstRHS, LookThroughSrc);
+  if (Src && ClassIfTrue == ~ClassIfFalse)
+return {Src, ClassIfTrue};
+  return {nullptr, fcAllFlags};
+}
+
+/// Return the return value for fcmpImpliesClass for a compare that produces an
+/// exact class test.
+static std::tuple exactClass(Value *V,
+FPClassTest M) 
{
+  return {V, M, ~M};
+}
+
+std::tuple
+llvm::fcmpImpliesClass(CmpInst::Predicate Pred, const Function &F, Value *LHS,
+   FPClassTest RHSClass, bool LookThroughSrc) {
+  assert(RHSClass != fcNone);
+
+  const FPClassTest OrigClass = RHSClass;
+
+  Value *Src = LHS;
+  const bool IsNegativeRHS = (RHSClass & fcNegative) == RHSClass;
+  const bool IsPositiveRHS = (RHSClass & fcPositive) == RHSClass;
+  const bool IsNaN = (RHSClass & ~fcNan) == fcNone;
+
+  if (IsNaN) {
+// fcmp o__ x, nan -> false
+// fcmp u__ x, nan -> true
+return exactClass(Src, CmpInst::isOrdered(Pred) ? fcNone : fcAllFlags);
+  }
+
   // fcmp ord x, zero|normal|subnormal|inf -> ~fcNan
-  if (Pred == FCmpInst::FCMP_ORD && !ConstRHS->isNaN())
-return {LHS, ~fcNan};
+  if (Pred == FCmpInst::FCMP_ORD)
+return {Src, ~fcNan, fcNan};
 
   // fcmp uno x, zero|normal|subnormal|inf -> fcNan
-  if (Pred == FCmpInst::FCMP_UNO && !ConstRHS->isNaN())
-return {LHS, fcNan};
+  if (Pred == FCmpInst::FCMP_UNO)
+return {Src, fcNan, ~fcNan};
+
+  const bool IsFabs = LookThroughSrc && match(LHS, m_FAbs(m_Value(Src)));
+  if (IsFabs)
+RHSClass = llvm::inverse_fabs(RHSClass);
 
-  if (ConstRHS->isZero()) {
+  const bool IsZero = (OrigClass & fcZero) == OrigClass;
+  if (IsZero) {
 // Compares with fcNone are only exactly equal to fcZero if input denormals
 // are not flushed.
 // TODO: Handle DAZ by expanding masks to cover subnormal cases.
 if (Pred != FCmpInst::FCMP_ORD && Pred != FCmpInst::FCMP_UNO &&
 !inputDenormalIsIEEE(F, LHS->getType()))
-  return {nullptr, fcAllFlags};
+  return {nullptr, fcAllFlags, fcAllFlags};
 
 switch (Pred) {
 case FCmpInst::FCMP_OEQ: // Match x == 0.0
-  return {LHS, fcZero};
+  return exactClass(Src, fcZero);
 case FCmpInst::FCMP_UEQ: // Match isnan(x) || (x == 0.0)
-  return {LHS, fcZero | fcNan};
+  return exactClass(Src, fcZero |

[clang] [clang-format] Add ShortReturnTypeColumn option. (PR #78011)

2024-01-26 Thread via cfe-commits

https://github.com/rmarker updated 
https://github.com/llvm/llvm-project/pull/78011

>From a1312a0a463bb946f336977b5b01ef7afbede678 Mon Sep 17 00:00:00 2001
From: rmarker 
Date: Thu, 11 Jan 2024 15:01:18 +1030
Subject: [PATCH 1/3] [clang-format] Add ShortReturnTypeColumn option.

---
 clang/docs/ClangFormatStyleOptions.rst | 13 +++
 clang/docs/ReleaseNotes.rst|  1 +
 clang/include/clang/Format/Format.h| 12 ++
 clang/lib/Format/ContinuationIndenter.cpp  |  3 +-
 clang/lib/Format/Format.cpp|  2 +
 clang/unittests/Format/ConfigParseTest.cpp |  1 +
 clang/unittests/Format/FormatTest.cpp  | 44 ++
 7 files changed, 75 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 4dc0de3a90f2650..7836cc8f1c9bb5b 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4999,6 +4999,19 @@ the configuration (without a prefix: ``Auto``).
int bar;   int bar;
  } // namespace b   } // namespace b
 
+.. _ShortReturnTypeColumn:
+
+**ShortReturnTypeColumn** (``Unsigned``) :versionbadge:`clang-format 19` 
:ref:`¶ `
+  When ``AlwaysBreakAfterReturnType`` is ``None``, line breaks are prevented
+  after short return types. This configures the column limit for a type
+  to be regarded as short.
+
+
+  .. note::
+
+   This isn't the length of the type itself, but the column where it
+   finishes. I.e. it includes indentation, etc.
+
 .. _SkipMacroDefinitionBody:
 
 **SkipMacroDefinitionBody** (``Boolean``) :versionbadge:`clang-format 18` 
:ref:`¶ `
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5330cd9caad8011..669b420fe21ec15 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -184,6 +184,7 @@ AST Matchers
 
 clang-format
 
+- Add ``ShortReturnTypeColumn`` option.
 
 libclang
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index bc9eecd42f9ebfd..7fd574c98a3944f 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3932,6 +3932,17 @@ struct FormatStyle {
   /// \version 13
   unsigned ShortNamespaceLines;
 
+  /// When ``AlwaysBreakAfterReturnType`` is ``None``, line breaks are 
prevented
+  /// after short return types. This configures the column limit for a type
+  /// to be regarded as short.
+  ///
+  /// \note
+  ///  This isn't the length of the type itself, but the column where it
+  ///  finishes. I.e. it includes indentation, etc.
+  /// \endnote
+  /// \version 19
+  unsigned ShortReturnTypeColumn;
+
   /// Do not format macro definition body.
   /// \version 18
   bool SkipMacroDefinitionBody;
@@ -4899,6 +4910,7 @@ struct FormatStyle {
RequiresExpressionIndentation == R.RequiresExpressionIndentation &&
SeparateDefinitionBlocks == R.SeparateDefinitionBlocks &&
ShortNamespaceLines == R.ShortNamespaceLines &&
+   ShortReturnTypeColumn == R.ShortReturnTypeColumn &&
SkipMacroDefinitionBody == R.SkipMacroDefinitionBody &&
SortIncludes == R.SortIncludes &&
SortJavaStaticImport == R.SortJavaStaticImport &&
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index a3eb9138b218335..3f9c0cc815745c3 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -328,7 +328,8 @@ bool ContinuationIndenter::canBreak(const LineState &State) 
{
 
   // Don't break after very short return types (e.g. "void") as that is often
   // unexpected.
-  if (Current.is(TT_FunctionDeclarationName) && State.Column < 6) {
+  if (Current.is(TT_FunctionDeclarationName) &&
+  State.Column <= Style.ShortReturnTypeColumn) {
 if (Style.AlwaysBreakAfterReturnType == FormatStyle::RTBS_None)
   return false;
   }
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index ff326dc784783b2..35478fac7b49629 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1085,6 +1085,7 @@ template <> struct MappingTraits {
Style.RequiresExpressionIndentation);
 IO.mapOptional("SeparateDefinitionBlocks", Style.SeparateDefinitionBlocks);
 IO.mapOptional("ShortNamespaceLines", Style.ShortNamespaceLines);
+IO.mapOptional("ShortReturnTypeColumn", Style.ShortReturnTypeColumn);
 IO.mapOptional("SkipMacroDefinitionBody", Style.SkipMacroDefinitionBody);
 IO.mapOptional("SortIncludes", Style.SortIncludes);
 IO.mapOptional("SortJavaStaticImport", Style.SortJavaStaticImport);
@@ -1557,6 +1558,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.RequiresExpressionIndentation = FormatStyle::REI_OuterScope;
   LLVMStyle.SeparateDefinitionBlocks = FormatStyle::SDS_Leave;
   LLVMStyle.ShortNamespaceLi

[clang] [clang-format] Add ShortReturnTypeColumn option. (PR #78011)

2024-01-26 Thread via cfe-commits

rmarker wrote:

Reworked this PR with a new approach, as discussed in #78010.

`ShortReturnTypeColumn` has been replaced with a new enum option 
`RTBS_AllowShortType` for `AlwaysBreakAfterReturnType `.
Also, the short return type behaviour has been updated to ignore the leading 
indentation on the line.

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


[compiler-rt] [flang] [lld] [mlir] [libc] [libcxxabi] [libcxx] [lldb] [clang] [openmp] [llvm] [libclc] [clang-tools-extra] [VPlan] Add new VPScalarCastRecipe, use for IV & step trunc. (PR #78113)

2024-01-26 Thread Florian Hahn via cfe-commits

https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/78113

>From 36b085f21b76d7bf7c9965a86a09d1cef4fe9329 Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Sun, 14 Jan 2024 14:13:08 +
Subject: [PATCH 1/9] [VPlan] Add new VPUniformPerUFRecipe, use for step
 truncation.

Add a new recipe to model uniform-per-UF instructions, without relying
on an underlying instruction. Initially, it supports uniform cast-ops
and is therefore storing the result type.

Not relying on an underlying instruction (like the current
VPReplicateRecipe) allows to create instances without a corresponding
instruction.

In the future, to plan is to extend this recipe to handle all opcodes
needed to replace the uniform part of VPReplicateRecipe.
---
 llvm/lib/Transforms/Vectorize/VPlan.h | 30 
 .../Transforms/Vectorize/VPlanAnalysis.cpp|  6 ++-
 .../lib/Transforms/Vectorize/VPlanRecipes.cpp | 49 ---
 .../Transforms/Vectorize/VPlanTransforms.cpp  |  9 
 llvm/lib/Transforms/Vectorize/VPlanValue.h|  1 +
 .../LoopVectorize/cast-induction.ll   |  4 +-
 .../interleave-and-scalarize-only.ll  |  3 +-
 .../pr46525-expander-insertpoint.ll   |  2 +-
 8 files changed, 93 insertions(+), 11 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h 
b/llvm/lib/Transforms/Vectorize/VPlan.h
index 4b4f4911eb6415e..d5985224488 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -1945,6 +1945,36 @@ class VPReplicateRecipe : public VPRecipeWithIRFlags, 
public VPValue {
   }
 };
 
+/// VPUniformPerUFRecipe represents an instruction with Opcode that is uniform
+/// per UF, i.e. it generates a single scalar instance per UF.
+/// TODO: at the moment, only Cast opcodes are supported, extend to support
+///   missing opcodes to replace uniform part of VPReplicateRecipe.
+class VPUniformPerUFRecipe : public VPRecipeBase, public VPValue {
+  unsigned Opcode;
+
+  /// Result type for the cast.
+  Type *ResultTy;
+
+  Value *generate(VPTransformState &State, unsigned Part);
+
+public:
+  VPUniformPerUFRecipe(Instruction::CastOps Opcode, VPValue *Op, Type 
*ResultTy)
+  : VPRecipeBase(VPDef::VPUniformPerUFSC, {Op}), VPValue(this),
+Opcode(Opcode), ResultTy(ResultTy) {}
+
+  ~VPUniformPerUFRecipe() override = default;
+
+  VP_CLASSOF_IMPL(VPDef::VPWidenIntOrFpInductionSC)
+
+  void execute(VPTransformState &State) override;
+
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  /// Print the recipe.
+  void print(raw_ostream &O, const Twine &Indent,
+ VPSlotTracker &SlotTracker) const override;
+#endif
+};
+
 /// A recipe for generating conditional branches on the bits of a mask.
 class VPBranchOnMaskRecipe : public VPRecipeBase {
 public:
diff --git a/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp 
b/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp
index 97a8a1803bbf5a5..d71b07039944500 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp
@@ -230,7 +230,11 @@ Type *VPTypeAnalysis::inferScalarType(const VPValue *V) {
 return V->getUnderlyingValue()->getType();
   })
   .Case(
-  [](const VPWidenCastRecipe *R) { return R->getResultType(); });
+  [](const VPWidenCastRecipe *R) { return R->getResultType(); })
+  .Case([](const VPExpandSCEVRecipe *R) {
+return R->getSCEV()->getType();
+  });
+
   assert(ResultTy && "could not infer type for the given VPValue");
   CachedTypes[V] = ResultTy;
   return ResultTy;
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp 
b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index 1f844bce23102e2..423504e8f7e05e7 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -164,6 +164,8 @@ bool VPRecipeBase::mayHaveSideEffects() const {
 auto *R = cast(this);
 return R->getUnderlyingInstr()->mayHaveSideEffects();
   }
+  case VPUniformPerUFSC:
+return false;
   default:
 return true;
   }
@@ -1117,13 +1119,7 @@ void VPScalarIVStepsRecipe::execute(VPTransformState 
&State) {
 
   // Ensure step has the same type as that of scalar IV.
   Type *BaseIVTy = BaseIV->getType()->getScalarType();
-  if (BaseIVTy != Step->getType()) {
-// TODO: Also use VPDerivedIVRecipe when only the step needs truncating, to
-// avoid separate truncate here.
-assert(Step->getType()->isIntegerTy() &&
-   "Truncation requires an integer step");
-Step = State.Builder.CreateTrunc(Step, BaseIVTy);
-  }
+  assert(BaseIVTy == Step->getType());
 
   // We build scalar steps for both integer and floating-point induction
   // variables. Here, we determine the kind of arithmetic we will perform.
@@ -1469,6 +1465,45 @@ void VPReplicateRecipe::print(raw_ostream &O, const 
Twine &Indent,
 }
 #endif
 
+Value *VPUniformPerUFRecipe ::generate(VPTransform

[clang] [clang-format] Add AllowShortType option for AlwaysBreakAfterReturnType. (PR #78011)

2024-01-26 Thread via cfe-commits

https://github.com/rmarker edited 
https://github.com/llvm/llvm-project/pull/78011
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [llvm] [clang] reject to capture variable in `RequiresExprBodyDecl` (PR #78598)

2024-01-26 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/78598

>From 8fa3dc43e770025308da47f6aff309fa58c47fc3 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Thu, 18 Jan 2024 23:12:23 +0800
Subject: [PATCH 1/3] [clang] reject to capture variable in
 `RequiresExprBodyDecl`

Expression in `RequiresExprBodyDecl` is resolved as constants and should not be 
captured.
Fixes: #69307, #76593.
---
 clang/lib/Sema/SemaExpr.cpp   | 21 ++--
 ...uires-expression-with-capture-variable.cpp | 25 +++
 2 files changed, 38 insertions(+), 8 deletions(-)
 create mode 100644 
clang/test/SemaCXX/requires-expression-with-capture-variable.cpp

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 6413a48f809ac9..580e759f634956 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -19704,6 +19704,12 @@ static void buildLambdaCaptureFixit(Sema &Sema, 
LambdaScopeInfo *LSI,
   }
 }
 
+static DeclContext *ignoreReuquiresBodyDecl(DeclContext *DC) {
+  if (isa_and_present(DC))
+return DC->getParent();
+  return DC;
+}
+
 bool Sema::tryCaptureVariable(
 ValueDecl *Var, SourceLocation ExprLoc, TryCaptureKind Kind,
 SourceLocation EllipsisLoc, bool BuildAndDiagnose, QualType &CaptureType,
@@ -19711,15 +19717,15 @@ bool Sema::tryCaptureVariable(
   // An init-capture is notionally from the context surrounding its
   // declaration, but its parent DC is the lambda class.
   DeclContext *VarDC = Var->getDeclContext();
-  DeclContext *DC = CurContext;
-
   // tryCaptureVariable is called every time a DeclRef is formed,
   // it can therefore have non-negigible impact on performances.
   // For local variables and when there is no capturing scope,
   // we can bailout early.
-  if (CapturingFunctionScopes == 0 && (!BuildAndDiagnose || VarDC == DC))
+  if (CapturingFunctionScopes == 0 && (!BuildAndDiagnose || VarDC == 
CurContext))
 return true;
 
+  DeclContext *DC = ignoreReuquiresBodyDecl(CurContext);
+
   const auto *VD = dyn_cast(Var);
   if (VD) {
 if (VD->isInitCapture())
@@ -19789,11 +19795,10 @@ bool Sema::tryCaptureVariable(
 
 // Only block literals, captured statements, and lambda expressions can
 // capture; other scopes don't work.
-DeclContext *ParentDC =
-!IsInScopeDeclarationContext
-? DC->getParent()
-: getParentOfCapturingContextOrNull(DC, Var, ExprLoc,
-BuildAndDiagnose, *this);
+DeclContext *ParentDC = IsInScopeDeclarationContext
+? getParentOfCapturingContextOrNull(
+  DC, Var, ExprLoc, BuildAndDiagnose, 
*this)
+: DC->getParent();
 // We need to check for the parent *first* because, if we *have*
 // private-captured a global variable, we need to recursively capture it in
 // intermediate blocks, lambdas, etc.
diff --git a/clang/test/SemaCXX/requires-expression-with-capture-variable.cpp 
b/clang/test/SemaCXX/requires-expression-with-capture-variable.cpp
new file mode 100644
index 00..d01a54133f6c39
--- /dev/null
+++ b/clang/test/SemaCXX/requires-expression-with-capture-variable.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang -fsyntax-only -std=c++20 -Xclang -verify %s
+
+// expected-no-diagnostics
+
+auto GH69307_Func_1() {
+  constexpr auto b = 1;
+  return [&](auto c) -> int
+   requires requires { b + c; }
+  { return 1; };
+};
+auto GH69307_Func_Ret = GH69307_Func_1()(1);
+
+auto GH69307_Lambda_1 = []() {
+  return [&](auto c) -> int
+   requires requires { c; }
+  { return 1; };
+};
+auto GH69307_Lambda_1_Ret = GH69307_Lambda_1()(1);
+
+auto GH69307_Lambda_2 = [](auto c) {
+  return [&]() -> int
+   requires requires { c; }
+  { return 1; };
+};
+auto GH69307_Lambda_2_Ret = GH69307_Lambda_2(1)();

>From a99f16ff51702ff249cdf8a47de0cf24a08f694a Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sat, 20 Jan 2024 13:40:12 +0800
Subject: [PATCH 2/3] another test

---
 clang/test/SemaCXX/warn-unused-lambda-capture-cxx20.cpp | 7 +++
 clang/test/SemaCXX/warn-unused-lambda-capture.cpp   | 4 
 2 files changed, 11 insertions(+)
 create mode 100644 clang/test/SemaCXX/warn-unused-lambda-capture-cxx20.cpp

diff --git a/clang/test/SemaCXX/warn-unused-lambda-capture-cxx20.cpp 
b/clang/test/SemaCXX/warn-unused-lambda-capture-cxx20.cpp
new file mode 100644
index 00..b787edb188ed8b
--- /dev/null
+++ b/clang/test/SemaCXX/warn-unused-lambda-capture-cxx20.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -fsyntax-only -Wunused-lambda-capture 
-Wused-but-marked-unused -Wno-uninitialized -verify -std=c++20 %s
+
+void test() {
+  int i;
+  auto explicit_by_value_unused_requires = [i] (auto) requires requires { i; } 
{}; // expected-warning{{lambda capture 'i' is not required to be captured for 
this use}}
+  explicit_by_value_unused_requires(1);
+}
diff --git a/

[compiler-rt] [flang] [lld] [mlir] [libc] [libcxxabi] [libcxx] [lldb] [clang] [openmp] [llvm] [libclc] [clang-tools-extra] [VPlan] Add new VPScalarCastRecipe, use for IV & step trunc. (PR #78113)

2024-01-26 Thread Florian Hahn via cfe-commits

https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/78113

>From 36b085f21b76d7bf7c9965a86a09d1cef4fe9329 Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Sun, 14 Jan 2024 14:13:08 +
Subject: [PATCH 01/10] [VPlan] Add new VPUniformPerUFRecipe, use for step
 truncation.

Add a new recipe to model uniform-per-UF instructions, without relying
on an underlying instruction. Initially, it supports uniform cast-ops
and is therefore storing the result type.

Not relying on an underlying instruction (like the current
VPReplicateRecipe) allows to create instances without a corresponding
instruction.

In the future, to plan is to extend this recipe to handle all opcodes
needed to replace the uniform part of VPReplicateRecipe.
---
 llvm/lib/Transforms/Vectorize/VPlan.h | 30 
 .../Transforms/Vectorize/VPlanAnalysis.cpp|  6 ++-
 .../lib/Transforms/Vectorize/VPlanRecipes.cpp | 49 ---
 .../Transforms/Vectorize/VPlanTransforms.cpp  |  9 
 llvm/lib/Transforms/Vectorize/VPlanValue.h|  1 +
 .../LoopVectorize/cast-induction.ll   |  4 +-
 .../interleave-and-scalarize-only.ll  |  3 +-
 .../pr46525-expander-insertpoint.ll   |  2 +-
 8 files changed, 93 insertions(+), 11 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h 
b/llvm/lib/Transforms/Vectorize/VPlan.h
index 4b4f4911eb6415..d598522448 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -1945,6 +1945,36 @@ class VPReplicateRecipe : public VPRecipeWithIRFlags, 
public VPValue {
   }
 };
 
+/// VPUniformPerUFRecipe represents an instruction with Opcode that is uniform
+/// per UF, i.e. it generates a single scalar instance per UF.
+/// TODO: at the moment, only Cast opcodes are supported, extend to support
+///   missing opcodes to replace uniform part of VPReplicateRecipe.
+class VPUniformPerUFRecipe : public VPRecipeBase, public VPValue {
+  unsigned Opcode;
+
+  /// Result type for the cast.
+  Type *ResultTy;
+
+  Value *generate(VPTransformState &State, unsigned Part);
+
+public:
+  VPUniformPerUFRecipe(Instruction::CastOps Opcode, VPValue *Op, Type 
*ResultTy)
+  : VPRecipeBase(VPDef::VPUniformPerUFSC, {Op}), VPValue(this),
+Opcode(Opcode), ResultTy(ResultTy) {}
+
+  ~VPUniformPerUFRecipe() override = default;
+
+  VP_CLASSOF_IMPL(VPDef::VPWidenIntOrFpInductionSC)
+
+  void execute(VPTransformState &State) override;
+
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  /// Print the recipe.
+  void print(raw_ostream &O, const Twine &Indent,
+ VPSlotTracker &SlotTracker) const override;
+#endif
+};
+
 /// A recipe for generating conditional branches on the bits of a mask.
 class VPBranchOnMaskRecipe : public VPRecipeBase {
 public:
diff --git a/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp 
b/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp
index 97a8a1803bbf5a..d71b0703994450 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp
@@ -230,7 +230,11 @@ Type *VPTypeAnalysis::inferScalarType(const VPValue *V) {
 return V->getUnderlyingValue()->getType();
   })
   .Case(
-  [](const VPWidenCastRecipe *R) { return R->getResultType(); });
+  [](const VPWidenCastRecipe *R) { return R->getResultType(); })
+  .Case([](const VPExpandSCEVRecipe *R) {
+return R->getSCEV()->getType();
+  });
+
   assert(ResultTy && "could not infer type for the given VPValue");
   CachedTypes[V] = ResultTy;
   return ResultTy;
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp 
b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index 1f844bce23102e..423504e8f7e05e 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -164,6 +164,8 @@ bool VPRecipeBase::mayHaveSideEffects() const {
 auto *R = cast(this);
 return R->getUnderlyingInstr()->mayHaveSideEffects();
   }
+  case VPUniformPerUFSC:
+return false;
   default:
 return true;
   }
@@ -1117,13 +1119,7 @@ void VPScalarIVStepsRecipe::execute(VPTransformState 
&State) {
 
   // Ensure step has the same type as that of scalar IV.
   Type *BaseIVTy = BaseIV->getType()->getScalarType();
-  if (BaseIVTy != Step->getType()) {
-// TODO: Also use VPDerivedIVRecipe when only the step needs truncating, to
-// avoid separate truncate here.
-assert(Step->getType()->isIntegerTy() &&
-   "Truncation requires an integer step");
-Step = State.Builder.CreateTrunc(Step, BaseIVTy);
-  }
+  assert(BaseIVTy == Step->getType());
 
   // We build scalar steps for both integer and floating-point induction
   // variables. Here, we determine the kind of arithmetic we will perform.
@@ -1469,6 +1465,45 @@ void VPReplicateRecipe::print(raw_ostream &O, const 
Twine &Indent,
 }
 #endif
 
+Value *VPUniformPerUFRecipe ::generate(VPTransformStat

[clang] [clang-format] Add AllowShortType option for AlwaysBreakAfterReturnType. (PR #78011)

2024-01-26 Thread via cfe-commits

https://github.com/rmarker edited 
https://github.com/llvm/llvm-project/pull/78011
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[compiler-rt] [flang] [lld] [libc] [libcxx] [lldb] [clang] [llvm] [clang-tools-extra] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-26 Thread Florian Hahn via cfe-commits

https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/73158

>From 13a26e8e7440c3b501730b22588af393a3e543cd Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Thu, 6 Jul 2023 08:07:45 +0100
Subject: [PATCH 1/3] [VPlan] Implement cloning of VPlans.

This patch implements cloning for VPlans and recipes. Cloning is used in
the epilogue vectorization path, to clone the VPlan for the main vector
loop. This means we won't re-use a VPlan when executing the VPlan for
the epilogue vector loop, which in turn will enable us to perform
optimizations based on UF & VF.
---
 .../Transforms/Vectorize/LoopVectorize.cpp|   2 +-
 llvm/lib/Transforms/Vectorize/VPlan.cpp   | 124 
 llvm/lib/Transforms/Vectorize/VPlan.h | 182 ++
 .../Transforms/Vectorize/VPlanTest.cpp|   2 +
 4 files changed, 309 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp 
b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 10c068e3b5895c2..9ffd44d59ffc6de 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -10078,7 +10078,7 @@ bool LoopVectorizePass::processLoop(Loop *L) {
 EpilogueVectorizerMainLoop MainILV(L, PSE, LI, DT, TLI, TTI, AC, ORE,
EPI, &LVL, &CM, BFI, PSI, Checks);
 
-VPlan &BestMainPlan = LVP.getBestPlanFor(EPI.MainLoopVF);
+VPlan &BestMainPlan = *LVP.getBestPlanFor(EPI.MainLoopVF).clone();
 const auto &[ExpandedSCEVs, ReductionResumeValues] = LVP.executePlan(
 EPI.MainLoopVF, EPI.MainLoopUF, BestMainPlan, MainILV, DT, true);
 ++LoopsVectorized;
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp 
b/llvm/lib/Transforms/Vectorize/VPlan.cpp
index b6e56c47c227f77..99b2a3bd59a64df 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -615,6 +615,18 @@ void VPBasicBlock::print(raw_ostream &O, const Twine 
&Indent,
 }
 #endif
 
+VPBlockBase *VPRegionBlock::clone() {
+  DenseMap Old2New;
+  DenseMap Old2NewVPValues;
+  VPBlockBase *NewEntry =
+  VPBlockUtils::cloneCFG(Entry, Old2New, Old2NewVPValues);
+  auto *NewR =
+  new VPRegionBlock(NewEntry, Old2New[Exiting], getName(), isReplicator());
+  for (VPBlockBase *Block : vp_depth_first_shallow(NewEntry))
+Block->setParent(NewR);
+  return NewR;
+}
+
 void VPRegionBlock::dropAllReferences(VPValue *NewValue) {
   for (VPBlockBase *Block : vp_depth_first_shallow(Entry))
 // Drop all references in VPBasicBlocks and replace all uses with
@@ -982,6 +994,65 @@ void VPlan::updateDominatorTree(DominatorTree *DT, 
BasicBlock *LoopHeaderBB,
   assert(DT->verify(DominatorTree::VerificationLevel::Fast));
 }
 
+static void remapVPValues(VPBasicBlock *OldBB, VPBasicBlock *NewBB,
+  DenseMap &Old2NewVPValues,
+  bool Full = false) {
+  for (const auto &[OldR, NewR] : zip(*OldBB, *NewBB)) {
+for (unsigned I = 0, E = NewR.getNumOperands(); I != E; ++I) {
+  VPValue *NewOp = Old2NewVPValues.lookup(OldR.getOperand(I));
+  if (!Full)
+continue;
+  NewR.setOperand(I, NewOp);
+}
+for (const auto &[OldV, NewV] :
+ zip(OldR.definedValues(), NewR.definedValues()))
+  Old2NewVPValues[OldV] = NewV;
+  }
+}
+
+VPlan *VPlan::clone() {
+  DenseMap Old2New;
+  DenseMap Old2NewVPValues;
+
+  auto *NewPlan = new VPlan();
+  SmallVector NewLiveIns;
+  for (VPValue *LI : VPLiveInsToFree) {
+VPValue *NewLI = new VPValue(LI->getLiveInIRValue());
+NewPlan->VPLiveInsToFree.push_back(NewLI);
+Old2NewVPValues[LI] = NewLI;
+  }
+
+  Old2NewVPValues[&VectorTripCount] = &NewPlan->VectorTripCount;
+  Old2NewVPValues[&VFxUF] = &NewPlan->VFxUF;
+  if (BackedgeTakenCount) {
+Old2NewVPValues[BackedgeTakenCount] = new VPValue();
+NewPlan->BackedgeTakenCount = Old2NewVPValues[BackedgeTakenCount];
+  }
+
+  auto NewPH = cast(Preheader->clone());
+  remapVPValues(cast(Preheader), cast(NewPH),
+Old2NewVPValues, /*Full*/ true);
+  VPValue *NewTC = Old2NewVPValues.lookup(TripCount);
+  if (!NewTC)
+Old2NewVPValues[TripCount] = new VPValue(TripCount->getLiveInIRValue());
+  NewPlan->TripCount = Old2NewVPValues[TripCount];
+
+  auto *NewEntry = cast(VPBlockUtils::cloneCFG(
+  getEntry(), Old2New, Old2NewVPValues, /*FullRemapping*/ true));
+
+  NewPlan->Entry = NewEntry;
+  NewPlan->Preheader = NewPH;
+  NewEntry->setPlan(NewPlan);
+  NewPH->setPlan(NewPlan);
+  NewPlan->VFs = VFs;
+  NewPlan->UFs = UFs;
+  NewPlan->Name = Name;
+
+  for (const auto &[_, LO] : LiveOuts)
+NewPlan->addLiveOut(LO->getPhi(), Old2NewVPValues[LO->getOperand(0)]);
+  return NewPlan;
+}
+
 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 
 Twine VPlanPrinter::getUID(const VPBlockBase *Block) {
@@ -1200,6 +1271,59 @@ void VPUser::printOperands(raw_ostream &O, VPSlotTracker 
&SlotTracker) const {
 }
 #end

[openmp] [libclc] [clang] [compiler-rt] [llvm] [flang] [libcxx] [lld] [clang-tools-extra] [mlir] [lldb] [libcxxabi] [libc] [VPlan] Add new VPScalarCastRecipe, use for IV & step trunc. (PR #78113)

2024-01-26 Thread Florian Hahn via cfe-commits


@@ -491,17 +491,39 @@ void VPlanTransforms::removeDeadRecipes(VPlan &Plan) {
 
 static VPValue *createScalarIVSteps(VPlan &Plan, const InductionDescriptor &ID,
 ScalarEvolution &SE, Instruction *TruncI,
-Type *IVTy, VPValue *StartV,
-VPValue *Step) {
+VPValue *StartV, VPValue *Step) {
   VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion()->getEntryBasicBlock();
   auto IP = HeaderVPBB->getFirstNonPhi();
   VPCanonicalIVPHIRecipe *CanonicalIV = Plan.getCanonicalIV();
-  Type *TruncTy = TruncI ? TruncI->getType() : IVTy;
-  VPValue *BaseIV = CanonicalIV;
-  if (!CanonicalIV->isCanonical(ID.getKind(), StartV, Step, TruncTy)) {
-BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step,
-   TruncI ? TruncI->getType() : nullptr);
-HeaderVPBB->insert(BaseIV->getDefiningRecipe(), IP);
+  VPSingleDefRecipe *BaseIV = CanonicalIV;
+  if (!CanonicalIV->isCanonical(ID.getKind(), StartV, Step)) {
+BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step);
+HeaderVPBB->insert(BaseIV, IP);
+  }
+
+  // Truncate base induction if needed.
+  VPTypeAnalysis TypeInfo(SE.getContext());
+  Type *ResultTy = TypeInfo.inferScalarType(BaseIV);
+  if (TruncI) {
+Type *TruncTy = TruncI->getType();
+assert(ResultTy->getScalarSizeInBits() > TruncTy->getScalarSizeInBits() &&
+   "Not truncating.");
+assert(ResultTy->isIntegerTy() && "Truncation requires an integer type");
+BaseIV = new VPScalarCastRecipe(Instruction::Trunc, BaseIV, TruncTy);
+HeaderVPBB->insert(BaseIV, IP);
+ResultTy = TruncTy;
+  }
+
+  // Truncate step if needed.
+  Type *StepTy = TypeInfo.inferScalarType(Step);
+  if (ResultTy != StepTy) {
+assert(StepTy->getScalarSizeInBits() > ResultTy->getScalarSizeInBits() &&
+   "Not truncating.");
+assert(StepTy->isIntegerTy() && "Truncation requires an integer type");
+Step = new VPScalarCastRecipe(Instruction::Trunc, Step, ResultTy);
+auto *VecPreheader =
+cast(Plan.getVectorLoopRegion()->getSinglePredecessor());

fhahn wrote:

Done, thanks!

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


[clang] [clang] Only set the trailing bytes to zero when filling a partially … (PR #79502)

2024-01-26 Thread via cfe-commits

https://github.com/serge-sans-paille updated 
https://github.com/llvm/llvm-project/pull/79502

>From 1ca9d2d7697528b1a126cc95a2fb7a9e5bb8669a Mon Sep 17 00:00:00 2001
From: serge-sans-paille 
Date: Thu, 25 Jan 2024 22:12:55 +0100
Subject: [PATCH] [clang] Only set the trailing bytes to zero when filling a
 partially initialized array

Fix #79500
---
 clang/lib/CodeGen/CGDecl.cpp  | 109 +-
 clang/test/CodeGen/array-init.c   |  50 
 .../test/CodeGenCXX/trivial-auto-var-init.cpp |   6 +-
 .../test/CodeGenOpenCL/partial_initializer.cl |   3 +-
 4 files changed, 163 insertions(+), 5 deletions(-)

diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index bbe14ef4c17244f..724dcf6464aef10 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -905,6 +905,98 @@ void CodeGenFunction::EmitScalarInit(const Expr *init, 
const ValueDecl *D,
   EmitStoreOfScalar(value, lvalue, /* isInitialization */ true);
 }
 
+static bool isNullOrUndef(llvm::Constant *C) {
+  return C->isNullValue() || isa(C) ||
+ isa(C) || isa(C);
+}
+
+static size_t CountLeadingNonNullBytes(const llvm::DataLayout &DL,
+   llvm::Constant *Init) {
+  // Zero and Undef never requires any extra stores.
+  if (isNullOrUndef(Init))
+return 0u;
+
+  if (isa(Init) || isa(Init) ||
+  isa(Init) || isa(Init) ||
+  isa(Init))
+return DL.getTypeAllocSize(Init->getType());
+
+  // For array, consider each element independently
+  if (auto *CA = dyn_cast(Init)) {
+
+llvm::ArrayType *CAT = CA->getType();
+uint64_t NumElements = CAT->getNumElements();
+uint64_t ElementByteCount = DL.getTypeAllocSize(CAT->getElementType());
+
+unsigned LeadingNonNullElementsCount = 0;
+for (; LeadingNonNullElementsCount != NumElements;
+ ++LeadingNonNullElementsCount) {
+  auto *Elt =
+  cast(Init->getOperand(LeadingNonNullElementsCount));
+  if (isNullOrUndef(Elt))
+break;
+}
+
+unsigned TrailingNonNullBytes = 0;
+if (LeadingNonNullElementsCount != 0) {
+  LeadingNonNullElementsCount -= 1;
+  TrailingNonNullBytes = CountLeadingNonNullBytes(
+  DL,
+  cast(Init->getOperand(LeadingNonNullElementsCount)));
+}
+
+return LeadingNonNullElementsCount * ElementByteCount +
+   TrailingNonNullBytes;
+;
+  }
+
+  // For records, per field
+  if (auto *CS = dyn_cast(Init)) {
+llvm::StructType *CST = CS->getType();
+const llvm::StructLayout *SL = DL.getStructLayout(CST);
+
+uint64_t NumElements = CST->getNumElements();
+uint64_t LeadingNonNullFieldsCount = 0;
+
+for (; LeadingNonNullFieldsCount != NumElements;
+ ++LeadingNonNullFieldsCount) {
+  auto *Elt =
+  cast(Init->getOperand(LeadingNonNullFieldsCount));
+  if (isNullOrUndef(Elt))
+break;
+}
+
+unsigned TrailingNonNullBytes = 0;
+if (LeadingNonNullFieldsCount != 0) {
+  LeadingNonNullFieldsCount -= 1;
+  TrailingNonNullBytes = CountLeadingNonNullBytes(
+  DL,
+  cast(Init->getOperand(LeadingNonNullFieldsCount)));
+}
+
+return SL->getElementOffset(LeadingNonNullFieldsCount) +
+   TrailingNonNullBytes;
+  }
+
+  if (llvm::ConstantDataSequential *CDS =
+  dyn_cast(Init)) {
+size_t LeadingNonNullElementCount = 0;
+uint64_t ElementByteCount = DL.getTypeAllocSize(CDS->getElementType());
+for (unsigned NumElements = CDS->getNumElements();
+ LeadingNonNullElementCount != NumElements;
+ ++LeadingNonNullElementCount) {
+  llvm::Constant *Elt =
+  CDS->getElementAsConstant(LeadingNonNullElementCount);
+  if (isNullOrUndef(Elt))
+break;
+}
+return LeadingNonNullElementCount * ElementByteCount;
+  }
+
+  // Anything else is hard and scary.
+  return 0;
+}
+
 /// Decide whether we can emit the non-zero parts of the specified initializer
 /// with equal or fewer than NumStores scalar stores.
 static bool canEmitInitWithFewStoresAfterBZero(llvm::Constant *Init,
@@ -1209,8 +1301,21 @@ static void emitStoresForConstant(CodeGenModule &CGM, 
const VarDecl &D,
   // If the initializer is all or mostly the same, codegen with bzero / memset
   // then do a few stores afterward.
   if (shouldUseBZeroPlusStoresToInitialize(constant, ConstantSize)) {
-auto *I = Builder.CreateMemSet(Loc, llvm::ConstantInt::get(CGM.Int8Ty, 0),
-   SizeVal, isVolatile);
+size_t LeadingNonNullBytes =
+CountLeadingNonNullBytes(CGM.getDataLayout(), constant);
+
+llvm::Constant *Z8 = llvm::ConstantInt::get(CGM.Int8Ty, 0);
+Address AdjustedLoc =
+LeadingNonNullBytes ? Builder.CreateConstInBoundsByteGEP(
+  Loc.withElementType(CGM.Int8Ty),
+  CharUnits::fromQuantity(LeadingNonNullBytes))
+: Loc;
+auto *I 

[clang] [lldb] [clang-tools-extra] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-26 Thread Balazs Benics via cfe-commits

steakhal wrote:

FYI this caused a crash in the Static Analyzer, tracked here: #79575
We will (well, probably I will) look into this to see what could be done about 
it to workaround/fix the crash for clang-18.

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


[libcxx] [clang] [mlir] [llvm] [clang-tools-extra] [openmp] [flang] [libclc] [lld] [lldb] [libcxxabi] [compiler-rt] [libc] [VPlan] Add new VPScalarCastRecipe, use for IV & step trunc. (PR #78113)

2024-01-26 Thread Florian Hahn via cfe-commits

https://github.com/fhahn closed https://github.com/llvm/llvm-project/pull/78113
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] [clang] [llvm] [clang-tools-extra] [flang] [lld] [lldb] [compiler-rt] [libc] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-26 Thread Florian Hahn via cfe-commits

https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/73158

>From 13a26e8e7440c3b501730b22588af393a3e543cd Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Thu, 6 Jul 2023 08:07:45 +0100
Subject: [PATCH 1/4] [VPlan] Implement cloning of VPlans.

This patch implements cloning for VPlans and recipes. Cloning is used in
the epilogue vectorization path, to clone the VPlan for the main vector
loop. This means we won't re-use a VPlan when executing the VPlan for
the epilogue vector loop, which in turn will enable us to perform
optimizations based on UF & VF.
---
 .../Transforms/Vectorize/LoopVectorize.cpp|   2 +-
 llvm/lib/Transforms/Vectorize/VPlan.cpp   | 124 
 llvm/lib/Transforms/Vectorize/VPlan.h | 182 ++
 .../Transforms/Vectorize/VPlanTest.cpp|   2 +
 4 files changed, 309 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp 
b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 10c068e3b5895c..9ffd44d59ffc6d 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -10078,7 +10078,7 @@ bool LoopVectorizePass::processLoop(Loop *L) {
 EpilogueVectorizerMainLoop MainILV(L, PSE, LI, DT, TLI, TTI, AC, ORE,
EPI, &LVL, &CM, BFI, PSI, Checks);
 
-VPlan &BestMainPlan = LVP.getBestPlanFor(EPI.MainLoopVF);
+VPlan &BestMainPlan = *LVP.getBestPlanFor(EPI.MainLoopVF).clone();
 const auto &[ExpandedSCEVs, ReductionResumeValues] = LVP.executePlan(
 EPI.MainLoopVF, EPI.MainLoopUF, BestMainPlan, MainILV, DT, true);
 ++LoopsVectorized;
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp 
b/llvm/lib/Transforms/Vectorize/VPlan.cpp
index b6e56c47c227f7..99b2a3bd59a64d 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -615,6 +615,18 @@ void VPBasicBlock::print(raw_ostream &O, const Twine 
&Indent,
 }
 #endif
 
+VPBlockBase *VPRegionBlock::clone() {
+  DenseMap Old2New;
+  DenseMap Old2NewVPValues;
+  VPBlockBase *NewEntry =
+  VPBlockUtils::cloneCFG(Entry, Old2New, Old2NewVPValues);
+  auto *NewR =
+  new VPRegionBlock(NewEntry, Old2New[Exiting], getName(), isReplicator());
+  for (VPBlockBase *Block : vp_depth_first_shallow(NewEntry))
+Block->setParent(NewR);
+  return NewR;
+}
+
 void VPRegionBlock::dropAllReferences(VPValue *NewValue) {
   for (VPBlockBase *Block : vp_depth_first_shallow(Entry))
 // Drop all references in VPBasicBlocks and replace all uses with
@@ -982,6 +994,65 @@ void VPlan::updateDominatorTree(DominatorTree *DT, 
BasicBlock *LoopHeaderBB,
   assert(DT->verify(DominatorTree::VerificationLevel::Fast));
 }
 
+static void remapVPValues(VPBasicBlock *OldBB, VPBasicBlock *NewBB,
+  DenseMap &Old2NewVPValues,
+  bool Full = false) {
+  for (const auto &[OldR, NewR] : zip(*OldBB, *NewBB)) {
+for (unsigned I = 0, E = NewR.getNumOperands(); I != E; ++I) {
+  VPValue *NewOp = Old2NewVPValues.lookup(OldR.getOperand(I));
+  if (!Full)
+continue;
+  NewR.setOperand(I, NewOp);
+}
+for (const auto &[OldV, NewV] :
+ zip(OldR.definedValues(), NewR.definedValues()))
+  Old2NewVPValues[OldV] = NewV;
+  }
+}
+
+VPlan *VPlan::clone() {
+  DenseMap Old2New;
+  DenseMap Old2NewVPValues;
+
+  auto *NewPlan = new VPlan();
+  SmallVector NewLiveIns;
+  for (VPValue *LI : VPLiveInsToFree) {
+VPValue *NewLI = new VPValue(LI->getLiveInIRValue());
+NewPlan->VPLiveInsToFree.push_back(NewLI);
+Old2NewVPValues[LI] = NewLI;
+  }
+
+  Old2NewVPValues[&VectorTripCount] = &NewPlan->VectorTripCount;
+  Old2NewVPValues[&VFxUF] = &NewPlan->VFxUF;
+  if (BackedgeTakenCount) {
+Old2NewVPValues[BackedgeTakenCount] = new VPValue();
+NewPlan->BackedgeTakenCount = Old2NewVPValues[BackedgeTakenCount];
+  }
+
+  auto NewPH = cast(Preheader->clone());
+  remapVPValues(cast(Preheader), cast(NewPH),
+Old2NewVPValues, /*Full*/ true);
+  VPValue *NewTC = Old2NewVPValues.lookup(TripCount);
+  if (!NewTC)
+Old2NewVPValues[TripCount] = new VPValue(TripCount->getLiveInIRValue());
+  NewPlan->TripCount = Old2NewVPValues[TripCount];
+
+  auto *NewEntry = cast(VPBlockUtils::cloneCFG(
+  getEntry(), Old2New, Old2NewVPValues, /*FullRemapping*/ true));
+
+  NewPlan->Entry = NewEntry;
+  NewPlan->Preheader = NewPH;
+  NewEntry->setPlan(NewPlan);
+  NewPH->setPlan(NewPlan);
+  NewPlan->VFs = VFs;
+  NewPlan->UFs = UFs;
+  NewPlan->Name = Name;
+
+  for (const auto &[_, LO] : LiveOuts)
+NewPlan->addLiveOut(LO->getPhi(), Old2NewVPValues[LO->getOperand(0)]);
+  return NewPlan;
+}
+
 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 
 Twine VPlanPrinter::getUID(const VPBlockBase *Block) {
@@ -1200,6 +1271,59 @@ void VPUser::printOperands(raw_ostream &O, VPSlotTracker 
&SlotTracker) const {
 }
 #endif
 

[libc] [lld] [llvm] [lldb] [clang-tools-extra] [clang] [flang] [compiler-rt] [libcxx] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-26 Thread Florian Hahn via cfe-commits


@@ -982,6 +1037,92 @@ void VPlan::updateDominatorTree(DominatorTree *DT, 
BasicBlock *LoopHeaderBB,
   assert(DT->verify(DominatorTree::VerificationLevel::Fast));
 }
 
+static void remapOperands(VPBlockBase *Entry, VPBlockBase *NewEntry,
+  DenseMap &Old2NewVPValues) {
+  // Update the operands of all cloned recipes starting at NewEntry. This
+  // traverses all reachable blocks. This is done in two steps, to handle 
cycles
+  // in PHI recipes.
+  ReversePostOrderTraversal>
+  OldDeepRPOT(Entry);
+  ReversePostOrderTraversal>
+  NewDeepRPOT(NewEntry);
+  // First, collect all mappings from old to new VPValues defined by cloned
+  // recipes.
+  for (const auto &[OldBB, NewBB] :
+   zip(VPBlockUtils::blocksOnly(OldDeepRPOT),
+   VPBlockUtils::blocksOnly(NewDeepRPOT))) {
+assert(OldBB->getRecipeList().size() == NewBB->getRecipeList().size() &&
+   "blocks must have the same number of recipes");
+

fhahn wrote:

Removed, thanks!

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


[clang] [lld] [libc] [flang] [lldb] [libcxx] [clang-tools-extra] [llvm] [compiler-rt] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-26 Thread Florian Hahn via cfe-commits


@@ -982,6 +1037,92 @@ void VPlan::updateDominatorTree(DominatorTree *DT, 
BasicBlock *LoopHeaderBB,
   assert(DT->verify(DominatorTree::VerificationLevel::Fast));
 }
 
+static void remapOperands(VPBlockBase *Entry, VPBlockBase *NewEntry,
+  DenseMap &Old2NewVPValues) {
+  // Update the operands of all cloned recipes starting at NewEntry. This
+  // traverses all reachable blocks. This is done in two steps, to handle 
cycles
+  // in PHI recipes.
+  ReversePostOrderTraversal>
+  OldDeepRPOT(Entry);
+  ReversePostOrderTraversal>
+  NewDeepRPOT(NewEntry);
+  // First, collect all mappings from old to new VPValues defined by cloned
+  // recipes.
+  for (const auto &[OldBB, NewBB] :
+   zip(VPBlockUtils::blocksOnly(OldDeepRPOT),
+   VPBlockUtils::blocksOnly(NewDeepRPOT))) {
+assert(OldBB->getRecipeList().size() == NewBB->getRecipeList().size() &&
+   "blocks must have the same number of recipes");
+
+for (const auto &[OldR, NewR] : zip(*OldBB, *NewBB)) {
+  assert(OldR.getNumOperands() == NewR.getNumOperands() &&
+ "recipes must have the same number of operands");
+  assert(OldR.getNumDefinedValues() == NewR.getNumDefinedValues() &&
+ "recipes must define the same number of operands");
+  for (const auto &[OldV, NewV] :
+   zip(OldR.definedValues(), NewR.definedValues()))
+Old2NewVPValues[OldV] = NewV;
+}
+  }
+
+  // Update all operands to use cloned VPValues.
+  for (VPBasicBlock *NewBB :
+   VPBlockUtils::blocksOnly(NewDeepRPOT)) {
+for (VPRecipeBase &NewR : *NewBB)
+  for (unsigned I = 0, E = NewR.getNumOperands(); I != E; ++I) {
+VPValue *NewOp = Old2NewVPValues.lookup(NewR.getOperand(I));
+NewR.setOperand(I, NewOp);
+  }
+  }
+}
+
+VPlan *VPlan::clone() {
+  DenseMap Old2NewVPValues;
+
+  // Clone blocks.
+  VPBlockBase *NewPreheader = cloneVPB(Preheader);
+  const auto &[NewEntry, __] = cloneSESE(getEntry());
+
+  // Create VPlan, clone live-ins and remap operands in the cloned blocks.
+  auto *NewPlan =
+  new VPlan(cast(NewPreheader), 
cast(NewEntry));
+  for (VPValue *OldLiveIn : VPLiveInsToFree) {
+VPValue *NewLiveIn = new VPValue(OldLiveIn->getLiveInIRValue());
+NewPlan->VPLiveInsToFree.push_back(NewLiveIn);
+Old2NewVPValues[OldLiveIn] = NewLiveIn;
+  }
+  Old2NewVPValues[&VectorTripCount] = &NewPlan->VectorTripCount;
+  Old2NewVPValues[&VFxUF] = &NewPlan->VFxUF;
+  if (BackedgeTakenCount) {
+NewPlan->BackedgeTakenCount = new VPValue();
+Old2NewVPValues[BackedgeTakenCount] = NewPlan->BackedgeTakenCount;
+  }
+  assert(TripCount && "trip count must be set");
+  if (TripCount->isLiveIn())
+Old2NewVPValues[TripCount] = new VPValue(TripCount->getLiveInIRValue());
+  // else NewTripCount will be created and inserted into Old2NewVPValues when
+  // TripCount is cloned. In any case NewPlan->TripCount is updated below.
+
+  remapOperands(Preheader, NewPreheader, Old2NewVPValues);
+  remapOperands(Entry, NewEntry, Old2NewVPValues);
+
+  // Clone live-outs.
+  for (const auto &[_, LO] : LiveOuts)
+NewPlan->addLiveOut(LO->getPhi(), Old2NewVPValues[LO->getOperand(0)]);
+
+  // Initialize remaining fields of cloned VPlan.
+  NewEntry->setPlan(NewPlan);
+  NewPreheader->setPlan(NewPlan);

fhahn wrote:

Removed, thanks!

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


[clang-tools-extra] [libcxx] [flang] [lld] [lldb] [libc] [llvm] [compiler-rt] [clang] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-26 Thread Florian Hahn via cfe-commits


@@ -982,6 +1037,92 @@ void VPlan::updateDominatorTree(DominatorTree *DT, 
BasicBlock *LoopHeaderBB,
   assert(DT->verify(DominatorTree::VerificationLevel::Fast));
 }
 
+static void remapOperands(VPBlockBase *Entry, VPBlockBase *NewEntry,

fhahn wrote:

I left it as is, as keeping it is quite long and having it separate makes it a 
bit easier to read IMO (also reduces one level of indent), but happy to move it 
preferred.

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


[libc] [clang] [flang] [clang-tools-extra] [compiler-rt] [llvm] [libcxx] [lld] [lldb] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-26 Thread Florian Hahn via cfe-commits


@@ -982,6 +1037,92 @@ void VPlan::updateDominatorTree(DominatorTree *DT, 
BasicBlock *LoopHeaderBB,
   assert(DT->verify(DominatorTree::VerificationLevel::Fast));
 }
 
+static void remapOperands(VPBlockBase *Entry, VPBlockBase *NewEntry,
+  DenseMap &Old2NewVPValues) {
+  // Update the operands of all cloned recipes starting at NewEntry. This
+  // traverses all reachable blocks. This is done in two steps, to handle 
cycles
+  // in PHI recipes.
+  ReversePostOrderTraversal>
+  OldDeepRPOT(Entry);
+  ReversePostOrderTraversal>
+  NewDeepRPOT(NewEntry);
+  // First, collect all mappings from old to new VPValues defined by cloned
+  // recipes.
+  for (const auto &[OldBB, NewBB] :
+   zip(VPBlockUtils::blocksOnly(OldDeepRPOT),
+   VPBlockUtils::blocksOnly(NewDeepRPOT))) {
+assert(OldBB->getRecipeList().size() == NewBB->getRecipeList().size() &&
+   "blocks must have the same number of recipes");
+
+for (const auto &[OldR, NewR] : zip(*OldBB, *NewBB)) {
+  assert(OldR.getNumOperands() == NewR.getNumOperands() &&
+ "recipes must have the same number of operands");
+  assert(OldR.getNumDefinedValues() == NewR.getNumDefinedValues() &&
+ "recipes must define the same number of operands");
+  for (const auto &[OldV, NewV] :
+   zip(OldR.definedValues(), NewR.definedValues()))
+Old2NewVPValues[OldV] = NewV;
+}
+  }
+
+  // Update all operands to use cloned VPValues.
+  for (VPBasicBlock *NewBB :
+   VPBlockUtils::blocksOnly(NewDeepRPOT)) {
+for (VPRecipeBase &NewR : *NewBB)
+  for (unsigned I = 0, E = NewR.getNumOperands(); I != E; ++I) {
+VPValue *NewOp = Old2NewVPValues.lookup(NewR.getOperand(I));
+NewR.setOperand(I, NewOp);
+  }
+  }
+}
+
+VPlan *VPlan::clone() {
+  DenseMap Old2NewVPValues;
+
+  // Clone blocks.
+  VPBlockBase *NewPreheader = cloneVPB(Preheader);
+  const auto &[NewEntry, __] = cloneSESE(getEntry());

fhahn wrote:

Updated to use `Entry`, thanks!

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


[llvm] [clang] [flang] [compiler-rt] [clang-tools-extra] [libcxx] [lldb] [libc] [lld] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-26 Thread Florian Hahn via cfe-commits


@@ -982,6 +1037,92 @@ void VPlan::updateDominatorTree(DominatorTree *DT, 
BasicBlock *LoopHeaderBB,
   assert(DT->verify(DominatorTree::VerificationLevel::Fast));
 }
 
+static void remapOperands(VPBlockBase *Entry, VPBlockBase *NewEntry,
+  DenseMap &Old2NewVPValues) {
+  // Update the operands of all cloned recipes starting at NewEntry. This
+  // traverses all reachable blocks. This is done in two steps, to handle 
cycles
+  // in PHI recipes.
+  ReversePostOrderTraversal>
+  OldDeepRPOT(Entry);
+  ReversePostOrderTraversal>
+  NewDeepRPOT(NewEntry);
+  // First, collect all mappings from old to new VPValues defined by cloned
+  // recipes.
+  for (const auto &[OldBB, NewBB] :
+   zip(VPBlockUtils::blocksOnly(OldDeepRPOT),
+   VPBlockUtils::blocksOnly(NewDeepRPOT))) {
+assert(OldBB->getRecipeList().size() == NewBB->getRecipeList().size() &&
+   "blocks must have the same number of recipes");
+
+for (const auto &[OldR, NewR] : zip(*OldBB, *NewBB)) {
+  assert(OldR.getNumOperands() == NewR.getNumOperands() &&
+ "recipes must have the same number of operands");
+  assert(OldR.getNumDefinedValues() == NewR.getNumDefinedValues() &&
+ "recipes must define the same number of operands");
+  for (const auto &[OldV, NewV] :
+   zip(OldR.definedValues(), NewR.definedValues()))
+Old2NewVPValues[OldV] = NewV;
+}
+  }
+
+  // Update all operands to use cloned VPValues.
+  for (VPBasicBlock *NewBB :
+   VPBlockUtils::blocksOnly(NewDeepRPOT)) {
+for (VPRecipeBase &NewR : *NewBB)
+  for (unsigned I = 0, E = NewR.getNumOperands(); I != E; ++I) {
+VPValue *NewOp = Old2NewVPValues.lookup(NewR.getOperand(I));
+NewR.setOperand(I, NewOp);
+  }
+  }
+}
+
+VPlan *VPlan::clone() {
+  DenseMap Old2NewVPValues;

fhahn wrote:

Moved, thanks!

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


[libcxx] [lldb] [clang] [compiler-rt] [libc] [lld] [llvm] [flang] [clang-tools-extra] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-26 Thread Florian Hahn via cfe-commits


@@ -614,6 +614,61 @@ void VPBasicBlock::print(raw_ostream &O, const Twine 
&Indent,
   printSuccessors(O, Indent);
 }
 #endif
+static void cloneCFG(VPBlockBase *Entry,
+ DenseMap &Old2NewVPBlocks);
+
+static VPBlockBase *cloneVPB(VPBlockBase *BB) {

fhahn wrote:

Updated to move block cloning to `::clone()` (in line with recipes) and renamed 
`VPlan::clone` to `VPlan::duplicate`. 

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


[clang-tools-extra] [flang] [llvm] [clang] [compiler-rt] [VPlan] Replace VPRecipeOrVPValue with VP2VP recipe simplification. (PR #76090)

2024-01-26 Thread via cfe-commits


@@ -8378,9 +8357,8 @@ void VPRecipeBuilder::fixHeaderPhis() {
   }
 }
 
-VPRecipeOrVPValueTy VPRecipeBuilder::handleReplication(Instruction *I,
-   VFRange &Range,
-   VPlan &Plan) {
+VPRecipeBase *VPRecipeBuilder::handleReplication(Instruction *I, VFRange 
&Range,

ayalz wrote:

```suggestion
VPReplicateRecipe *VPRecipeBuilder::handleReplication(Instruction *I, VFRange 
&Range,
```
?

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


[clang] [flang] [clang-tools-extra] [compiler-rt] [llvm] [VPlan] Replace VPRecipeOrVPValue with VP2VP recipe simplification. (PR #76090)

2024-01-26 Thread via cfe-commits


@@ -8999,6 +8963,18 @@ void 
LoopVectorizationPlanner::adjustRecipesForReductions(
 LinkVPBB->insert(FMulRecipe, CurrentLink->getIterator());
 VecOp = FMulRecipe;
   } else {
+auto *Blend = dyn_cast(CurrentLink);
+if (PhiR->isInLoop() && Blend) {
+  assert(Blend->getNumIncomingValues() == 2);
+  assert(any_of(Blend->operands(),
+[PhiR](VPValue *Op) { return Op == PhiR; }));
+  if (Blend->getIncomingValue(0) == PhiR)
+Blend->replaceAllUsesWith(Blend->getIncomingValue(1));
+  else

ayalz wrote:

```suggestion
  else {
assert(Blend->getIncomingValue(1) == PhiR && "...");
```
instead of above assert(any_of(...))?

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


[compiler-rt] [clang-tools-extra] [flang] [clang] [llvm] [VPlan] Replace VPRecipeOrVPValue with VP2VP recipe simplification. (PR #76090)

2024-01-26 Thread via cfe-commits


@@ -8999,6 +8963,18 @@ void 
LoopVectorizationPlanner::adjustRecipesForReductions(
 LinkVPBB->insert(FMulRecipe, CurrentLink->getIterator());
 VecOp = FMulRecipe;
   } else {
+auto *Blend = dyn_cast(CurrentLink);

ayalz wrote:

Add folding of inloop blend to documentation above.

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


[flang] [llvm] [clang] [clang-tools-extra] [compiler-rt] [VPlan] Replace VPRecipeOrVPValue with VP2VP recipe simplification. (PR #76090)

2024-01-26 Thread via cfe-commits


@@ -116,12 +111,11 @@ class VPRecipeBuilder {
 
   /// Check if an existing VPValue can be used for \p Instr or a recipe can be
   /// create for \p I withing the given VF \p Range. If an existing VPValue can

ayalz wrote:

Comment needs updating. (Plus fixing "withing" typo).

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


[clang] [clang-tools-extra] [compiler-rt] [llvm] [flang] [VPlan] Replace VPRecipeOrVPValue with VP2VP recipe simplification. (PR #76090)

2024-01-26 Thread via cfe-commits


@@ -806,6 +806,19 @@ static unsigned getOpcodeForRecipe(VPRecipeBase &R) {
 
 /// Try to simplify recipe \p R.
 static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
+  // Try to remove redundant blend recipes.
+  if (auto *Blend = dyn_cast(&R)) {
+bool AllEqual = true;
+for (unsigned I = 1; I != Blend->getNumIncomingValues(); ++I)
+  AllEqual &= Blend->getIncomingValue(0) == Blend->getIncomingValue(I);
+if (AllEqual) {
+  Blend->replaceAllUsesWith(Blend->getIncomingValue(0));
+  Blend->eraseFromParent();
+  return;
+}
+return;
+  }

ayalz wrote:

Can be simplified?
```suggestion
  if (auto *Blend = dyn_cast(&R)) {
for (unsigned I = 1; I != Blend->getNumIncomingValues(); ++I)
  if (Blend->getIncomingValue(0) != Blend->getIncomingValue(I))
return;
Blend->replaceAllUsesWith(Blend->getIncomingValue(0));
Blend->eraseFromParent();
return;
  }
```

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


[llvm] [clang] [clang-tools-extra] [compiler-rt] [flang] [VPlan] Replace VPRecipeOrVPValue with VP2VP recipe simplification. (PR #76090)

2024-01-26 Thread via cfe-commits


@@ -88,8 +86,8 @@ class VPRecipeBuilder {
   /// or a new VPBlendRecipe otherwise. Currently all such phi nodes are turned

ayalz wrote:

Comment needs updating.

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


[compiler-rt] [flang] [clang] [clang-tools-extra] [llvm] [VPlan] Replace VPRecipeOrVPValue with VP2VP recipe simplification. (PR #76090)

2024-01-26 Thread via cfe-commits


@@ -8999,6 +8963,18 @@ void 
LoopVectorizationPlanner::adjustRecipesForReductions(
 LinkVPBB->insert(FMulRecipe, CurrentLink->getIterator());
 VecOp = FMulRecipe;
   } else {
+auto *Blend = dyn_cast(CurrentLink);
+if (PhiR->isInLoop() && Blend) {
+  assert(Blend->getNumIncomingValues() == 2);

ayalz wrote:

nit: assert message.

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


[clang] [flang] [clang-tools-extra] [compiler-rt] [llvm] [VPlan] Replace VPRecipeOrVPValue with VP2VP recipe simplification. (PR #76090)

2024-01-26 Thread via cfe-commits


@@ -8292,13 +8271,13 @@ VPRecipeOrVPValueTy VPRecipeBuilder::tryToBlend(PHINode 
*Phi,
   for (unsigned In = 0; In < NumIncoming; In++) {
 VPValue *EdgeMask =
 createEdgeMask(Phi->getIncomingBlock(In), Phi->getParent(), *Plan);
-assert((EdgeMask || NumIncoming == 1) &&
+assert((EdgeMask || NumIncoming == 1 || Operands[In] == Operands[0]) &&

ayalz wrote:

Ah, right. This empty edge-mask case is a bit subtle.

Blend recipe expects an even number of operands, referring to them as 
{incoming-value, non-null edge-mask} pairs, or else a single operand, referring 
to it as an incoming-value.

An empty edge-mask is formed when its predecessor has an empty block-mask and a 
single successor or two identical successors, as in the above degenerate 
example. In the latter case, however, OperandsWithMask will contain two 
entries, both being (the same) incoming-values, as their edge-masks are both 
null. Note that three or more incoming-values must (all) have non-null 
edge-masks, otherwise they must post/dominate each other.

So maybe clearer to have something like:
```
  for (unsigned In = 0; In < NumIncoming; In++) {
OperandsWithMask.push_back(Operands[In]);
VPValue *EdgeMask =
createEdgeMask(Phi->getIncomingBlock(In), Phi->getParent(), *Plan);
if (!EdgeMask) {
  assert(In == 0 && "Both null and non-null edge masks found");
  assert(llvm::all_equal(Operands) && "Distinct incoming values with one 
having a full mask");
  break;
}
OperandsWithMask.push_back(EdgeMask);
  }
```

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


[clang] [clang-repl] Typo within InterpreterTest.cpp (PR #79119)

2024-01-26 Thread Nashe Mncube via cfe-commits

https://github.com/nasherm closed 
https://github.com/llvm/llvm-project/pull/79119
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Typo within InterpreterTest.cpp (PR #79119)

2024-01-26 Thread Nashe Mncube via cfe-commits

nasherm wrote:

Need to follow proper contribution process. So closing for now

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


[clang] [libc] [flang] [libcxx] [clang-tools-extra] [lld] [compiler-rt] [llvm] [lldb] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-26 Thread via cfe-commits

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

Looks good to me, ship it!

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


[clang] [llvm] Changed the __ARM_ARCH macro to match the definition in the ACLE. (PR #79583)

2024-01-26 Thread James Westwood via cfe-commits

https://github.com/jwestwood921 created 
https://github.com/llvm/llvm-project/pull/79583

Added functionality to the ARMTargetParser to obtain the minor version of each 
architecture, and amended ARM.cpp and AArch64.cpp to define __ARM_ARCH 
correctly.

In ACLE 5.4.1, __ARM_ARCH is defined as equal to the major architecture version 
for ISAs up to and including v8. From v8.1 onwards, it's definition is changed 
to include minor versions, such that for an architecture vX.Y, __ARM_ARCH = 
X*100 + Y.


>From ca0e00f887f1d7c397f1ff690f2614c46b423285 Mon Sep 17 00:00:00 2001
From: James Westwood 
Date: Tue, 16 Jan 2024 13:40:50 +
Subject: [PATCH] Changed the __ARM_ARCH macro to match the definition in the
 ACLE.

Added functionality to the ARMTargetParser to obtain the minor version of each 
architecture, and amended ARM.cpp and AArch64.cpp to define __ARM_ARCH 
correctly.

In ACLE 5.4.1, __ARM_ARCH is defined as equal to the major architecture version 
for ISAs up to and including v8. From v8.1 onwards, it's definition is changed 
to
include minor versions, such that for an architecture vX.Y, __ARM_ARCH = X*100 
+ Y.

Change-Id: Ia9d0943009790f206f1f6422e43996cf501e99f8
---
 clang/lib/Basic/Targets/AArch64.cpp   | 17 +-
 clang/lib/Basic/Targets/ARM.cpp   | 15 -
 clang/lib/Basic/Targets/ARM.h |  1 +
 clang/test/Preprocessor/arm-target-features.c | 32 +-
 .../llvm/TargetParser/ARMTargetParser.h   |  1 +
 llvm/lib/TargetParser/ARMTargetParser.cpp | 60 +++
 .../TargetParser/TargetParserTest.cpp |  8 +++
 7 files changed, 113 insertions(+), 21 deletions(-)

diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index d47181bfca4fc86..7d0f879b3daee6f 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -368,8 +368,21 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
 
   // ACLE predefines. Many can only have one possible value on v8 AArch64.
   Builder.defineMacro("__ARM_ACLE", "200");
-  Builder.defineMacro("__ARM_ARCH",
-  std::to_string(ArchInfo->Version.getMajor()));
+
+  // ACLE 5.4.1 ARM/Thumb instruction set architecture
+  // __ARM_ARCH is defined as an integer value indicating the current ARM ISA.
+  // For ISAs up to and including v8, __ARM_ARCH is equal to the major version
+  // number. For ISAs from v8.1 onwards, __ARM_ARCH is scaled up to include the
+  // minor version number, e.g. for ARM architecture ARMvX.Y:
+  // __ARM_ARCH = X * 100 + Y.
+  if (ArchInfo->Version.getMajor() == 8 && ArchInfo->Version.getMinor() == 0)
+Builder.defineMacro("__ARM_ARCH",
+std::to_string(ArchInfo->Version.getMajor()));
+  else
+Builder.defineMacro("__ARM_ARCH",
+std::to_string(ArchInfo->Version.getMajor() * 100 +
+   ArchInfo->Version.getMinor().value()));
+
   Builder.defineMacro("__ARM_ARCH_PROFILE",
   std::string("'") + (char)ArchInfo->Profile + "'");
 
diff --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp
index 55b71557452fa04..9ac558caa2886aa 100644
--- a/clang/lib/Basic/Targets/ARM.cpp
+++ b/clang/lib/Basic/Targets/ARM.cpp
@@ -130,6 +130,7 @@ void ARMTargetInfo::setArchInfo(llvm::ARM::ArchKind Kind) {
   SubArch = llvm::ARM::getSubArch(ArchKind);
   ArchProfile = llvm::ARM::parseArchProfile(SubArch);
   ArchVersion = llvm::ARM::parseArchVersion(SubArch);
+  ArchMinorVersion = llvm::ARM::parseArchMinorVersion(SubArch);
 
   // cache CPU related strings
   CPUAttr = getCPUAttr();
@@ -736,9 +737,17 @@ void ARMTargetInfo::getTargetDefines(const LangOptions 
&Opts,
   if (!CPUAttr.empty())
 Builder.defineMacro("__ARM_ARCH_" + CPUAttr + "__");
 
-  // ACLE 6.4.1 ARM/Thumb instruction set architecture
-  // __ARM_ARCH is defined as an integer value indicating the current ARM ISA
-  Builder.defineMacro("__ARM_ARCH", Twine(ArchVersion));
+  // ACLE 5.4.1 ARM/Thumb instruction set architecture
+  // __ARM_ARCH is defined as an integer value indicating the current ARM ISA.
+  // For ISAs up to and including v8, __ARM_ARCH is equal to the major version
+  // number. For ISAs from v8.1 onwards, __ARM_ARCH is scaled up to include the
+  // minor version number, e.g. for ARM architecture ARMvX.Y:
+  // __ARM_ARCH = X * 100 + Y.
+  if (ArchVersion >= 9 || ArchMinorVersion != 0)
+Builder.defineMacro("__ARM_ARCH",
+Twine(ArchVersion * 100 + ArchMinorVersion));
+  else
+Builder.defineMacro("__ARM_ARCH", Twine(ArchVersion));
 
   if (ArchVersion >= 8) {
 // ACLE 6.5.7 Crypto Extension
diff --git a/clang/lib/Basic/Targets/ARM.h b/clang/lib/Basic/Targets/ARM.h
index 9802eb01abf3c43..9c4bd299f67339a 100644
--- a/clang/lib/Basic/Targets/ARM.h
+++ b/clang/lib/Basic/Targets/ARM.h
@@ -60,6 +60,7 @@ class LLVM_LIBRARY_VISIBILITY ARMTargetInfo : public 
TargetInfo {

[clang] [llvm] Changed the __ARM_ARCH macro to match the definition in the ACLE. (PR #79583)

2024-01-26 Thread via cfe-commits

github-actions[bot] wrote:

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] [llvm] Changed the __ARM_ARCH macro to match the definition in the ACLE. (PR #79583)

2024-01-26 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-backend-arm

@llvm/pr-subscribers-backend-aarch64

Author: James Westwood (jwestwood921)


Changes

Added functionality to the ARMTargetParser to obtain the minor version of each 
architecture, and amended ARM.cpp and AArch64.cpp to define __ARM_ARCH 
correctly.

In ACLE 5.4.1, __ARM_ARCH is defined as equal to the major architecture version 
for ISAs up to and including v8. From v8.1 onwards, it's definition is changed 
to include minor versions, such that for an architecture vX.Y, __ARM_ARCH = 
X*100 + Y.


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


7 Files Affected:

- (modified) clang/lib/Basic/Targets/AArch64.cpp (+15-2) 
- (modified) clang/lib/Basic/Targets/ARM.cpp (+12-3) 
- (modified) clang/lib/Basic/Targets/ARM.h (+1) 
- (modified) clang/test/Preprocessor/arm-target-features.c (+16-16) 
- (modified) llvm/include/llvm/TargetParser/ARMTargetParser.h (+1) 
- (modified) llvm/lib/TargetParser/ARMTargetParser.cpp (+60) 
- (modified) llvm/unittests/TargetParser/TargetParserTest.cpp (+8) 


``diff
diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index d47181bfca4fc8..7d0f879b3daee6 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -368,8 +368,21 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
 
   // ACLE predefines. Many can only have one possible value on v8 AArch64.
   Builder.defineMacro("__ARM_ACLE", "200");
-  Builder.defineMacro("__ARM_ARCH",
-  std::to_string(ArchInfo->Version.getMajor()));
+
+  // ACLE 5.4.1 ARM/Thumb instruction set architecture
+  // __ARM_ARCH is defined as an integer value indicating the current ARM ISA.
+  // For ISAs up to and including v8, __ARM_ARCH is equal to the major version
+  // number. For ISAs from v8.1 onwards, __ARM_ARCH is scaled up to include the
+  // minor version number, e.g. for ARM architecture ARMvX.Y:
+  // __ARM_ARCH = X * 100 + Y.
+  if (ArchInfo->Version.getMajor() == 8 && ArchInfo->Version.getMinor() == 0)
+Builder.defineMacro("__ARM_ARCH",
+std::to_string(ArchInfo->Version.getMajor()));
+  else
+Builder.defineMacro("__ARM_ARCH",
+std::to_string(ArchInfo->Version.getMajor() * 100 +
+   ArchInfo->Version.getMinor().value()));
+
   Builder.defineMacro("__ARM_ARCH_PROFILE",
   std::string("'") + (char)ArchInfo->Profile + "'");
 
diff --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp
index 55b71557452fa0..9ac558caa2886a 100644
--- a/clang/lib/Basic/Targets/ARM.cpp
+++ b/clang/lib/Basic/Targets/ARM.cpp
@@ -130,6 +130,7 @@ void ARMTargetInfo::setArchInfo(llvm::ARM::ArchKind Kind) {
   SubArch = llvm::ARM::getSubArch(ArchKind);
   ArchProfile = llvm::ARM::parseArchProfile(SubArch);
   ArchVersion = llvm::ARM::parseArchVersion(SubArch);
+  ArchMinorVersion = llvm::ARM::parseArchMinorVersion(SubArch);
 
   // cache CPU related strings
   CPUAttr = getCPUAttr();
@@ -736,9 +737,17 @@ void ARMTargetInfo::getTargetDefines(const LangOptions 
&Opts,
   if (!CPUAttr.empty())
 Builder.defineMacro("__ARM_ARCH_" + CPUAttr + "__");
 
-  // ACLE 6.4.1 ARM/Thumb instruction set architecture
-  // __ARM_ARCH is defined as an integer value indicating the current ARM ISA
-  Builder.defineMacro("__ARM_ARCH", Twine(ArchVersion));
+  // ACLE 5.4.1 ARM/Thumb instruction set architecture
+  // __ARM_ARCH is defined as an integer value indicating the current ARM ISA.
+  // For ISAs up to and including v8, __ARM_ARCH is equal to the major version
+  // number. For ISAs from v8.1 onwards, __ARM_ARCH is scaled up to include the
+  // minor version number, e.g. for ARM architecture ARMvX.Y:
+  // __ARM_ARCH = X * 100 + Y.
+  if (ArchVersion >= 9 || ArchMinorVersion != 0)
+Builder.defineMacro("__ARM_ARCH",
+Twine(ArchVersion * 100 + ArchMinorVersion));
+  else
+Builder.defineMacro("__ARM_ARCH", Twine(ArchVersion));
 
   if (ArchVersion >= 8) {
 // ACLE 6.5.7 Crypto Extension
diff --git a/clang/lib/Basic/Targets/ARM.h b/clang/lib/Basic/Targets/ARM.h
index 9802eb01abf3c4..9c4bd299f67339 100644
--- a/clang/lib/Basic/Targets/ARM.h
+++ b/clang/lib/Basic/Targets/ARM.h
@@ -60,6 +60,7 @@ class LLVM_LIBRARY_VISIBILITY ARMTargetInfo : public 
TargetInfo {
   llvm::ARM::ArchKind ArchKind = llvm::ARM::ArchKind::ARMV4T;
   llvm::ARM::ProfileKind ArchProfile;
   unsigned ArchVersion;
+  unsigned ArchMinorVersion;
 
   unsigned FPU : 5;
   unsigned MVE : 2;
diff --git a/clang/test/Preprocessor/arm-target-features.c 
b/clang/test/Preprocessor/arm-target-features.c
index 236c9f2479b705..2122082760b6f6 100644
--- a/clang/test/Preprocessor/arm-target-features.c
+++ b/clang/test/Preprocessor/arm-target-features.c
@@ -737,7 +737,7 @@
 
 // Test whether predefines are as expected when targeting cortex-m55 (softfp 
FP ABI as default).
 //

[clang] [Clang][RISCV] Forward --no-relax option to linker for RISC-V (PR #76432)

2024-01-26 Thread Andreu Carminati via cfe-commits

andcarminati wrote:

> Do you need someone to commit this?

Hi @topperc, if you can commit for me I would appreciate it.

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


[clang] [Sema] Fix c23 not checking CheckBoolLikeConversion (PR #79588)

2024-01-26 Thread Pil Eghoff via cfe-commits

https://github.com/pileghoff created 
https://github.com/llvm/llvm-project/pull/79588

Fixes #79435 

Im not sure if this is the best solution, but it seems to work well.
Should i be adding tests for this? If i should, i would need some help on how. 
I was able to run the test suite, but i have no idea where this test would go. 
My guess would be `tautological-constant-compare.c`, but that test seems to be 
C++ specific.

>From cdacba44198ed9925cbc2cd9e6c79a9b74265b4f Mon Sep 17 00:00:00 2001
From: Pil Eghoff 
Date: Fri, 26 Jan 2024 13:30:17 +0100
Subject: [PATCH] [Sema] Fix c23 not checking CheckBoolLikeConversion

---
 clang/lib/Sema/SemaChecking.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 4d280f25cc04c2..8e3bd1cd46076d 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -16166,7 +16166,7 @@ static void CheckConditionalOperator(Sema &S, 
AbstractConditionalOperator *E,
 /// Check conversion of given expression to boolean.
 /// Input argument E is a logical expression.
 static void CheckBoolLikeConversion(Sema &S, Expr *E, SourceLocation CC) {
-  if (S.getLangOpts().Bool)
+  if (S.getLangOpts().Bool && !S.getLangOpts().C23)
 return;
   if (E->IgnoreParenImpCasts()->getType()->isAtomicType())
 return;

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


[clang] [Sema] Fix c23 not checking CheckBoolLikeConversion (PR #79588)

2024-01-26 Thread via cfe-commits

github-actions[bot] wrote:

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] [Sema] Fix c23 not checking CheckBoolLikeConversion (PR #79588)

2024-01-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Pil Eghoff (pileghoff)


Changes

Fixes #79435 

Im not sure if this is the best solution, but it seems to work well.
Should i be adding tests for this? If i should, i would need some help on how. 
I was able to run the test suite, but i have no idea where this test would go. 
My guess would be `tautological-constant-compare.c`, but that test seems to be 
C++ specific.

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


1 Files Affected:

- (modified) clang/lib/Sema/SemaChecking.cpp (+1-1) 


``diff
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 4d280f25cc04c2..8e3bd1cd46076d 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -16166,7 +16166,7 @@ static void CheckConditionalOperator(Sema &S, 
AbstractConditionalOperator *E,
 /// Check conversion of given expression to boolean.
 /// Input argument E is a logical expression.
 static void CheckBoolLikeConversion(Sema &S, Expr *E, SourceLocation CC) {
-  if (S.getLangOpts().Bool)
+  if (S.getLangOpts().Bool && !S.getLangOpts().C23)
 return;
   if (E->IgnoreParenImpCasts()->getType()->isAtomicType())
 return;

``




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


[clang] [Sema] Fix c23 not checking CheckBoolLikeConversion (PR #79588)

2024-01-26 Thread Pil Eghoff via cfe-commits

pileghoff wrote:

@AaronBallman If you have time for review, the PR is ready 👍🏽 

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


[clang] Extend life of variables in `DiagComparison` in `ExprConstant` (PR #79522)

2024-01-26 Thread via cfe-commits

AdvenamTacet wrote:

@cor3ntin  Thx for your comment! I looked at ternary operator at the very 
beginning, but discarded this direction as I was unable to create a small 
example reproducing the error. After your comment I started looking at it again.
Your temporary fix also resolves the problem on buildbots, which may mean that 
my assumption of the origin of the error is wrong.

We really should understand what is happening here.

Assuming that there is no use after end of life, by looking at shadow memory:
```
  0x7fc0a5b28e80: f2 f2 f8 f8 f8 f8 f8 f8 f8 f8 f8 f2 f2 f2 f2 f2
=>0x7fc0a5b28f00: 00 00 00 f2 f2 f2 f2 f2 04 fc[fc]f3 f3 f3 f3 f3
  0x7fc0a5b28f80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
```
and backtrace:
```
#0 0x5625049af24b in __get_long_pointer 
/b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan_ubsan/include/c++/v1/string:1870:29
#1 0x5625049af24b in __get_pointer 
/b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan_ubsan/include/c++/v1/string:1882:26
#2 0x5625049af24b in data 
/b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan_ubsan/include/c++/v1/string:1596:30
#3 0x5625049af24b in StringRef 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/ADT/StringRef.h:101:18
#4 0x5625049af24b in operator<<, std::__1::allocator > > 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/include/clang/Basic/PartialDiagnostic.h:60:11
#5 0x5625049af24b in operator<<, std::__1::allocator > > 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/include/clang/AST/OptionalDiagnostic.h:36:13
#6 0x5625049af24b in bool EvaluateComparisonBinaryOperator<(anonymous 
namespace)::IntExprEvaluator::VisitBinaryOperator(clang::BinaryOperator 
const*)::$_0&, (anonymous 
namespace)::IntExprEvaluator::VisitBinaryOperator(clang::BinaryOperator 
const*)::$_1>((anonymous namespace)::EvalInfo&, clang::BinaryOperator const*, 
(anonymous 
namespace)::IntExprEvaluator::VisitBinaryOperator(clang::BinaryOperator 
const*)::$_0&, (anonymous 
namespace)::IntExprEvaluator::VisitBinaryOperator(clang::BinaryOperator 
const*)::$_1&&)::'lambda'(unsigned int, bool)::operator()(unsigned int, bool) 
const 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/AST/ExprConstant.cpp:13295:13
#7 0x5625049aaabd in bool EvaluateComparisonBinaryOperator<(anonymous 
namespace)::IntExprEvaluator::VisitBinaryOperator(clang::BinaryOperator 
const*)::$_0&, (anonymous 
namespace)::IntExprEvaluator::VisitBinaryOperator(clang::BinaryOperator 
const*)::$_1>((anonymous namespace)::EvalInfo&, clang::BinaryOperator const*, 
(anonymous 
namespace)::IntExprEvaluator::VisitBinaryOperator(clang::BinaryOperator 
const*)::$_0&, (anonymous 
namespace)::IntExprEvaluator::VisitBinaryOperator(clang::BinaryOperator 
const*)::$_1&&) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/AST/ExprConstant.cpp
#8 0x5625049878b1 in (anonymous 
namespace)::IntExprEvaluator::VisitBinaryOperator(clang::BinaryOperator const*) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/AST/ExprConstant.cpp:13584:12
  
```
One potential option I see are incorrect annotations.
It's possible that a function marked `_LIBCPP_STRING_INTERNAL_MEMORY_ACCESS` in 
`libcxx/include/string` writes over poisoned memory and never updates 
annotations. There are five functions like that, which write to memory, and I 
cannot see a single issue with them.

For testing, I will write code not using 
`_LIBCPP_STRING_INTERNAL_MEMORY_ACCESS` at all and check if ASan error is 
raised earlier. 

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


[clang] [clang] Add GCC-compatible code model names for sparc64 (PR #79485)

2024-01-26 Thread Rainer Orth via cfe-commits

rorth wrote:

GCC also supports `-mcmodel=embmedany`.  Maybe it would be good to reject that 
with a clear message?

As for the generated code (not this PR, I'd say), it would certainly be good to 
test that on some larger code base (like LLVM itself) and, preferably, also 
test actual interoperability with GCC. Especially in SPARC support, I have seen 
to many cases where LLVM wouldn't interoperate with itself, let alone GCC.

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


[clang] [llvm] [FMV] Add alias for FEAT_RDM and change priorities according to ACLE. (PR #79316)

2024-01-26 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea updated 
https://github.com/llvm/llvm-project/pull/79316

>From 3e0a3fe637ad6e815d0ca62f38d39c2a27f8b5d5 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Wed, 24 Jan 2024 15:26:01 +
Subject: [PATCH] [FMV] Change feature priorities according to ACLE.

This patch follows the latest ACLE specification as shown in PR
https://github.com/ARM-software/acle/pull/279. It adjusts the
priorities for FEAT_DOTPROD, FEAT_SM4, FEAT_FP16FML, FEAT_RDM.
---
 clang/test/CodeGen/attr-target-version.c  | 30 +--
 .../llvm/TargetParser/AArch64TargetParser.h   |  8 ++---
 2 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/clang/test/CodeGen/attr-target-version.c 
b/clang/test/CodeGen/attr-target-version.c
index feb6c094ab62b1a..2a96697e4291b9b 100644
--- a/clang/test/CodeGen/attr-target-version.c
+++ b/clang/test/CodeGen/attr-target-version.c
@@ -364,36 +364,36 @@ int hoo(void) {
 // CHECK-NEXT:ret ptr @fmv_inline._Mdpb2Mjscvt
 // CHECK:   resolver_else22:
 // CHECK-NEXT:[[TMP48:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
-// CHECK-NEXT:[[TMP49:%.*]] = and i64 [[TMP48]], 16400
-// CHECK-NEXT:[[TMP50:%.*]] = icmp eq i64 [[TMP49]], 16400
+// CHECK-NEXT:[[TMP49:%.*]] = and i64 [[TMP48]], 8
+// CHECK-NEXT:[[TMP50:%.*]] = icmp eq i64 [[TMP49]], 8
 // CHECK-NEXT:[[TMP51:%.*]] = and i1 true, [[TMP50]]
 // CHECK-NEXT:br i1 [[TMP51]], label [[RESOLVER_RETURN23:%.*]], label 
[[RESOLVER_ELSE24:%.*]]
 // CHECK:   resolver_return23:
-// CHECK-NEXT:ret ptr @fmv_inline._MdotprodMaes
+// CHECK-NEXT:ret ptr @fmv_inline._MsimdMfp16fml
 // CHECK:   resolver_else24:
 // CHECK-NEXT:[[TMP52:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
-// CHECK-NEXT:[[TMP53:%.*]] = and i64 [[TMP52]], 8
-// CHECK-NEXT:[[TMP54:%.*]] = icmp eq i64 [[TMP53]], 8
+// CHECK-NEXT:[[TMP53:%.*]] = and i64 [[TMP52]], 16400
+// CHECK-NEXT:[[TMP54:%.*]] = icmp eq i64 [[TMP53]], 16400
 // CHECK-NEXT:[[TMP55:%.*]] = and i1 true, [[TMP54]]
 // CHECK-NEXT:br i1 [[TMP55]], label [[RESOLVER_RETURN25:%.*]], label 
[[RESOLVER_ELSE26:%.*]]
 // CHECK:   resolver_return25:
-// CHECK-NEXT:ret ptr @fmv_inline._Mfp16fmlMsimd
+// CHECK-NEXT:ret ptr @fmv_inline._MdotprodMaes
 // CHECK:   resolver_else26:
 // CHECK-NEXT:[[TMP56:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
-// CHECK-NEXT:[[TMP57:%.*]] = and i64 [[TMP56]], 32
-// CHECK-NEXT:[[TMP58:%.*]] = icmp eq i64 [[TMP57]], 32
+// CHECK-NEXT:[[TMP57:%.*]] = and i64 [[TMP56]], 192
+// CHECK-NEXT:[[TMP58:%.*]] = icmp eq i64 [[TMP57]], 192
 // CHECK-NEXT:[[TMP59:%.*]] = and i1 true, [[TMP58]]
 // CHECK-NEXT:br i1 [[TMP59]], label [[RESOLVER_RETURN27:%.*]], label 
[[RESOLVER_ELSE28:%.*]]
 // CHECK:   resolver_return27:
-// CHECK-NEXT:ret ptr @fmv_inline._Msm4Mfp
+// CHECK-NEXT:ret ptr @fmv_inline._MlseMrdm
 // CHECK:   resolver_else28:
 // CHECK-NEXT:[[TMP60:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
-// CHECK-NEXT:[[TMP61:%.*]] = and i64 [[TMP60]], 192
-// CHECK-NEXT:[[TMP62:%.*]] = icmp eq i64 [[TMP61]], 192
+// CHECK-NEXT:[[TMP61:%.*]] = and i64 [[TMP60]], 32
+// CHECK-NEXT:[[TMP62:%.*]] = icmp eq i64 [[TMP61]], 32
 // CHECK-NEXT:[[TMP63:%.*]] = and i1 true, [[TMP62]]
 // CHECK-NEXT:br i1 [[TMP63]], label [[RESOLVER_RETURN29:%.*]], label 
[[RESOLVER_ELSE30:%.*]]
 // CHECK:   resolver_return29:
-// CHECK-NEXT:ret ptr @fmv_inline._MrdmMlse
+// CHECK-NEXT:ret ptr @fmv_inline._MfpMsm4
 // CHECK:   resolver_else30:
 // CHECK-NEXT:ret ptr @fmv_inline.default
 //
@@ -659,21 +659,21 @@ int hoo(void) {
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: define {{[^@]+}}@fmv_inline._Mfp16fmlMsimd
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MsimdMfp16fml
 // CHECK-SAME: () #[[ATTR7]] {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:ret i32 14
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: define {{[^@]+}}@fmv_inline._Msm4Mfp
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MfpMsm4
 // CHECK-SAME: () #[[ATTR24:[0-9]+]] {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:ret i32 15
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MrdmMlse
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MlseMrdm
 // CHECK-SAME: () #[[ATTR25:[0-9]+]] {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:ret i32 16
diff --git a/llvm/include/llvm/TargetParser/AArch64TargetParser.h 
b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
index 623fdc21ba65a6e..1ac041591b5637f 100644
--- a/llvm/include/llvm/TargetParser/AArch64TargetParser.h
+++ b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
@@ -222,7 +222,7 @@ inline constexpr ExtensionInfo Extensions[] = {
 {"d128", AArch64::AEK_D128, "+d128", "-d128", FEAT_INIT, "", 0},
 {"dgh", AArch64::AEK_NONE, {}, {}, FEAT_DGH, 

[llvm] [clang] [FMV] Change feature priorities according to ACLE. (PR #79316)

2024-01-26 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea edited 
https://github.com/llvm/llvm-project/pull/79316
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [FMV] Change feature priorities according to ACLE. (PR #79316)

2024-01-26 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea edited 
https://github.com/llvm/llvm-project/pull/79316
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [FMV] Change feature priorities according to ACLE. (PR #79316)

2024-01-26 Thread Alexandros Lamprineas via cfe-commits


@@ -114,6 +121,10 @@ const AArch64::ArchInfo *AArch64::parseArch(StringRef 
Arch) {
 }
 
 std::optional AArch64::parseArchExtension(StringRef 
ArchExt) {
+  // Resolve aliases first.
+  ArchExt = resolveExtAlias(ArchExt);

labrinea wrote:

I will separate this change to another PR and leave this review just for the 
adjustment of feature priorities.

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


[llvm] [libcxxabi] [mlir] [openmp] [libcxx] [clang] [flang] [compiler-rt] [libc] [clang-tools-extra] [AArch64] Add custom lowering for load <3 x i8>. (PR #78632)

2024-01-26 Thread Florian Hahn via cfe-commits


@@ -21248,6 +21297,51 @@ static SDValue foldTruncStoreOfExt(SelectionDAG &DAG, 
SDNode *N) {
   return SDValue();
 }
 
+// A custom combine to lower load <3 x i8> as the more efficient sequence
+// below:
+//ldrb wX, [x0, #2]
+//ldrh wY, [x0]
+//orr wX, wY, wX, lsl #16
+//fmov s0, wX
+//
+static SDValue combineV3I8LoadExt(LoadSDNode *LD, SelectionDAG &DAG) {
+  EVT MemVT = LD->getMemoryVT();
+  if (MemVT != EVT::getVectorVT(*DAG.getContext(), MVT::i8, 3) ||
+  LD->getOriginalAlign() >= 4)
+return SDValue();
+
+  SDLoc DL(LD);
+  MachineFunction &MF = DAG.getMachineFunction();
+  SDValue Chain = LD->getChain();
+  SDValue BasePtr = LD->getBasePtr();
+  MachineMemOperand *MMO = LD->getMemOperand();
+  assert(LD->getOffset().isUndef() && "undef offset expected");

fhahn wrote:

Could you share more details?  Not sure how if encountering this with a 
non-AArch64 backend would directly translate to the AArch64 backend?  I am also 
curious how the `<3 x i8>` vectors have been introduced before the backend?

> Should we use some if-branch to detect this, and return SDValue()?

We could, but unless we have a test case, I'd prefer to keep it as an assert 
for now, to give us a chance to catch a test case, if it is possible.

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


[clang] [Sema] Substitute parameter packs when deduced from function arguments (PR #79371)

2024-01-26 Thread Gábor Spaits via cfe-commits

https://github.com/spaits updated 
https://github.com/llvm/llvm-project/pull/79371

From 3e0c3db0d8500e5f2111e3603da3d8f2b1cd261d Mon Sep 17 00:00:00 2001
From: Gabor Spaits 
Date: Wed, 24 Jan 2024 21:21:26 +0100
Subject: [PATCH 01/13] [Sema]Substitue template parameter packs when deduced
 from function parameter

---
 clang/lib/Sema/SemaTemplateDeduction.cpp | 63 +++-
 1 file changed, 62 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index e9e7ab5bb6698a0..46fa9eece3747a2 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -730,6 +730,7 @@ class PackDeductionScope {
   void addPack(unsigned Index) {
 // Save the deduced template argument for the parameter pack expanded
 // by this pack expansion, then clear out the deduction.
+DeducedFromEarlierParameter = !Deduced[Index].isNull();
 DeducedPack Pack(Index);
 Pack.Saved = Deduced[Index];
 Deduced[Index] = TemplateArgument();
@@ -858,6 +859,29 @@ class PackDeductionScope {
   Info.PendingDeducedPacks[Pack.Index] = Pack.Outer;
   }
 
+  std::optional getSavedPackSize(unsigned Index,
+   TemplateArgument Pattern) const {
+
+SmallVector Unexpanded;
+S.collectUnexpandedParameterPacks(Pattern, Unexpanded);
+if (Unexpanded.size() == 0 ||
+Packs[0].Saved.getKind() != clang::TemplateArgument::Pack)
+  return {};
+unsigned PackSize = Packs[0].Saved.pack_size();
+
+if (std::all_of(Packs.begin() + 1, Packs.end(),
+[&PackSize](auto P) {
+  return P.Saved.getKind() == TemplateArgument::Pack &&
+ P.Saved.pack_size() == PackSize;
+}))
+  return PackSize;
+return {};
+  }
+
+  /// Determine whether this pack has already been deduced from a previous
+  /// argument.
+  bool isDeducedFromEarlierParameter() const {return 
DeducedFromEarlierParameter;}
+
   /// Determine whether this pack has already been partially expanded into a
   /// sequence of (prior) function parameters / template arguments.
   bool isPartiallyExpanded() { return IsPartiallyExpanded; }
@@ -970,7 +994,6 @@ class PackDeductionScope {
 NewPack = Pack.DeferredDeduction;
 Result = checkDeducedTemplateArguments(S.Context, OldPack, NewPack);
   }
-
   NamedDecl *Param = TemplateParams->getParam(Pack.Index);
   if (Result.isNull()) {
 Info.Param = makeTemplateParameter(Param);
@@ -1003,9 +1026,12 @@ class PackDeductionScope {
   unsigned PackElements = 0;
   bool IsPartiallyExpanded = false;
   bool DeducePackIfNotAlreadyDeduced = false;
+  bool DeducedFromEarlierParameter = false;
+
   /// The number of expansions, if we have a fully-expanded pack in this scope.
   std::optional FixedNumExpansions;
 
+
   SmallVector Packs;
 };
 
@@ -4371,6 +4397,41 @@ Sema::TemplateDeductionResult 
Sema::DeduceTemplateArguments(
   // corresponding argument is a list?
   PackScope.nextPackElement();
 }
+  } else if (!IsTrailingPack && !PackScope.isPartiallyExpanded() &&
+ PackScope.isDeducedFromEarlierParameter() &&
+ !isa(ParamTypes[ParamIdx + 1])) {
+// [temp.deduct.general#3]
+// When all template arguments have been deduced
+// or obtained from default template arguments, all uses of template
+// parameters in the template parameter list of the template are
+// replaced with the corresponding deduced or default argument values
+//
+// If we have a trailing parameter pack, that has been deduced 
perviously
+// we substitute the pack here in a similar fashion as seen above with
+// the trailing parameter packs. The main difference here is that, in
+// this case we are not processing all of the remaining arguments. We
+// are only process as many arguments as much we have in the already
+// deduced parameter.
+SmallVector Unexpanded;
+collectUnexpandedParameterPacks(ParamPattern, Unexpanded);
+if (Unexpanded.size() == 0)
+  continue;
+
+std::optional ArgPosAfterSubstitution =
+PackScope.getSavedPackSize(getDepthAndIndex(Unexpanded[0]).second,
+   ParamPattern);
+if (!ArgPosAfterSubstitution)
+  continue;
+
+unsigned PackArgEnd = ArgIdx + *ArgPosAfterSubstitution;
+for (; ArgIdx < PackArgEnd && ArgIdx < Args.size(); ArgIdx++) {
+  ParamTypesForArgChecking.push_back(ParamPattern);
+  if (auto Result = DeduceCallArgument(ParamPattern, ArgIdx,
+   
/*ExplicitObjetArgument=*/false))
+return Result;
+
+  PackScope.nextPackElement();
+}
   }
 }
 

From 59a01f3be41a1d8efa11e0e31448887b5517

[clang] [clang] Only set the trailing bytes to zero when filling a partially … (PR #79502)

2024-01-26 Thread via cfe-commits

serge-sans-paille wrote:

> (Extra tests needed)

test added, ready for review

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


[clang] [llvm] [AIX][TLS] Disallow the use of -maix-small-local-exec-tls and -fno-data-sections (PR #79252)

2024-01-26 Thread via cfe-commits


@@ -12,6 +15,10 @@ entry:
 ; Check that the aix-small-local-exec-tls attribute is not supported on Linux 
and AIX (32-bit).
 ; CHECK-NOT-SUPPORTED: The aix-small-local-exec-tls attribute is only 
supported on AIX in 64-bit mode.
 
+; Check that the aix-small-local-exec-tls attribute is only supported when
+; data sections are enabled.
+; CHECK-UNSUPPORTED-NO-DATASEC: The aix-small-local-exec-tls attribute can 
only be specified with -data-sections.

stephenpeckham wrote:

```suggestion
; CHECK-UNSUPPORTED-NO-DATASEC: The aix-small-local-exec-tls attribute can only 
be specified with -fdata-sections.
```

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


[clang] [llvm] [AIX][TLS] Disallow the use of -maix-small-local-exec-tls and -fno-data-sections (PR #79252)

2024-01-26 Thread via cfe-commits


@@ -124,10 +124,23 @@ void PPCSubtarget::initSubtargetFeatures(StringRef CPU, 
StringRef TuneCPU,
   // Determine endianness.
   IsLittleEndian = TM.isLittleEndian();
 
-  if (HasAIXSmallLocalExecTLS && (!TargetTriple.isOSAIX() || !IsPPC64))
-report_fatal_error(
-  "The aix-small-local-exec-tls attribute is only supported on AIX in "
-  "64-bit mode.\n", false);
+  if (HasAIXSmallLocalExecTLS) {
+if (!TargetTriple.isOSAIX() || !IsPPC64)
+  report_fatal_error(
+  "The aix-small-local-exec-tls attribute is only supported on AIX in "
+  "64-bit mode.\n",
+  false);
+// The aix-small-local-exec-tls attribute should only be used with
+// -data-sections, as having data sections turned off with this option
+// is not ideal for performance. Moreover, the small-local-exec-tls region
+// is a limited resource, and should not be used for variables that may
+// be replaced.
+if (!TM.getDataSections())
+  report_fatal_error(
+  "The aix-small-local-exec-tls attribute can only be specified with "
+  "-data-sections.\n",

stephenpeckham wrote:

```suggestion
  "-fdata-sections.\n",
```

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


[clang] [clang] Add GCC-compatible code model names for sparc64 (PR #79485)

2024-01-26 Thread via cfe-commits

koachan wrote:

`embmedany` is already rejected by the driver at the moment:
```
error: unsupported argument 'embmedany' to option '-mcmodel=' for target 
'sparc64'
```

On the testing issue, however, would compiling LLVM with each of the code 
models + running codegen tests be enough to at least exercise the relevant 
parts (and see if there's still issues, etc.)?

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


[clang] [Clang] Implement P2718R0 "Lifetime extension in range-based for loops" (PR #76361)

2024-01-26 Thread via cfe-commits

cor3ntin wrote:

@yronglin Do you know when you will be able to get to this? thanks!

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


[clang] [lldb] [clang-tools-extra] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-26 Thread Erich Keane via cfe-commits

erichkeane wrote:

@bolshakov-a : The original bug has a good amount of analysis to it, so if you 
could see if there is a fix for it, else we probably do have to revert for that 
one and miss 18 with this patch.

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


[clang] [clang][analyzer] Fix argument invalidations in StreamChecker. (PR #79470)

2024-01-26 Thread Balázs Kéri via cfe-commits


@@ -0,0 +1,133 @@
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN: -analyzer-checker=core \
+// RUN: -analyzer-checker=alpha.unix.Stream \
+// RUN: -analyzer-checker=debug.StreamTester \
+// RUN: -analyzer-checker=debug.ExprInspection
+
+#include "Inputs/system-header-simulator.h"
+
+void clang_analyzer_eval(int);
+void clang_analyzer_dump(int);
+void clang_analyzer_warnIfReached(void);
+void StreamTesterChecker_make_feof_stream(FILE *);
+void StreamTesterChecker_make_ferror_stream(FILE *);
+
+void test_fread(void) {
+  FILE *F = fopen("file", "r+");
+  if (!F)
+return;
+
+  char Buf[3] = {10, 10, 10};
+  fread(Buf, 1, 3, F);
+  // this check applies to succes and failure
+  clang_analyzer_dump(Buf[0]); // expected-warning {{conj_$}} Should not 
preserve the previous value, thus should not be 10.
+  clang_analyzer_dump(Buf[2]); // expected-warning {{conj_$}}
+  if (feof(F)) {

balazske wrote:

At `ferror(F)` the next stream call should produce a "file position 
indeterminate" warning (this is tested in another file) that stops the 
analysis, buffer invalidation is not needed to be tested.

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


[clang] [Sema] Substitute parameter packs when deduced from function arguments (PR #79371)

2024-01-26 Thread via cfe-commits


@@ -431,6 +442,17 @@ namespace deduction_after_explicit_pack {
 i(0, 1, 2, 3, 4, 5); // expected-error {{no match}}
   }
 
+  template 
+  void bar(args_tag, type_identity_t..., int mid, 
type_identity_t...) {}

cor3ntin wrote:

I'd like to see a test for ```cpp
template 
void foo2(args_tag, args_tag, type_identity_t..., 
type_identity_t...) {}
```

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


[clang] [Sema] Substitute parameter packs when deduced from function arguments (PR #79371)

2024-01-26 Thread via cfe-commits

https://github.com/cor3ntin edited 
https://github.com/llvm/llvm-project/pull/79371
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema] Substitute parameter packs when deduced from function arguments (PR #79371)

2024-01-26 Thread Gábor Spaits via cfe-commits

spaits wrote:

I did some more digging. I saw that the test in the CI fails with permission 
errors.

```
| No symbol table is loaded.  Use the "file" command.
| warning: opening /proc/PID/mem file for lwp 4103309.4103309 failed: 
Permission denied (13)
| Traceback (most recent call last):
|   File 
"/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h5ngp-1/llvm-project/clang-ci/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py",
 line 123, in 
| gdb.execute("run")
| gdb.error: Warning:
| Cannot insert breakpoint 1.
| Cannot access memory at address 0x637c
```

I thought that maybe the problem is that, the program to be debugged by `dbg` 
does not compile with the compiler that includes my changes. I decided to just 
compile the test file with my modified compiler. I copied the test file. 
Removed one include that is only needed for manual debugging and recreated the 
command used in the CI as much as I could. The command looks like this now:
```
/home/spaits/repo/llvm-project/build/bin/clang++ -pthread 
--target=x86_64-unknown-linux-gnu /home/spaits/cpp/deb.cpp -o 
/home/spaits/cpp/deb.out -std=c++26 -Werror -Wall -Wctad-maybe-unsupported 
-Wextra -Wshadow -Wundef -Wunused-template -Wno-unused-command-line-argument 
-Wno-attributes -Wno-pessimizing-move -Wno-noexcept-type -Wno-atomic-alignment 
-Wno-reserved-module-identifier -Wdeprecated-copy -Wdeprecated-copy-dtor 
-Wno-user-defined-literals -Wno-tautological-compare -Wsign-compare 
-Wunused-variable -Wunused-parameter -Wunreachable-code 
-Wno-unused-local-typedef -Wno-local-type-template-args -Wno-c++11-extensions 
-Wno-unknown-pragmas -Wno-pass-failed -Wno-mismatched-new-delete 
-Wno-redundant-move -Wno-self-move -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER 
-D_LIBCPP_ENABLE_EXPERIMENTAL 
-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_NONE -Werror=thread-safety 
-Wuser-defined-warnings -g   -lc++ -latomic
0 spaits@work-laptop:~/cpp$ 
```
Because of the GCC 13+ prereq. I did not build libc++ for my self, but used the 
one available on my machine.
This way the file has compiled successfully.

I will still try to run the tests myself.

Until that if you have any idea what should I, do what wen possibly wrong pleas 
share that with me.

Thanks.

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


[clang] [Sema] Substitute parameter packs when deduced from function arguments (PR #79371)

2024-01-26 Thread via cfe-commits


@@ -4371,6 +4394,34 @@ Sema::TemplateDeductionResult 
Sema::DeduceTemplateArguments(
   // corresponding argument is a list?
   PackScope.nextPackElement();
 }
+  } else if (!IsTrailingPack && !PackScope.isPartiallyExpanded() &&
+ PackScope.isDeducedFromEarlierParameter()) {
+// [temp.deduct.general#3]
+// When all template arguments have been deduced
+// or obtained from default template arguments, all uses of template
+// parameters in the template parameter list of the template are
+// replaced with the corresponding deduced or default argument values
+//
+// If we have a trailing parameter pack, that has been deduced
+// previously we substitute the pack here in a similar fashion as
+// above with the trailing parameter packs. The main difference here is
+// that, in this case we are not processing all of the remaining
+// arguments. We are only process as many arguments as much we have in

cor3ntin wrote:

```suggestion
// arguments. We are only process as many arguments as we have in
```

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


[clang] [Sema] Substitute parameter packs when deduced from function arguments (PR #79371)

2024-01-26 Thread Gábor Spaits via cfe-commits

https://github.com/spaits updated 
https://github.com/llvm/llvm-project/pull/79371

From 3e0c3db0d8500e5f2111e3603da3d8f2b1cd261d Mon Sep 17 00:00:00 2001
From: Gabor Spaits 
Date: Wed, 24 Jan 2024 21:21:26 +0100
Subject: [PATCH 01/14] [Sema]Substitue template parameter packs when deduced
 from function parameter

---
 clang/lib/Sema/SemaTemplateDeduction.cpp | 63 +++-
 1 file changed, 62 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index e9e7ab5bb6698a..46fa9eece3747a 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -730,6 +730,7 @@ class PackDeductionScope {
   void addPack(unsigned Index) {
 // Save the deduced template argument for the parameter pack expanded
 // by this pack expansion, then clear out the deduction.
+DeducedFromEarlierParameter = !Deduced[Index].isNull();
 DeducedPack Pack(Index);
 Pack.Saved = Deduced[Index];
 Deduced[Index] = TemplateArgument();
@@ -858,6 +859,29 @@ class PackDeductionScope {
   Info.PendingDeducedPacks[Pack.Index] = Pack.Outer;
   }
 
+  std::optional getSavedPackSize(unsigned Index,
+   TemplateArgument Pattern) const {
+
+SmallVector Unexpanded;
+S.collectUnexpandedParameterPacks(Pattern, Unexpanded);
+if (Unexpanded.size() == 0 ||
+Packs[0].Saved.getKind() != clang::TemplateArgument::Pack)
+  return {};
+unsigned PackSize = Packs[0].Saved.pack_size();
+
+if (std::all_of(Packs.begin() + 1, Packs.end(),
+[&PackSize](auto P) {
+  return P.Saved.getKind() == TemplateArgument::Pack &&
+ P.Saved.pack_size() == PackSize;
+}))
+  return PackSize;
+return {};
+  }
+
+  /// Determine whether this pack has already been deduced from a previous
+  /// argument.
+  bool isDeducedFromEarlierParameter() const {return 
DeducedFromEarlierParameter;}
+
   /// Determine whether this pack has already been partially expanded into a
   /// sequence of (prior) function parameters / template arguments.
   bool isPartiallyExpanded() { return IsPartiallyExpanded; }
@@ -970,7 +994,6 @@ class PackDeductionScope {
 NewPack = Pack.DeferredDeduction;
 Result = checkDeducedTemplateArguments(S.Context, OldPack, NewPack);
   }
-
   NamedDecl *Param = TemplateParams->getParam(Pack.Index);
   if (Result.isNull()) {
 Info.Param = makeTemplateParameter(Param);
@@ -1003,9 +1026,12 @@ class PackDeductionScope {
   unsigned PackElements = 0;
   bool IsPartiallyExpanded = false;
   bool DeducePackIfNotAlreadyDeduced = false;
+  bool DeducedFromEarlierParameter = false;
+
   /// The number of expansions, if we have a fully-expanded pack in this scope.
   std::optional FixedNumExpansions;
 
+
   SmallVector Packs;
 };
 
@@ -4371,6 +4397,41 @@ Sema::TemplateDeductionResult 
Sema::DeduceTemplateArguments(
   // corresponding argument is a list?
   PackScope.nextPackElement();
 }
+  } else if (!IsTrailingPack && !PackScope.isPartiallyExpanded() &&
+ PackScope.isDeducedFromEarlierParameter() &&
+ !isa(ParamTypes[ParamIdx + 1])) {
+// [temp.deduct.general#3]
+// When all template arguments have been deduced
+// or obtained from default template arguments, all uses of template
+// parameters in the template parameter list of the template are
+// replaced with the corresponding deduced or default argument values
+//
+// If we have a trailing parameter pack, that has been deduced 
perviously
+// we substitute the pack here in a similar fashion as seen above with
+// the trailing parameter packs. The main difference here is that, in
+// this case we are not processing all of the remaining arguments. We
+// are only process as many arguments as much we have in the already
+// deduced parameter.
+SmallVector Unexpanded;
+collectUnexpandedParameterPacks(ParamPattern, Unexpanded);
+if (Unexpanded.size() == 0)
+  continue;
+
+std::optional ArgPosAfterSubstitution =
+PackScope.getSavedPackSize(getDepthAndIndex(Unexpanded[0]).second,
+   ParamPattern);
+if (!ArgPosAfterSubstitution)
+  continue;
+
+unsigned PackArgEnd = ArgIdx + *ArgPosAfterSubstitution;
+for (; ArgIdx < PackArgEnd && ArgIdx < Args.size(); ArgIdx++) {
+  ParamTypesForArgChecking.push_back(ParamPattern);
+  if (auto Result = DeduceCallArgument(ParamPattern, ArgIdx,
+   
/*ExplicitObjetArgument=*/false))
+return Result;
+
+  PackScope.nextPackElement();
+}
   }
 }
 

From 59a01f3be41a1d8efa11e0e31448887b55178f

[clang] [Sema] Substitute parameter packs when deduced from function arguments (PR #79371)

2024-01-26 Thread Erich Keane via cfe-commits
=?utf-8?q?Gábor?= Spaits
Message-ID:
In-Reply-To: 


erichkeane wrote:

> I did some more digging. I saw that the test in the CI fails with permission 
> errors.
> 
> ```
> | No symbol table is loaded.  Use the "file" command.
> | warning: opening /proc/PID/mem file for lwp 4103309.4103309 failed: 
> Permission denied (13)
> | Traceback (most recent call last):
> |   File 
> "/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-h5ngp-1/llvm-project/clang-ci/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py",
>  line 123, in 
> | gdb.execute("run")
> | gdb.error: Warning:
> | Cannot insert breakpoint 1.
> | Cannot access memory at address 0x637c
> ```
> 
> I thought that maybe the problem is that, the program to be debugged by `dbg` 
> does not compile with the compiler that includes my changes. I decided to 
> just compile the test file with my modified compiler. I copied the test file. 
> Removed one include that is only needed for manual debugging and recreated 
> the command used in the CI as much as I could. The command looks like this 
> now:
> 
> ```
> /home/spaits/repo/llvm-project/build/bin/clang++ -pthread 
> --target=x86_64-unknown-linux-gnu /home/spaits/cpp/deb.cpp -o 
> /home/spaits/cpp/deb.out -std=c++26 -Werror -Wall -Wctad-maybe-unsupported 
> -Wextra -Wshadow -Wundef -Wunused-template -Wno-unused-command-line-argument 
> -Wno-attributes -Wno-pessimizing-move -Wno-noexcept-type 
> -Wno-atomic-alignment -Wno-reserved-module-identifier -Wdeprecated-copy 
> -Wdeprecated-copy-dtor -Wno-user-defined-literals -Wno-tautological-compare 
> -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code 
> -Wno-unused-local-typedef -Wno-local-type-template-args -Wno-c++11-extensions 
> -Wno-unknown-pragmas -Wno-pass-failed -Wno-mismatched-new-delete 
> -Wno-redundant-move -Wno-self-move -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER 
> -D_LIBCPP_ENABLE_EXPERIMENTAL 
> -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_NONE -Werror=thread-safety 
> -Wuser-defined-warnings -g   -lc++ -latomic
> 0 spaits@work-laptop:~/cpp$ 
> ```
> 
> Because of the GCC 13+ prereq. I did not build libc++ for my self, but used 
> the one available on my machine. This way the file has compiled successfully.
> 
> I will still try to run the tests myself.
> 
> Until that if you have any idea what should I, do what wen possibly wrong 
> pleas share that with me.
> 
> Thanks.

It could very well just be a transient error/something that failed and has 
since been fixed.  See if it still happens after this pending build.

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


[clang] [Sema] Substitute parameter packs when deduced from function arguments (PR #79371)

2024-01-26 Thread via cfe-commits
=?utf-8?q?G=C3=A1bor?= Spaits
Message-ID:
In-Reply-To: 



@@ -858,6 +859,27 @@ class PackDeductionScope {
   Info.PendingDeducedPacks[Pack.Index] = Pack.Outer;
   }
 
+  // Return the size of the saved packs if all of them has the same size.
+  std::optional getSavedPackSizeIfAllEqual() const {
+if (Packs.size() == 0 ||
+Packs[0].Saved.getKind() != clang::TemplateArgument::Pack)

cor3ntin wrote:

when is `Packs[0].Saved.getKind() != clang::TemplateArgument::Pack` true?

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


[clang] [Clang] Implement P2718R0 "Lifetime extension in range-based for loops" (PR #76361)

2024-01-26 Thread via cfe-commits

https://github.com/yronglin updated 
https://github.com/llvm/llvm-project/pull/76361

>From 89eeeaea909ba8297236889e50936f8948dd82a4 Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Thu, 11 Jan 2024 23:28:32 +0800
Subject: [PATCH 1/2] [Clang] Implement P2718R0 "Lifetime extension in
 range-based for loops"

 Implement P2718R0 "Lifetime extension in range-based for loops" 
(https://wg21.link/P2718R0)

Differential Revision: https://reviews.llvm.org/D153701
---
 clang/docs/ReleaseNotes.rst   |   3 +
 clang/include/clang/Parse/Parser.h|   2 +-
 clang/include/clang/Sema/Sema.h   |  43 ++-
 clang/lib/Parse/ParseDecl.cpp |  19 +
 clang/lib/Parse/ParseStmt.cpp |   8 +-
 clang/lib/Sema/SemaExpr.cpp   |  22 +-
 clang/lib/Sema/SemaExprCXX.cpp|  47 ++-
 clang/lib/Sema/SemaInit.cpp   |   4 +
 clang/lib/Sema/SemaStmt.cpp   |  17 +-
 .../test/AST/ast-dump-for-range-lifetime.cpp  | 355 ++
 clang/test/CXX/special/class.temporary/p6.cpp | 234 
 11 files changed, 713 insertions(+), 41 deletions(-)
 create mode 100644 clang/test/AST/ast-dump-for-range-lifetime.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 392f694065a242b..01b581b26934ebe 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -195,6 +195,9 @@ C++23 Feature Support
 - Added a separate warning to warn the use of attributes on lambdas as a C++23 
extension
   in previous language versions: ``-Wc++23-lambda-attributes``.
 
+- Implemented `P2718R0: Lifetime extension in range-based for loops 
`_. Also
+  materialize temporary object which is a prvalue in discarded-value 
expression.
+
 C++2c Feature Support
 ^
 
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 9e2b452cbe05172..7bc2acd5e84d092 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -2398,7 +2398,7 @@ class Parser : public CodeCompletionHandler {
   struct ForRangeInit {
 SourceLocation ColonLoc;
 ExprResult RangeExpr;
-
+SmallVector LifetimeExtendTemps;
 bool ParsedForRangeDecl() { return !ColonLoc.isInvalid(); }
   };
   struct ForRangeInfo : ForRangeInit {
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 0db39333b0ee347..1f2a5a546821f8a 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1342,6 +1342,12 @@ class Sema final {
 /// context not already known to be immediately invoked.
 llvm::SmallPtrSet ReferenceToConsteval;
 
+/// P2718R0 - Lifetime extension in range-based for loops.
+/// MaterializeTemporaryExprs in for-range-init expression which need to
+/// extend lifetime. Add MaterializeTemporaryExpr* if the value of
+/// IsInLifetimeExtendingContext is true.
+SmallVector ForRangeLifetimeExtendTemps;
+
 /// \brief Describes whether we are in an expression constext which we have
 /// to handle differently.
 enum ExpressionKind {
@@ -1361,6 +1367,19 @@ class Sema final {
 // VLAs).
 bool InConditionallyConstantEvaluateContext = false;
 
+/// Whether we are currently in a context in which temporaries must be
+/// lifetime-extended (Eg. in a for-range initializer).
+bool IsInLifetimeExtendingContext = false;
+
+/// Whether we should materialize temporaries in discarded expressions.
+///
+/// [C++23][class.temporary]/p2.6 when a prvalue that has type other than 
cv
+/// void appears as a discarded-value expression ([expr.context]).
+///
+/// We do not materialize temporaries by default in order to avoid creating
+/// unnecessary temporary objects.
+bool MaterializePRValueInDiscardedExpression = false;
+
 // When evaluating immediate functions in the initializer of a default
 // argument or default member initializer, this is the declaration whose
 // default initializer is being evaluated and the location of the call
@@ -5245,13 +5264,11 @@ class Sema final {
 BFRK_Check
   };
 
-  StmtResult ActOnCXXForRangeStmt(Scope *S, SourceLocation ForLoc,
-  SourceLocation CoawaitLoc,
-  Stmt *InitStmt,
-  Stmt *LoopVar,
-  SourceLocation ColonLoc, Expr *Collection,
-  SourceLocation RParenLoc,
-  BuildForRangeKind Kind);
+  StmtResult ActOnCXXForRangeStmt(
+  Scope *S, SourceLocation ForLoc, SourceLocation CoawaitLoc,
+  Stmt *InitStmt, Stmt *LoopVar, SourceLocation ColonLoc, Expr *Collection,
+  SourceLocation RParenLoc, BuildForRangeKind Kind,
+  ArrayRef LifetimeExtendTemps = {});
   StmtResult BuildCXXForRangeStmt(SourceLocation ForLoc,

[clang] [Sema] Substitute parameter packs when deduced from function arguments (PR #79371)

2024-01-26 Thread via cfe-commits
=?utf-8?q?G=C3=A1bor?= Spaits
Message-ID:
In-Reply-To: 



@@ -858,6 +859,27 @@ class PackDeductionScope {
   Info.PendingDeducedPacks[Pack.Index] = Pack.Outer;
   }
 
+  // Return the size of the saved packs if all of them has the same size.
+  std::optional getSavedPackSizeIfAllEqual() const {
+if (Packs.size() == 0 ||
+Packs[0].Saved.getKind() != clang::TemplateArgument::Pack)

cor3ntin wrote:

for that matter when is `Packs.size() != 0` ?

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


[clang] [Clang] Implement P2718R0 "Lifetime extension in range-based for loops" (PR #76361)

2024-01-26 Thread via cfe-commits

yronglin wrote:

> @yronglin Do you know when you will be able to get to this? thanks!

Sorry for the lack of new actions for a long time. I have recently fixed some 
problems in the dependent context. I will try to complete the DefaultInit 
related functions and tests this weekend.

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


[clang] [Sema] Substitute parameter packs when deduced from function arguments (PR #79371)

2024-01-26 Thread Gábor Spaits via cfe-commits

https://github.com/spaits updated 
https://github.com/llvm/llvm-project/pull/79371

From 3e0c3db0d8500e5f2111e3603da3d8f2b1cd261d Mon Sep 17 00:00:00 2001
From: Gabor Spaits 
Date: Wed, 24 Jan 2024 21:21:26 +0100
Subject: [PATCH 01/15] [Sema]Substitue template parameter packs when deduced
 from function parameter

---
 clang/lib/Sema/SemaTemplateDeduction.cpp | 63 +++-
 1 file changed, 62 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index e9e7ab5bb6698a..46fa9eece3747a 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -730,6 +730,7 @@ class PackDeductionScope {
   void addPack(unsigned Index) {
 // Save the deduced template argument for the parameter pack expanded
 // by this pack expansion, then clear out the deduction.
+DeducedFromEarlierParameter = !Deduced[Index].isNull();
 DeducedPack Pack(Index);
 Pack.Saved = Deduced[Index];
 Deduced[Index] = TemplateArgument();
@@ -858,6 +859,29 @@ class PackDeductionScope {
   Info.PendingDeducedPacks[Pack.Index] = Pack.Outer;
   }
 
+  std::optional getSavedPackSize(unsigned Index,
+   TemplateArgument Pattern) const {
+
+SmallVector Unexpanded;
+S.collectUnexpandedParameterPacks(Pattern, Unexpanded);
+if (Unexpanded.size() == 0 ||
+Packs[0].Saved.getKind() != clang::TemplateArgument::Pack)
+  return {};
+unsigned PackSize = Packs[0].Saved.pack_size();
+
+if (std::all_of(Packs.begin() + 1, Packs.end(),
+[&PackSize](auto P) {
+  return P.Saved.getKind() == TemplateArgument::Pack &&
+ P.Saved.pack_size() == PackSize;
+}))
+  return PackSize;
+return {};
+  }
+
+  /// Determine whether this pack has already been deduced from a previous
+  /// argument.
+  bool isDeducedFromEarlierParameter() const {return 
DeducedFromEarlierParameter;}
+
   /// Determine whether this pack has already been partially expanded into a
   /// sequence of (prior) function parameters / template arguments.
   bool isPartiallyExpanded() { return IsPartiallyExpanded; }
@@ -970,7 +994,6 @@ class PackDeductionScope {
 NewPack = Pack.DeferredDeduction;
 Result = checkDeducedTemplateArguments(S.Context, OldPack, NewPack);
   }
-
   NamedDecl *Param = TemplateParams->getParam(Pack.Index);
   if (Result.isNull()) {
 Info.Param = makeTemplateParameter(Param);
@@ -1003,9 +1026,12 @@ class PackDeductionScope {
   unsigned PackElements = 0;
   bool IsPartiallyExpanded = false;
   bool DeducePackIfNotAlreadyDeduced = false;
+  bool DeducedFromEarlierParameter = false;
+
   /// The number of expansions, if we have a fully-expanded pack in this scope.
   std::optional FixedNumExpansions;
 
+
   SmallVector Packs;
 };
 
@@ -4371,6 +4397,41 @@ Sema::TemplateDeductionResult 
Sema::DeduceTemplateArguments(
   // corresponding argument is a list?
   PackScope.nextPackElement();
 }
+  } else if (!IsTrailingPack && !PackScope.isPartiallyExpanded() &&
+ PackScope.isDeducedFromEarlierParameter() &&
+ !isa(ParamTypes[ParamIdx + 1])) {
+// [temp.deduct.general#3]
+// When all template arguments have been deduced
+// or obtained from default template arguments, all uses of template
+// parameters in the template parameter list of the template are
+// replaced with the corresponding deduced or default argument values
+//
+// If we have a trailing parameter pack, that has been deduced 
perviously
+// we substitute the pack here in a similar fashion as seen above with
+// the trailing parameter packs. The main difference here is that, in
+// this case we are not processing all of the remaining arguments. We
+// are only process as many arguments as much we have in the already
+// deduced parameter.
+SmallVector Unexpanded;
+collectUnexpandedParameterPacks(ParamPattern, Unexpanded);
+if (Unexpanded.size() == 0)
+  continue;
+
+std::optional ArgPosAfterSubstitution =
+PackScope.getSavedPackSize(getDepthAndIndex(Unexpanded[0]).second,
+   ParamPattern);
+if (!ArgPosAfterSubstitution)
+  continue;
+
+unsigned PackArgEnd = ArgIdx + *ArgPosAfterSubstitution;
+for (; ArgIdx < PackArgEnd && ArgIdx < Args.size(); ArgIdx++) {
+  ParamTypesForArgChecking.push_back(ParamPattern);
+  if (auto Result = DeduceCallArgument(ParamPattern, ArgIdx,
+   
/*ExplicitObjetArgument=*/false))
+return Result;
+
+  PackScope.nextPackElement();
+}
   }
 }
 

From 59a01f3be41a1d8efa11e0e31448887b55178f

[clang] [Sema] Substitute parameter packs when deduced from function arguments (PR #79371)

2024-01-26 Thread Gábor Spaits via cfe-commits


@@ -431,6 +442,17 @@ namespace deduction_after_explicit_pack {
 i(0, 1, 2, 3, 4, 5); // expected-error {{no match}}
   }
 
+  template 
+  void bar(args_tag, type_identity_t..., int mid, 
type_identity_t...) {}

spaits wrote:

Added the test. It also works.

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


[clang] [Clang] Implement P2718R0 "Lifetime extension in range-based for loops" (PR #76361)

2024-01-26 Thread via cfe-commits


@@ -1361,6 +1367,20 @@ class Sema final {
 // VLAs).
 bool InConditionallyConstantEvaluateContext = false;
 
+/// Whether we are currently in a context in which all temporaries must be
+/// lifetime-extended, even if they're not bound to a reference (for 
example,
+/// in a for-range initializer).
+bool IsInLifetimeExtendingContext = false;
+
+/// Whether we should materialize temporaries in discarded expressions.
+///
+/// [C++23][class.temporary]/p2.6 when a prvalue that has type other than 
cv
+/// void appears as a discarded-value expression ([expr.context]).
+///
+/// We do not materialize temporaries by default in order to avoid creating
+/// unnecessary temporary objects.
+bool MaterializePRValueInDiscardedExpression = false;

yronglin wrote:

I think this variable and related function 
`needMaterializePRValueInDiscardedExpression()` should be renamed to  
`NeedMaterializePRValue` and `needMaterializePRValue()` , then it can use in 
other cases.

In [class.temporary P2][http://eel.is/c++draft/class.temporary#2]

The materialization of a temporary object is generally delayed as long as 
possible in order to avoid creating unnecessary temporary 
objects[.](http://eel.is/c++draft/class.temporary#2.sentence-1)
[Note [3](http://eel.is/c++draft/class.temporary#note-3): Temporary objects are 
materialized:
[(2.1)](http://eel.is/c++draft/class.temporary#2.1)
when binding a reference to a prvalue 
([[dcl.init.ref]](http://eel.is/c++draft/dcl.init.ref), 
[[expr.type.conv]](http://eel.is/c++draft/expr.type.conv), 
[[expr.dynamic.cast]](http://eel.is/c++draft/expr.dynamic.cast), 
[[expr.static.cast]](http://eel.is/c++draft/expr.static.cast), 
[[expr.const.cast]](http://eel.is/c++draft/expr.const.cast), 
[[expr.cast]](http://eel.is/c++draft/expr.cast)),
[(2.2)](http://eel.is/c++draft/class.temporary#2.2)
when performing member access on a class prvalue 
([[expr.ref]](http://eel.is/c++draft/expr.ref), 
[[expr.mptr.oper]](http://eel.is/c++draft/expr.mptr.oper)),
[(2.3)](http://eel.is/c++draft/class.temporary#2.3)
when performing an array-to-pointer conversion or subscripting on an array 
prvalue ([[conv.array]](http://eel.is/c++draft/conv.array), 
[[expr.sub]](http://eel.is/c++draft/expr.sub)),
[(2.4)](http://eel.is/c++draft/class.temporary#2.4)
when initializing an object of type std​::​initializer_list from a 
[braced-init-list](http://eel.is/c++draft/dcl.init.general#nt:braced-init-list) 
([[dcl.init.list]](http://eel.is/c++draft/dcl.init.list)),
[(2.5)](http://eel.is/c++draft/class.temporary#2.5)
for certain unevaluated operands 
([[expr.typeid]](http://eel.is/c++draft/expr.typeid), 
[[expr.sizeof]](http://eel.is/c++draft/expr.sizeof)), and
[(2.6)](http://eel.is/c++draft/class.temporary#2.6)
when a prvalue that has type other than cv void appears as a discarded-value 
expression 
([[expr.context]](http://eel.is/c++draft/expr.context))[.](http://eel.is/c++draft/class.temporary#2.sentence-2)
— end note]

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


[clang] [Clang] Implement P2718R0 "Lifetime extension in range-based for loops" (PR #76361)

2024-01-26 Thread via cfe-commits

https://github.com/yronglin edited 
https://github.com/llvm/llvm-project/pull/76361
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] Allow specifying what headers are always included via "" or <> (PR #67749)

2024-01-26 Thread kleines Filmröllchen via cfe-commits

kleinesfilmroellchen wrote:

> Sorry, I'm still struggling with Github reviews compared to Phabricator... 
> how do I get to an interdiff showing the latest version of the patch compared 
> to the version I reviewed?

I'm fairly sure that GitHub has no built-in feature for this; I've never used 
it for my own reviews but it's unfortunate that that is missing of course.

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


[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-01-26 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

The newest version of this patch still doesn't work correctly. Switching the 
new `LoadExternalSpecializationsLazily` to disabled by default (somehow the 
argument didn't work on its own) instead crashes, most of the cases involving 
`MultiOnDiskHashTable`. I suspect some kind of memory error maybe? Sorry to not 
be more helpful at the moment...

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


[clang] [Sema] Substitute parameter packs when deduced from function arguments (PR #79371)

2024-01-26 Thread Gábor Spaits via cfe-commits


@@ -858,6 +859,27 @@ class PackDeductionScope {
   Info.PendingDeducedPacks[Pack.Index] = Pack.Outer;
   }
 
+  // Return the size of the saved packs if all of them has the same size.
+  std::optional getSavedPackSizeIfAllEqual() const {
+if (Packs.size() == 0 ||
+Packs[0].Saved.getKind() != clang::TemplateArgument::Pack)

spaits wrote:

The reason I added them is because I wanted to be careful. What if someone 
constructs a `PackDeductionScope` with a non pack `TemplateArgument`.

Should I replace them with insertions?

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


[clang] [Sema] Substitute parameter packs when deduced from function arguments (PR #79371)

2024-01-26 Thread Gábor Spaits via cfe-commits

https://github.com/spaits edited https://github.com/llvm/llvm-project/pull/79371
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [flang] [clang-tools-extra] [flang] add SYSTEM runtime and lowering intrinsics support (PR #74309)

2024-01-26 Thread Yi Wu via cfe-commits

https://github.com/yi-wu-arm updated 
https://github.com/llvm/llvm-project/pull/74309

>From 14f8c3e38791cc6b06455b8beffe37a6f7105e03 Mon Sep 17 00:00:00 2001
From: Yi Wu 
Date: Mon, 4 Dec 2023 10:32:03 +
Subject: [PATCH 01/18] Add SYSTEM runtime and lowering intrinsic support

Calls std::system() function and pass the command,
cmd on Windows or shell on Linux.
Command parameter is required, exitstatus is optional.
call system(command)
call system(command, exitstatus)
---
 flang/docs/Intrinsics.md  |  2 +-
 .../flang/Optimizer/Builder/IntrinsicCall.h   |  1 +
 .../flang/Optimizer/Builder/Runtime/Command.h |  5 +++
 flang/include/flang/Runtime/command.h |  5 +++
 flang/lib/Evaluate/intrinsics.cpp | 16 +---
 flang/lib/Optimizer/Builder/IntrinsicCall.cpp | 22 ++
 .../lib/Optimizer/Builder/Runtime/Command.cpp | 13 ++
 flang/runtime/command.cpp | 19 +
 flang/test/Lower/Intrinsics/system.f90| 39 ++
 flang/unittests/Runtime/CommandTest.cpp   | 41 +++
 10 files changed, 157 insertions(+), 6 deletions(-)
 create mode 100644 flang/test/Lower/Intrinsics/system.f90

diff --git a/flang/docs/Intrinsics.md b/flang/docs/Intrinsics.md
index fef2b4ea4dd8c85..871332399628e92 100644
--- a/flang/docs/Intrinsics.md
+++ b/flang/docs/Intrinsics.md
@@ -751,7 +751,7 @@ This phase currently supports all the intrinsic procedures 
listed above but the
 | Object characteristic inquiry functions | ALLOCATED, ASSOCIATED, 
EXTENDS_TYPE_OF, IS_CONTIGUOUS, PRESENT, RANK, SAME_TYPE, STORAGE_SIZE |
 | Type inquiry intrinsic functions | BIT_SIZE, DIGITS, EPSILON, HUGE, KIND, 
MAXEXPONENT, MINEXPONENT, NEW_LINE, PRECISION, RADIX, RANGE, TINY|
 | Non-standard intrinsic functions | AND, OR, XOR, SHIFT, ZEXT, IZEXT, COSD, 
SIND, TAND, ACOSD, ASIND, ATAND, ATAN2D, COMPL, EQV, NEQV, INT8, JINT, JNINT, 
KNINT, QCMPLX, DREAL, DFLOAT, QEXT, QFLOAT, QREAL, DNUM, NUM, JNUM, KNUM, QNUM, 
RNUM, RAN, RANF, ILEN, SIZEOF, MCLOCK, SECNDS, COTAN, IBCHNG, ISHA, ISHC, ISHL, 
IXOR, IARG, IARGC, NARGS, GETPID, NUMARG, BADDRESS, IADDR, CACHESIZE, EOF, 
FP_CLASS, INT_PTR_KIND, ISNAN, MALLOC |
-| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, 
SYSTEM_CLOCK |
+| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, 
SYSTEM, SYSTEM_CLOCK |
 | Atomic intrinsic subroutines | ATOMIC_ADD |
 | Collective intrinsic subroutines | CO_REDUCE |
 
diff --git a/flang/include/flang/Optimizer/Builder/IntrinsicCall.h 
b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
index 5065f11ae9e7264..669d076c3e0e7d8 100644
--- a/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
+++ b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
@@ -321,6 +321,7 @@ struct IntrinsicLibrary {
   fir::ExtendedValue genStorageSize(mlir::Type,
 llvm::ArrayRef);
   fir::ExtendedValue genSum(mlir::Type, llvm::ArrayRef);
+  void genSystem(mlir::ArrayRef args);
   void genSystemClock(llvm::ArrayRef);
   mlir::Value genTand(mlir::Type, llvm::ArrayRef);
   mlir::Value genTrailz(mlir::Type, llvm::ArrayRef);
diff --git a/flang/include/flang/Optimizer/Builder/Runtime/Command.h 
b/flang/include/flang/Optimizer/Builder/Runtime/Command.h
index 976fb3aa0b6fbb7..9d6a39639844fc7 100644
--- a/flang/include/flang/Optimizer/Builder/Runtime/Command.h
+++ b/flang/include/flang/Optimizer/Builder/Runtime/Command.h
@@ -53,5 +53,10 @@ mlir::Value genGetEnvVariable(fir::FirOpBuilder &, 
mlir::Location,
   mlir::Value length, mlir::Value trimName,
   mlir::Value errmsg);
 
+/// Generate a call to System runtime function which implements
+/// the non-standard System GNU extension.
+void genSystem(fir::FirOpBuilder &, mlir::Location, mlir::Value command,
+   mlir::Value exitstat);
+
 } // namespace fir::runtime
 #endif // FORTRAN_OPTIMIZER_BUILDER_RUNTIME_COMMAND_H
diff --git a/flang/include/flang/Runtime/command.h 
b/flang/include/flang/Runtime/command.h
index c67d171c8e2f1b8..f325faa7bd09fa1 100644
--- a/flang/include/flang/Runtime/command.h
+++ b/flang/include/flang/Runtime/command.h
@@ -55,6 +55,11 @@ std::int32_t RTNAME(GetEnvVariable)(const Descriptor &name,
 const Descriptor *value = nullptr, const Descriptor *length = nullptr,
 bool trim_name = true, const Descriptor *errmsg = nullptr,
 const char *sourceFile = nullptr, int line = 0);
+
+// Calls std::system()
+void RTNAME(System)(const Descriptor *command = nullptr,
+const Descriptor *exitstat = nullptr, const char *sourceFile = nullptr,
+int line = 0);
 }
 } // namespace Fortran::runt

[clang] [Sema] Substitute parameter packs when deduced from function arguments (PR #79371)

2024-01-26 Thread via cfe-commits
=?utf-8?q?Gábor?= Spaits,Gabor Spaits 
Message-ID:
In-Reply-To: 



@@ -858,6 +859,27 @@ class PackDeductionScope {
   Info.PendingDeducedPacks[Pack.Index] = Pack.Outer;
   }
 
+  // Return the size of the saved packs if all of them has the same size.
+  std::optional getSavedPackSizeIfAllEqual() const {
+if (Packs.size() == 0 ||
+Packs[0].Saved.getKind() != clang::TemplateArgument::Pack)

cor3ntin wrote:

I think you can remove it entirely, there is an assert in `.pack_size();` - 
that should simplify that code a bit !

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


  1   2   3   4   >