[clang] Document runtime config directory options (PR #66593)

2023-09-17 Thread via cfe-commits

https://github.com/xbjfk created https://github.com/llvm/llvm-project/pull/66593

In the clang user manual the build options `CLANG_CONFIG_FILE_USER_DIR` and 
`CLANG_CONFIG_FILE_SYSTEM_DIR` are documented, but the run time overrides 
`--config-user-dir` and `--config-system-dir` are not.

I have updated the manual to add these run time arguments.

>From c21b4281428e2a76b09c532ae1dc23101dd22c0e Mon Sep 17 00:00:00 2001
From: Reagan Bohan 
Date: Sun, 17 Sep 2023 21:19:33 +1200
Subject: [PATCH] Document runtime config directory options

---
 clang/docs/UsersManual.rst | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 25bbd72c81f7a3b..e180f77793e80b7 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -944,10 +944,13 @@ treated as a file name and is searched for sequentially 
in the directories:
 - system directory,
 - the directory where Clang executable resides.
 
-Both user and system directories for configuration files are specified during
-clang build using CMake parameters, ``CLANG_CONFIG_FILE_USER_DIR`` and
-``CLANG_CONFIG_FILE_SYSTEM_DIR`` respectively. The first file found is used.
-It is an error if the required file cannot be found.
+Both user and system directories for configuration files can be specified
+either during build or during runtime. At build time, use
+``CLANG_CONFIG_FILE_USER_DIR`` and ``CLANG_CONFIG_FILE_SYSTEM_DIR``. At run
+time use the ``--config-user-dir=`` and ``--config-system-dir=`` command line
+options. Specifying config directories at runtime overrides the config
+directories set at build time The first file found is used. It is an error if
+the required file cannot be found.
 
 The default configuration files are searched for in the same directories
 following the rules described in the next paragraphs. Loading default

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


[clang] Document runtime config directory options (PR #66593)

2023-09-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes

In the clang user manual the build options `CLANG_CONFIG_FILE_USER_DIR` and 
`CLANG_CONFIG_FILE_SYSTEM_DIR` are documented, but the run time overrides 
`--config-user-dir` and `--config-system-dir` are not.

I have updated the manual to add these run time arguments.
---
Full diff: https://github.com/llvm/llvm-project/pull/66593.diff


1 Files Affected:

- (modified) clang/docs/UsersManual.rst (+7-4) 


``diff
diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 25bbd72c81f7a3b..e180f77793e80b7 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -944,10 +944,13 @@ treated as a file name and is searched for sequentially 
in the directories:
 - system directory,
 - the directory where Clang executable resides.
 
-Both user and system directories for configuration files are specified during
-clang build using CMake parameters, ``CLANG_CONFIG_FILE_USER_DIR`` and
-``CLANG_CONFIG_FILE_SYSTEM_DIR`` respectively. The first file found is used.
-It is an error if the required file cannot be found.
+Both user and system directories for configuration files can be specified
+either during build or during runtime. At build time, use
+``CLANG_CONFIG_FILE_USER_DIR`` and ``CLANG_CONFIG_FILE_SYSTEM_DIR``. At run
+time use the ``--config-user-dir=`` and ``--config-system-dir=`` command line
+options. Specifying config directories at runtime overrides the config
+directories set at build time The first file found is used. It is an error if
+the required file cannot be found.
 
 The default configuration files are searched for in the same directories
 following the rules described in the next paragraphs. Loading default

``




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


[clang] de56ceb - [clang] fix stray whitespace in release notes to fix CI failure

2023-09-17 Thread via cfe-commits

Author: Nuno Lopes
Date: 2023-09-17T10:25:53+01:00
New Revision: de56ceb54a14487245ec70d2a291182a9501d9ba

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

LOG: [clang] fix stray whitespace in release notes to fix CI failure

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e9bfefd40bbbf82..d47d664c062c204 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -283,10 +283,10 @@ Bug Fixes to C++ Support
 - Clang now properly handles out of line template specializations when there is
   a non-template inner-class between the function and the class template.
   (`#65810 `_)
-  
-- Clang now properly converts static lambda call operator to function 
-  pointer on win32.
-  (`#62594 `_)  
+
+- Clang now properly converts static lambda call operator to function
+  pointers on win32.
+  (`#62594 `_)
 
 Bug Fixes to AST Handling
 ^



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


[PATCH] D156605: [clangd][CodeComplete] Improve FunctionCanBeCall

2023-09-17 Thread Younan Zhang via Phabricator via cfe-commits
zyounan updated this revision to Diff 556909.
zyounan marked 2 inline comments as done.
zyounan added a comment.

Address comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156605/new/

https://reviews.llvm.org/D156605

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/CodeCompletionStrings.cpp
  clang-tools-extra/clangd/CodeCompletionStrings.h
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/clangd/unittests/CodeCompletionStringsTests.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/member-access.cpp
  clang/unittests/Sema/CodeCompleteTest.cpp

Index: clang/unittests/Sema/CodeCompleteTest.cpp
===
--- clang/unittests/Sema/CodeCompleteTest.cpp
+++ clang/unittests/Sema/CodeCompleteTest.cpp
@@ -60,7 +60,10 @@
 for (unsigned I = 0; I < NumResults; ++I) {
   auto R = Results[I];
   if (R.Kind == CodeCompletionResult::RK_Declaration) {
-if (const auto *FD = llvm::dyn_cast(R.getDeclaration())) {
+auto *ND = R.getDeclaration();
+if (auto *Template = llvm::dyn_cast(ND))
+  ND = Template->getTemplatedDecl();
+if (const auto *FD = llvm::dyn_cast(ND)) {
   CompletedFunctionDecl D;
   D.Name = FD->getNameAsString();
   D.CanBeCall = R.FunctionCanBeCall;
@@ -191,6 +194,10 @@
 struct Foo {
   static int staticMethod();
   int method() const;
+  template 
+  T generic(U, V);
+  template 
+  static T staticGeneric();
   Foo() {
 this->$canBeCall^
 $canBeCall^
@@ -199,6 +206,8 @@
 };
 
 struct Derived : Foo {
+  using Foo::method;
+  using Foo::generic;
   Derived() {
 Foo::$canBeCall^
   }
@@ -207,15 +216,29 @@
 struct OtherClass {
   OtherClass() {
 Foo f;
+Derived d;
 f.$canBeCall^
+; // Prevent parsing as 'f.f'
+f.Foo::$canBeCall^
 &Foo::$cannotBeCall^
+;
+d.Foo::$canBeCall^
+;
+d.Derived::$canBeCall^
   }
 };
 
 int main() {
   Foo f;
+  Derived d;
   f.$canBeCall^
+  ; // Prevent parsing as 'f.f'
+  f.Foo::$canBeCall^
   &Foo::$cannotBeCall^
+  ;
+  d.Foo::$canBeCall^
+  ;
+  d.Derived::$canBeCall^
 }
 )cpp");
 
@@ -223,12 +246,16 @@
 auto Results = CollectCompletedFunctions(Code.code(), P);
 EXPECT_THAT(Results, Contains(AllOf(named("method"), isStatic(false),
 canBeCall(true;
+EXPECT_THAT(Results, Contains(AllOf(named("generic"), isStatic(false),
+canBeCall(true;
   }
 
   for (const auto &P : Code.points("cannotBeCall")) {
 auto Results = CollectCompletedFunctions(Code.code(), P);
 EXPECT_THAT(Results, Contains(AllOf(named("method"), isStatic(false),
 canBeCall(false;
+EXPECT_THAT(Results, Contains(AllOf(named("generic"), isStatic(false),
+canBeCall(false;
   }
 
   // static method can always be a call
@@ -236,6 +263,8 @@
 auto Results = CollectCompletedFunctions(Code.code(), P);
 EXPECT_THAT(Results, Contains(AllOf(named("staticMethod"), isStatic(true),
 canBeCall(true;
+EXPECT_THAT(Results, Contains(AllOf(named("staticGeneric"), isStatic(true),
+canBeCall(true;
   }
 }
 
Index: clang/test/CodeCompletion/member-access.cpp
===
--- clang/test/CodeCompletion/member-access.cpp
+++ clang/test/CodeCompletion/member-access.cpp
@@ -341,3 +341,14 @@
   // RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits -code-completion-at=%s:339:10 %s -o - | FileCheck -check-prefix=CHECK-FIELD-DECLARED-VIA-USING %s
   // CHECK-FIELD-DECLARED-VIA-USING: [#int#]field (requires fix-it: {339:8-339:9} to "->")
 }
+
+namespace function_can_be_call {
+  struct S {
+template 
+T foo(U, V);
+  };
+
+  &S::f
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:351:7 %s -o - | FileCheck -check-prefix=CHECK_FUNCTION_CAN_BE_CALL %s
+  // CHECK_FUNCTION_CAN_BE_CALL: COMPLETION: foo : [#T#]foo<<#typename T#>, <#typename U#>{#, <#typename V#>#}>(<#U#>, <#V#>)
+}
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -310,6 +310,23 @@
   bool isInterestingDecl(const NamedDecl *ND,
  bool &AsNestedNameSpecifier) const;
 
+  /// Decide whether or not a use of function Decl can be a call.
+  ///
+  /// \param ND the function declaration.
+  ///
+  /// \param BaseExprType the object type in a member access expression,
+  /// if

[PATCH] D156605: [clangd][CodeComplete] Improve FunctionCanBeCall

2023-09-17 Thread Younan Zhang via Phabricator via cfe-commits
zyounan added a comment.

Thank you Nathan for your constructive opinions! I've updated this patch again, 
hopefully this becomes better.




Comment at: clang/lib/Sema/SemaCodeComplete.cpp:1387
 
-  // When completing a non-static member function (and not via
-  // dot/arrow member access) and we're not inside that class' scope,
-  // it can't be a call.
+  // Decide whether or not a non-static member function can be a call.
   if (CompletionContext.getKind() == clang::CodeCompletionContext::CCC_Symbol) 
{

nridge wrote:
> zyounan wrote:
> > sammccall wrote:
> > > This is confusing: the `CCC_Symbol` test is part of the specific 
> > > heuristics being used (it's the "not via dot/arrow member access" part, 
> > > right?) but you've moved the comment explaining what it does.
> > > 
> > > Also this function is just getting too long, and we're inlining more 
> > > complicated control flow here.
> > > Can we extract a function?
> > > 
> > > ```
> > > const auto *Method = ...;
> > > if (Method & !Method->isStatic()) {
> > >   R.FunctionCanBeCall = canMethodBeCalled(...);
> > > }
> > > ```
> > > it's the "not via dot/arrow member access" part
> > 
> > (Sorry for being unaware of the historical context). But I think 
> > `CCC_Symbol` should mean "we're completing a name such as a function or 
> > type name" per its comment. The heuristic for dot/arrow member access 
> > actually lies on the next line, i.e., if the completing decl is a 
> > CXXMethodDecl.
> > 
> > > Can we extract a function?
> > 
> > Sure. 
> The check for `CompletionContext.getKind()` is in fact a part of the 
> heuristic:
> 
>  * for `f.method`, the kind is `CCC_DotMemberAccess`
>  * for `f->method`, the kind is `CCC_ArrowMemberAccess`
>  * for `f.Foo::method` and `f->Foo::method`, the kind is `CCC_Symbol`
> 
> (I realize that's a bit inconsistent. Maybe the `f.Foo::` and `f->Foo::` 
> cases should be using `DotMemberAccess` and `ArrowMemberAccess` as well? 
> Anyways, that's a pre-existing issue.)
> 
> So, the `if (CompletionContext.getKind() == 
> clang::CodeCompletionContext::CCC_Symbol)` check is what currently makes sure 
> that in the `f.method` and `f->method` cases, we just keep `FunctionCanBeCall 
> = true` without having to check any context or expression type.
> 
> I think it may be clearest to move this entire `if` block into the new 
> function (whose name can be generalized to `canBeCall` or similar), and here 
> just unconditionally set `R.FunctionCanBeCall = canBeCall(CompletionContext, 
> /* other things */)`.
> I think it may be clearest to move this entire if block into the new function

Nice suggestion. I'll take it.



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:3577
   // containing all of the arguments up to the first deducible argument.
+  // Or, if this isn't a call, emit all the template arguments
+  // to disambiguate the (potential) overloads.

zyounan wrote:
> nridge wrote:
> > zyounan wrote:
> > > nridge wrote:
> > > > 1. If this is not a call, we can avoid running the 
> > > > `Sema::MarkDeducedTemplateParameters` operation altogether.
> > > > 
> > > > 2. A future improvement we could consider: if this is not a call, try 
> > > > to detect cases where the template parameters can be deduced from the 
> > > > surrounding context (["Deducing template arguments taking the address 
> > > > of a function template 
> > > > "](https://eel.is/c++draft/temp.deduct.funcaddr)). Maybe add a FIXME 
> > > > for this?
> > > > avoid running the Sema::MarkDeducedTemplateParameters operation 
> > > > altogether
> > > 
> > > I think doing so could cause too many adjustments to the flow, and I'm 
> > > afraid that the `Sema::MarkDeducedTemplateParameters` would be required 
> > > again when we decide to implement point 2.
> > > 
> > > I'm adding a FIXME anyway but leave the first intact. However, I'd be 
> > > happy to rearrange the logic flow if you insist.
> > I realized there's actually an open question here: if `FunctionCanBeCall == 
> > false`, do we want to include **all** the template parameters, or just the 
> > non-deducible ones?
> > 
> > Let's consider an example:
> > 
> > ```
> > class Foo {
> >   template 
> >   T convertTo(U from);
> > };
> > 
> > void bar() {
> >   Foo::^
> > }
> > ```
> > 
> > Here, `U` can be deduced but `T` cannot.
> > 
> > The current behaviour is to complete `convertTo`. That seems appropriate 
> > for a **call**, since `U` will be deduced from the call. But since this is 
> > not a call, wouldn't it be  better to complete `convertTo`?
> > But since this is not a call, wouldn't it be better to complete 
> > convertTo?
> 
> (Ugh, this is exactly this patch's initial intention, but how...?)
> 
> Oh, I made a mistake here: I presumed `LastDeducibleArgument` would always be 
> 0 if we're in a non-callable context, but this is wrong! This variable is 
> calculated based on the function parameters, which ought to be equal

[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)

2023-09-17 Thread via cfe-commits

https://github.com/5chmidti updated 
https://github.com/llvm/llvm-project/pull/66583

>From 8f5e9e6024b0db8f251625669adbc5d607da83cb Mon Sep 17 00:00:00 2001
From: Julian Schmidt <44101708+5chmi...@users.noreply.github.com>
Date: Sat, 16 Sep 2023 16:24:13 +0200
Subject: [PATCH 1/4] [clang-tidy] add modernize-use-std-numbers check

This check finds constants and function calls to math functions that can be 
replaced
with c++20's mathematical constants ('numbers' header) and offers fixit-hints.
Does not match the use of variables or macros with that value and instead, 
offers a replacement
at the definition of said variables and macros.
---
 .../clang-tidy/modernize/CMakeLists.txt   |   1 +
 .../modernize/ModernizeTidyModule.cpp |   3 +
 .../modernize/UseStdNumbersCheck.cpp  | 377 ++
 .../clang-tidy/modernize/UseStdNumbersCheck.h |  37 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |   6 +
 .../docs/clang-tidy/checks/list.rst   |   3 +-
 .../checks/modernize/use-std-numbers.rst  |  25 ++
 .../checkers/modernize/use-std-numbers.cpp| 205 ++
 8 files changed, 656 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
 create mode 100644 clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-numbers.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-numbers.cpp

diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 717c400c4790330..d82353d74fbd0d4 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -16,6 +16,7 @@ add_clang_library(clangTidyModernizeModule
   MakeSharedCheck.cpp
   MakeSmartPtrCheck.cpp
   MakeUniqueCheck.cpp
+  UseStdNumbersCheck.cpp
   ModernizeTidyModule.cpp
   PassByValueCheck.cpp
   RawStringLiteralCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 73751cf2705068d..73584e20166f66a 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -18,6 +18,7 @@
 #include "MacroToEnumCheck.h"
 #include "MakeSharedCheck.h"
 #include "MakeUniqueCheck.h"
+#include "UseStdNumbersCheck.h"
 #include "PassByValueCheck.h"
 #include "RawStringLiteralCheck.h"
 #include "RedundantVoidArgCheck.h"
@@ -65,6 +66,8 @@ class ModernizeModule : public ClangTidyModule {
 CheckFactories.registerCheck("modernize-macro-to-enum");
 CheckFactories.registerCheck("modernize-make-shared");
 CheckFactories.registerCheck("modernize-make-unique");
+CheckFactories.registerCheck(
+"modernize-use-std-numbers");
 CheckFactories.registerCheck("modernize-pass-by-value");
 CheckFactories.registerCheck("modernize-use-std-print");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
new file mode 100644
index 000..c23dc6671013bc3
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
@@ -0,0 +1,377 @@
+//===--- UseStdNumbersCheck.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 "UseStdNumbersCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersInternal.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/TokenKinds.h"
+#include "clang/Lex/PPCallbacks.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/Token.h"
+#include "clang/Tooling/Transformer/RewriteRule.h"
+#include "clang/Tooling/Transformer/Stencil.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/MathExtras.h"
+#include 
+#include 
+
+namespace {
+using namespace clang::ast_matchers;
+using clang::ast_matchers::internal::Matcher;
+using clang::transformer::addInclude;
+using clang::transformer::applyFirst;
+using clang::transformer::ASTEdit;
+using clang::transformer::cat;
+using clang::transformer::changeTo;
+using clang::transformer::edit;
+using clang::transformer::EditGenerator;
+using clang::transformer::flattenVector;
+using clang::transformer::RewriteRuleWith;
+using llvm::StringRef;
+
+constexpr double Pi = 3.1415926535897932384

[PATCH] D74094: Reapply: [IRGen] Emit lifetime intrinsics around temporary aggregate argument allocas

2023-09-17 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

>> So we can start by giving these objects full-expression lifetime, chase down 
>> any program bugs that that uncovers (which will all *unquestionably* be 
>> program bugs under the standard), and then gradually work on landing the 
>> more aggressive rule (perhaps even for non-trivial types).

maybe provide a new flag to control this behaviour?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74094/new/

https://reviews.llvm.org/D74094

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


[clang] [clang] Enable --print-supported-extensions for all targets (PR #66586)

2023-09-17 Thread Balint Cristian via cfe-commits

https://github.com/cbalint13 updated 
https://github.com/llvm/llvm-project/pull/66586

>From fbbc72c2f3d0cbcbb34eca2c9dcb6214076d38de Mon Sep 17 00:00:00 2001
From: Balint Cristian 
Date: Sun, 17 Sep 2023 14:06:05 +0300
Subject: [PATCH] [clang] Enable --print-supported-extensions for all targets

Signed-off-by: Balint Cristian 
---
 clang/include/clang/Driver/Options.td |  2 +-
 clang/lib/Driver/Driver.cpp   | 14 +--
 clang/lib/Driver/ToolChains/Clang.cpp |  7 
 .../test/Driver/print-supported-extensions.c  | 18 +---
 clang/tools/driver/cc1_main.cpp   | 42 ++-
 llvm/include/llvm/MC/MCSubtargetInfo.h|  6 +++
 6 files changed, 51 insertions(+), 38 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 553c7928c4f949e..431f2f5c4109232 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5277,7 +5277,7 @@ def print_supported_cpus : Flag<["-", "--"], 
"print-supported-cpus">,
   MarshallingInfoFlag>;
 def print_supported_extensions : Flag<["-", "--"], 
"print-supported-extensions">,
   Visibility<[ClangOption, CC1Option, CLOption]>,
-  HelpText<"Print supported -march extensions (RISC-V, AArch64 and ARM only)">,
+  HelpText<"Print supported -march extensions">,
   MarshallingInfoFlag>;
 def : Flag<["-"], "mcpu=help">, Alias;
 def : Flag<["-"], "mtune=help">, Alias;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 84b8fc7685fed42..5b6b14d175f5299 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4279,19 +4279,9 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
 // If --print-supported-cpus, -mcpu=? or -mtune=? is specified, build a
 // custom Compile phase that prints out supported cpu models and quits.
 //
-// If --print-supported-extensions is specified, call the helper function
-// RISCVMarchHelp in RISCVISAInfo.cpp that prints out supported extensions
-// and quits.
+// If --print-supported-extensions is specified, list all supported flags
+// within the target and quit.
 if (Arg *A = Args.getLastArg(Opt)) {
-  if (Opt == options::OPT_print_supported_extensions &&
-  !C.getDefaultToolChain().getTriple().isRISCV() &&
-  !C.getDefaultToolChain().getTriple().isAArch64() &&
-  !C.getDefaultToolChain().getTriple().isARM()) {
-C.getDriver().Diag(diag::err_opt_not_valid_on_target)
-<< "--print-supported-extensions";
-return;
-  }
-
   // Use the -mcpu=? flag as the dummy input to cc1.
   Actions.clear();
   Action *InputAc = C.MakeAction(*A, types::TY_C);
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 40e60585a8b8d6e..ed756ed7ea785c5 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5733,6 +5733,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 CmdArgs.push_back(Args.MakeArgString(CPU));
   }
 
+  // Track -mcpu presence
+  // it's absence marks -target-cpu generic
+  if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
+CmdArgs.push_back("-mcpu");
+CmdArgs.push_back(A->getValue());
+  }
+
   RenderTargetOptions(Triple, Args, KernelOrKext, CmdArgs);
 
   // Add clang-cl arguments.
diff --git a/clang/test/Driver/print-supported-extensions.c 
b/clang/test/Driver/print-supported-extensions.c
index 8daf4d8a34b8a60..d85d5bc50347144 100644
--- a/clang/test/Driver/print-supported-extensions.c
+++ b/clang/test/Driver/print-supported-extensions.c
@@ -3,16 +3,24 @@
 
 // RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
-// AARCH64: All available -march extensions for AArch64
+// AARCH64: All available -march extensions for aarch64
+
+// RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu 
-mcpu=cortex-a55 \
+// RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
+// AARCH64: All available -march extensions for aarch64 and -mcpu cortex-a55
 
 // RUN: %if riscv-registered-target %{ %clang --target=riscv64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
RISCV %}
-// RISCV: All available -march extensions for RISC-V
+// RISCV: All available -march extensions for riscv64
 
 // RUN: %if arm-registered-target %{ %clang --target=arm-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix ARM 
%}
-// ARM: All available -march extensions for ARM
+// ARM: All available -march extensions for arm
+
+// RUN: %if aarch64-registered-target %{ %clang --target=x86_64-linux-gnu \
+// RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix X86 
%}
+// X86: All available -march extensions for x86-64
 
-// RUN: 

[clang] [clang] Enable --print-supported-extensions for all targets (PR #66586)

2023-09-17 Thread Balint Cristian via cfe-commits

cbalint13 wrote:

@DavidSpickett ,

> * We can limit to list flags only for a desired e.g. -mcpu=XYZ, so the user 
> can query like:
> Let me know if it would be another interesting command-line feature, I'll be 
> happy doing it in a subsecvent PR.

Implemented the -mcpu filter option too.
```
$ ./bin/clang --target=x86_64-unknown-linux-gnu -mcpu=sandybridge 
--print-supported-extensions
clang version 18.0.0 (https://github.com/cbalint13/llvm-project 
4a1fe09b189f100e2fb53105bbcd7b15b8adf4f8)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/cbalint/work/GITHUB/llvm-project/build/./bin
All available -march extensions for x86-64 and -mcpu sandybridge

  64bitSupport 64-bit instructions
  64bit-mode   64-bit mode (x86_64)
  avx  Enable AVX instructions
  cmov Enable conditional move instructions
  crc32Enable SSE 4.2 CRC32 instruction 
(used when SSE4.2 is ...
  cx16 64-bit with cmpxchg16b (this is true 
for most x86-64 chips ...
  cx8  Support CMPXCHG8B instructions
  false-deps-popcntPOPCNT has a false dependency on 
dest register
  fast-15bytenop   Target can quickly decode up to 15 
byte NOPs
  fast-scalar-fsqrtScalar SQRT is fast (disable 
Newton-Raphson)
  fast-shld-rotate SHLD can be used as a faster rotate
  fxsr Support fxsave/fxrestore instructions
  idivq-to-divlUse 32-bit divide for positive 
values less than 2^32
  macrofusion  Various instructions can be fused 
with conditional branches
  mmx  Enable MMX instructions
  no-bypass-delay-mov  Has no bypass delay when using the 
'wrong' mov type
  nopl Enable NOPL instruction (generally 
pentium pro+)
  pclmul   Enable packed carry-less 
multiplication instructions
  popcnt   Support POPCNT instruction
  sahf Support LAHF and SAHF instructions 
in 64-bit mode
  slow-3ops-leaLEA instruction with 3 ops or 
certain registers is slow
  slow-unaligned-mem-32Slow unaligned 32-byte memory access
  sse  Enable SSE instructions
  sse2 Enable SSE2 instructions
  sse3 Enable SSE3 instructions
  sse4.1   Enable SSE 4.1 instructions
  sse4.2   Enable SSE 4.2 instructions
  ssse3Enable SSSE3 instructions
  vzeroupper   Should insert vzeroupper instructions
  x87  Enable X87 float instructions
  xsaveSupport xsave instructions
  xsaveopt Support xsaveopt instructions
```


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


[clang] [clang] Enable --print-supported-extensions for all targets (PR #66586)

2023-09-17 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable --print-supported-extensions for all targets (PR #66586)

2023-09-17 Thread Balint Cristian via cfe-commits

https://github.com/cbalint13 updated 
https://github.com/llvm/llvm-project/pull/66586

>From 633e258d41bf15e77f592f4e95eda729e6da5a4b Mon Sep 17 00:00:00 2001
From: Balint Cristian 
Date: Sun, 17 Sep 2023 14:16:13 +0300
Subject: [PATCH] [clang] Enable --print-supported-extensions for all targets

Signed-off-by: Balint Cristian 
---
 clang/include/clang/Driver/Options.td |  2 +-
 clang/lib/Driver/Driver.cpp   | 14 +--
 clang/lib/Driver/ToolChains/Clang.cpp |  7 
 .../test/Driver/print-supported-extensions.c  | 18 +---
 clang/tools/driver/cc1_main.cpp   | 42 ++-
 llvm/include/llvm/MC/MCSubtargetInfo.h|  6 +++
 6 files changed, 51 insertions(+), 38 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 553c7928c4f949e..431f2f5c4109232 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5277,7 +5277,7 @@ def print_supported_cpus : Flag<["-", "--"], 
"print-supported-cpus">,
   MarshallingInfoFlag>;
 def print_supported_extensions : Flag<["-", "--"], 
"print-supported-extensions">,
   Visibility<[ClangOption, CC1Option, CLOption]>,
-  HelpText<"Print supported -march extensions (RISC-V, AArch64 and ARM only)">,
+  HelpText<"Print supported -march extensions">,
   MarshallingInfoFlag>;
 def : Flag<["-"], "mcpu=help">, Alias;
 def : Flag<["-"], "mtune=help">, Alias;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 84b8fc7685fed42..5b6b14d175f5299 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4279,19 +4279,9 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
 // If --print-supported-cpus, -mcpu=? or -mtune=? is specified, build a
 // custom Compile phase that prints out supported cpu models and quits.
 //
-// If --print-supported-extensions is specified, call the helper function
-// RISCVMarchHelp in RISCVISAInfo.cpp that prints out supported extensions
-// and quits.
+// If --print-supported-extensions is specified, list all supported flags
+// within the target and quit.
 if (Arg *A = Args.getLastArg(Opt)) {
-  if (Opt == options::OPT_print_supported_extensions &&
-  !C.getDefaultToolChain().getTriple().isRISCV() &&
-  !C.getDefaultToolChain().getTriple().isAArch64() &&
-  !C.getDefaultToolChain().getTriple().isARM()) {
-C.getDriver().Diag(diag::err_opt_not_valid_on_target)
-<< "--print-supported-extensions";
-return;
-  }
-
   // Use the -mcpu=? flag as the dummy input to cc1.
   Actions.clear();
   Action *InputAc = C.MakeAction(*A, types::TY_C);
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 40e60585a8b8d6e..ed756ed7ea785c5 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5733,6 +5733,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 CmdArgs.push_back(Args.MakeArgString(CPU));
   }
 
+  // Track -mcpu presence
+  // it's absence marks -target-cpu generic
+  if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
+CmdArgs.push_back("-mcpu");
+CmdArgs.push_back(A->getValue());
+  }
+
   RenderTargetOptions(Triple, Args, KernelOrKext, CmdArgs);
 
   // Add clang-cl arguments.
diff --git a/clang/test/Driver/print-supported-extensions.c 
b/clang/test/Driver/print-supported-extensions.c
index 8daf4d8a34b8a60..d85d5bc50347144 100644
--- a/clang/test/Driver/print-supported-extensions.c
+++ b/clang/test/Driver/print-supported-extensions.c
@@ -3,16 +3,24 @@
 
 // RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
-// AARCH64: All available -march extensions for AArch64
+// AARCH64: All available -march extensions for aarch64
+
+// RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu 
-mcpu=cortex-a55 \
+// RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
+// AARCH64: All available -march extensions for aarch64 and -mcpu cortex-a55
 
 // RUN: %if riscv-registered-target %{ %clang --target=riscv64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
RISCV %}
-// RISCV: All available -march extensions for RISC-V
+// RISCV: All available -march extensions for riscv64
 
 // RUN: %if arm-registered-target %{ %clang --target=arm-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix ARM 
%}
-// ARM: All available -march extensions for ARM
+// ARM: All available -march extensions for arm
+
+// RUN: %if aarch64-registered-target %{ %clang --target=x86_64-linux-gnu \
+// RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix X86 
%}
+// X86: All available -march extensions for x86-64
 
-// RUN: 

[clang] [clang] Enable --print-supported-extensions for all targets (PR #66586)

2023-09-17 Thread Balint Cristian via cfe-commits

https://github.com/cbalint13 updated 
https://github.com/llvm/llvm-project/pull/66586

>From ac90fe17df0f7212e675ddf38dbce5b608933b8e Mon Sep 17 00:00:00 2001
From: Balint Cristian 
Date: Sun, 17 Sep 2023 14:20:10 +0300
Subject: [PATCH] [clang] Enable --print-supported-extensions for all targets

Signed-off-by: Balint Cristian 
---
 clang/include/clang/Driver/Options.td |  2 +-
 clang/lib/Driver/Driver.cpp   | 14 +--
 clang/lib/Driver/ToolChains/Clang.cpp |  7 
 .../test/Driver/print-supported-extensions.c  | 18 +---
 clang/tools/driver/cc1_main.cpp   | 42 ++-
 llvm/include/llvm/MC/MCSubtargetInfo.h|  6 +++
 6 files changed, 51 insertions(+), 38 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 553c7928c4f949e..431f2f5c4109232 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5277,7 +5277,7 @@ def print_supported_cpus : Flag<["-", "--"], 
"print-supported-cpus">,
   MarshallingInfoFlag>;
 def print_supported_extensions : Flag<["-", "--"], 
"print-supported-extensions">,
   Visibility<[ClangOption, CC1Option, CLOption]>,
-  HelpText<"Print supported -march extensions (RISC-V, AArch64 and ARM only)">,
+  HelpText<"Print supported -march extensions">,
   MarshallingInfoFlag>;
 def : Flag<["-"], "mcpu=help">, Alias;
 def : Flag<["-"], "mtune=help">, Alias;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 84b8fc7685fed42..5b6b14d175f5299 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4279,19 +4279,9 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
 // If --print-supported-cpus, -mcpu=? or -mtune=? is specified, build a
 // custom Compile phase that prints out supported cpu models and quits.
 //
-// If --print-supported-extensions is specified, call the helper function
-// RISCVMarchHelp in RISCVISAInfo.cpp that prints out supported extensions
-// and quits.
+// If --print-supported-extensions is specified, list all supported flags
+// within the target and quit.
 if (Arg *A = Args.getLastArg(Opt)) {
-  if (Opt == options::OPT_print_supported_extensions &&
-  !C.getDefaultToolChain().getTriple().isRISCV() &&
-  !C.getDefaultToolChain().getTriple().isAArch64() &&
-  !C.getDefaultToolChain().getTriple().isARM()) {
-C.getDriver().Diag(diag::err_opt_not_valid_on_target)
-<< "--print-supported-extensions";
-return;
-  }
-
   // Use the -mcpu=? flag as the dummy input to cc1.
   Actions.clear();
   Action *InputAc = C.MakeAction(*A, types::TY_C);
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 40e60585a8b8d6e..ed756ed7ea785c5 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5733,6 +5733,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 CmdArgs.push_back(Args.MakeArgString(CPU));
   }
 
+  // Track -mcpu presence
+  // it's absence marks -target-cpu generic
+  if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
+CmdArgs.push_back("-mcpu");
+CmdArgs.push_back(A->getValue());
+  }
+
   RenderTargetOptions(Triple, Args, KernelOrKext, CmdArgs);
 
   // Add clang-cl arguments.
diff --git a/clang/test/Driver/print-supported-extensions.c 
b/clang/test/Driver/print-supported-extensions.c
index 8daf4d8a34b8a60..b4b5350ed86e27d 100644
--- a/clang/test/Driver/print-supported-extensions.c
+++ b/clang/test/Driver/print-supported-extensions.c
@@ -3,16 +3,24 @@
 
 // RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
-// AARCH64: All available -march extensions for AArch64
+// AARCH64: All available -march extensions for aarch64
+
+// RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu 
-mcpu=cortex-a55 \
+// RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
+// AARCH64: All available -march extensions for aarch64 and -mcpu cortex-a55
 
 // RUN: %if riscv-registered-target %{ %clang --target=riscv64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
RISCV %}
-// RISCV: All available -march extensions for RISC-V
+// RISCV: All available -march extensions for riscv64
 
 // RUN: %if arm-registered-target %{ %clang --target=arm-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix ARM 
%}
-// ARM: All available -march extensions for ARM
+// ARM: All available -march extensions for arm
+
+// RUN: %if x86-registered-target %{ %clang --target=x86_64-linux-gnu \
+// RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix X86 
%}
+// X86: All available -march extensions for x86-64
 
-// RUN: %if 

[clang-tools-extra] [InstCombine] Fix transforms of two select patterns (PR #65845)

2023-09-17 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw updated 
https://github.com/llvm/llvm-project/pull/65845

>From 91af70acd72c8e889f542ba6dfff6401b89b2dc5 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Sat, 9 Sep 2023 16:47:24 +0800
Subject: [PATCH] [InstCombine] Fix transforms of select (~a | c), a, b and
 select (c & b), a, b

---
 .../InstCombine/InstCombineSelect.cpp |  17 +-
 .../Transforms/InstCombine/select-and-or.ll   | 214 +-
 2 files changed, 166 insertions(+), 65 deletions(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index 33d370690e71a8c..7913644d376f80b 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -3086,17 +3086,18 @@ Instruction 
*InstCombinerImpl::foldSelectOfBools(SelectInst &SI) {
 m_c_LogicalOr(m_Deferred(A), m_Deferred(B)
 return BinaryOperator::CreateXor(A, B);
 
-  // select (~a | c), a, b -> and a, (or c, freeze(b))
+  // select (~a | c), a, b -> select a, (select c, true, b), false
   if (match(CondVal, m_c_Or(m_Not(m_Specific(TrueVal)), m_Value(C))) &&
   CondVal->hasOneUse()) {
-FalseVal = Builder.CreateFreeze(FalseVal);
-return BinaryOperator::CreateAnd(TrueVal, Builder.CreateOr(C, FalseVal));
+Value *OrV = Builder.CreateSelect(C, One, FalseVal);
+return SelectInst::Create(TrueVal, OrV, Zero);
   }
-  // select (~c & b), a, b -> and b, (or freeze(a), c)
-  if (match(CondVal, m_c_And(m_Not(m_Value(C)), m_Specific(FalseVal))) &&
-  CondVal->hasOneUse()) {
-TrueVal = Builder.CreateFreeze(TrueVal);
-return BinaryOperator::CreateAnd(FalseVal, Builder.CreateOr(C, TrueVal));
+  // select (c & b), a, b -> select b, (select ~c, true, a), false
+  if (match(CondVal, m_c_And(m_Value(C), m_Specific(FalseVal))) &&
+  CondVal->hasOneUse() && isFreeToInvert(C, C->hasOneUse())) {
+Value *NotC = Builder.CreateNot(C);
+Value *OrV = Builder.CreateSelect(NotC, One, TrueVal);
+return SelectInst::Create(FalseVal, OrV, Zero);
   }
   // select (a | c), a, b -> select a, true, (select ~c, b, false)
   if (match(CondVal, m_c_Or(m_Specific(TrueVal), m_Value(C))) &&
diff --git a/llvm/test/Transforms/InstCombine/select-and-or.ll 
b/llvm/test/Transforms/InstCombine/select-and-or.ll
index fb78f0affcb8f14..7edcd767b86ecba 100644
--- a/llvm/test/Transforms/InstCombine/select-and-or.ll
+++ b/llvm/test/Transforms/InstCombine/select-and-or.ll
@@ -453,9 +453,8 @@ define i1 @demorgan_select_infloop2(i1 %L) {
 
 define i1 @and_or1(i1 %a, i1 %b, i1 %c) {
 ; CHECK-LABEL: @and_or1(
-; CHECK-NEXT:[[TMP1:%.*]] = freeze i1 [[B:%.*]]
-; CHECK-NEXT:[[TMP2:%.*]] = or i1 [[TMP1]], [[C:%.*]]
-; CHECK-NEXT:[[R:%.*]] = and i1 [[TMP2]], [[A:%.*]]
+; CHECK-NEXT:[[TMP1:%.*]] = select i1 [[C:%.*]], i1 true, i1 [[B:%.*]]
+; CHECK-NEXT:[[R:%.*]] = select i1 [[A:%.*]], i1 [[TMP1]], i1 false
 ; CHECK-NEXT:ret i1 [[R]]
 ;
   %nota = xor i1 %a, true
@@ -466,9 +465,8 @@ define i1 @and_or1(i1 %a, i1 %b, i1 %c) {
 
 define i1 @and_or2(i1 %a, i1 %b, i1 %c) {
 ; CHECK-LABEL: @and_or2(
-; CHECK-NEXT:[[TMP1:%.*]] = freeze i1 [[A:%.*]]
-; CHECK-NEXT:[[TMP2:%.*]] = or i1 [[TMP1]], [[C:%.*]]
-; CHECK-NEXT:[[R:%.*]] = and i1 [[TMP2]], [[B:%.*]]
+; CHECK-NEXT:[[TMP1:%.*]] = select i1 [[C:%.*]], i1 true, i1 [[A:%.*]]
+; CHECK-NEXT:[[R:%.*]] = select i1 [[B:%.*]], i1 [[TMP1]], i1 false
 ; CHECK-NEXT:ret i1 [[R]]
 ;
   %notc = xor i1 %c, true
@@ -477,32 +475,32 @@ define i1 @and_or2(i1 %a, i1 %b, i1 %c) {
   ret i1 %r
 }
 
-define i1 @and_or1_bundef(i1 %a, i1 noundef %b, i1 %c) {
-; CHECK-LABEL: @and_or1_bundef(
-; CHECK-NEXT:[[TMP1:%.*]] = or i1 [[C:%.*]], [[B:%.*]]
-; CHECK-NEXT:[[R:%.*]] = and i1 [[TMP1]], [[A:%.*]]
+define i1 @and_or1_commuted(i1 %a, i1 %b, i1 %c) {
+; CHECK-LABEL: @and_or1_commuted(
+; CHECK-NEXT:[[TMP1:%.*]] = select i1 [[C:%.*]], i1 true, i1 [[B:%.*]]
+; CHECK-NEXT:[[R:%.*]] = select i1 [[A:%.*]], i1 [[TMP1]], i1 false
 ; CHECK-NEXT:ret i1 [[R]]
 ;
   %nota = xor i1 %a, true
-  %cond = or i1 %nota, %c
+  %cond = or i1 %c, %nota
   %r = select i1 %cond, i1 %a, i1 %b
   ret i1 %r
 }
 
-define i1 @and_or2_aundef(i1 noundef %a, i1 %b, i1 %c) {
-; CHECK-LABEL: @and_or2_aundef(
-; CHECK-NEXT:[[TMP1:%.*]] = or i1 [[C:%.*]], [[A:%.*]]
-; CHECK-NEXT:[[R:%.*]] = and i1 [[TMP1]], [[B:%.*]]
+define i1 @and_or2_commuted(i1 %a, i1 %b, i1 %c) {
+; CHECK-LABEL: @and_or2_commuted(
+; CHECK-NEXT:[[TMP1:%.*]] = select i1 [[C:%.*]], i1 true, i1 [[A:%.*]]
+; CHECK-NEXT:[[R:%.*]] = select i1 [[B:%.*]], i1 [[TMP1]], i1 false
 ; CHECK-NEXT:ret i1 [[R]]
 ;
   %notc = xor i1 %c, true
-  %cond = and i1 %notc, %b
+  %cond = and i1 %b, %notc
   %r = select i1 %cond, i1 %a, i1 %b
   ret i1 %r
 }
 
-define i1 @no_and_or1_bundef(i1 %a, i1 noundef %b, i1 %c) {
-; CHECK-LABEL: @no_and_or1_bundef(
+define i1 @and_or1_mult

[clang] [InstCombine] Fix transforms of two select patterns (PR #65845)

2023-09-17 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw updated 
https://github.com/llvm/llvm-project/pull/65845

>From 91af70acd72c8e889f542ba6dfff6401b89b2dc5 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Sat, 9 Sep 2023 16:47:24 +0800
Subject: [PATCH] [InstCombine] Fix transforms of select (~a | c), a, b and
 select (c & b), a, b

---
 .../InstCombine/InstCombineSelect.cpp |  17 +-
 .../Transforms/InstCombine/select-and-or.ll   | 214 +-
 2 files changed, 166 insertions(+), 65 deletions(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index 33d370690e71a8c..7913644d376f80b 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -3086,17 +3086,18 @@ Instruction 
*InstCombinerImpl::foldSelectOfBools(SelectInst &SI) {
 m_c_LogicalOr(m_Deferred(A), m_Deferred(B)
 return BinaryOperator::CreateXor(A, B);
 
-  // select (~a | c), a, b -> and a, (or c, freeze(b))
+  // select (~a | c), a, b -> select a, (select c, true, b), false
   if (match(CondVal, m_c_Or(m_Not(m_Specific(TrueVal)), m_Value(C))) &&
   CondVal->hasOneUse()) {
-FalseVal = Builder.CreateFreeze(FalseVal);
-return BinaryOperator::CreateAnd(TrueVal, Builder.CreateOr(C, FalseVal));
+Value *OrV = Builder.CreateSelect(C, One, FalseVal);
+return SelectInst::Create(TrueVal, OrV, Zero);
   }
-  // select (~c & b), a, b -> and b, (or freeze(a), c)
-  if (match(CondVal, m_c_And(m_Not(m_Value(C)), m_Specific(FalseVal))) &&
-  CondVal->hasOneUse()) {
-TrueVal = Builder.CreateFreeze(TrueVal);
-return BinaryOperator::CreateAnd(FalseVal, Builder.CreateOr(C, TrueVal));
+  // select (c & b), a, b -> select b, (select ~c, true, a), false
+  if (match(CondVal, m_c_And(m_Value(C), m_Specific(FalseVal))) &&
+  CondVal->hasOneUse() && isFreeToInvert(C, C->hasOneUse())) {
+Value *NotC = Builder.CreateNot(C);
+Value *OrV = Builder.CreateSelect(NotC, One, TrueVal);
+return SelectInst::Create(FalseVal, OrV, Zero);
   }
   // select (a | c), a, b -> select a, true, (select ~c, b, false)
   if (match(CondVal, m_c_Or(m_Specific(TrueVal), m_Value(C))) &&
diff --git a/llvm/test/Transforms/InstCombine/select-and-or.ll 
b/llvm/test/Transforms/InstCombine/select-and-or.ll
index fb78f0affcb8f14..7edcd767b86ecba 100644
--- a/llvm/test/Transforms/InstCombine/select-and-or.ll
+++ b/llvm/test/Transforms/InstCombine/select-and-or.ll
@@ -453,9 +453,8 @@ define i1 @demorgan_select_infloop2(i1 %L) {
 
 define i1 @and_or1(i1 %a, i1 %b, i1 %c) {
 ; CHECK-LABEL: @and_or1(
-; CHECK-NEXT:[[TMP1:%.*]] = freeze i1 [[B:%.*]]
-; CHECK-NEXT:[[TMP2:%.*]] = or i1 [[TMP1]], [[C:%.*]]
-; CHECK-NEXT:[[R:%.*]] = and i1 [[TMP2]], [[A:%.*]]
+; CHECK-NEXT:[[TMP1:%.*]] = select i1 [[C:%.*]], i1 true, i1 [[B:%.*]]
+; CHECK-NEXT:[[R:%.*]] = select i1 [[A:%.*]], i1 [[TMP1]], i1 false
 ; CHECK-NEXT:ret i1 [[R]]
 ;
   %nota = xor i1 %a, true
@@ -466,9 +465,8 @@ define i1 @and_or1(i1 %a, i1 %b, i1 %c) {
 
 define i1 @and_or2(i1 %a, i1 %b, i1 %c) {
 ; CHECK-LABEL: @and_or2(
-; CHECK-NEXT:[[TMP1:%.*]] = freeze i1 [[A:%.*]]
-; CHECK-NEXT:[[TMP2:%.*]] = or i1 [[TMP1]], [[C:%.*]]
-; CHECK-NEXT:[[R:%.*]] = and i1 [[TMP2]], [[B:%.*]]
+; CHECK-NEXT:[[TMP1:%.*]] = select i1 [[C:%.*]], i1 true, i1 [[A:%.*]]
+; CHECK-NEXT:[[R:%.*]] = select i1 [[B:%.*]], i1 [[TMP1]], i1 false
 ; CHECK-NEXT:ret i1 [[R]]
 ;
   %notc = xor i1 %c, true
@@ -477,32 +475,32 @@ define i1 @and_or2(i1 %a, i1 %b, i1 %c) {
   ret i1 %r
 }
 
-define i1 @and_or1_bundef(i1 %a, i1 noundef %b, i1 %c) {
-; CHECK-LABEL: @and_or1_bundef(
-; CHECK-NEXT:[[TMP1:%.*]] = or i1 [[C:%.*]], [[B:%.*]]
-; CHECK-NEXT:[[R:%.*]] = and i1 [[TMP1]], [[A:%.*]]
+define i1 @and_or1_commuted(i1 %a, i1 %b, i1 %c) {
+; CHECK-LABEL: @and_or1_commuted(
+; CHECK-NEXT:[[TMP1:%.*]] = select i1 [[C:%.*]], i1 true, i1 [[B:%.*]]
+; CHECK-NEXT:[[R:%.*]] = select i1 [[A:%.*]], i1 [[TMP1]], i1 false
 ; CHECK-NEXT:ret i1 [[R]]
 ;
   %nota = xor i1 %a, true
-  %cond = or i1 %nota, %c
+  %cond = or i1 %c, %nota
   %r = select i1 %cond, i1 %a, i1 %b
   ret i1 %r
 }
 
-define i1 @and_or2_aundef(i1 noundef %a, i1 %b, i1 %c) {
-; CHECK-LABEL: @and_or2_aundef(
-; CHECK-NEXT:[[TMP1:%.*]] = or i1 [[C:%.*]], [[A:%.*]]
-; CHECK-NEXT:[[R:%.*]] = and i1 [[TMP1]], [[B:%.*]]
+define i1 @and_or2_commuted(i1 %a, i1 %b, i1 %c) {
+; CHECK-LABEL: @and_or2_commuted(
+; CHECK-NEXT:[[TMP1:%.*]] = select i1 [[C:%.*]], i1 true, i1 [[A:%.*]]
+; CHECK-NEXT:[[R:%.*]] = select i1 [[B:%.*]], i1 [[TMP1]], i1 false
 ; CHECK-NEXT:ret i1 [[R]]
 ;
   %notc = xor i1 %c, true
-  %cond = and i1 %notc, %b
+  %cond = and i1 %b, %notc
   %r = select i1 %cond, i1 %a, i1 %b
   ret i1 %r
 }
 
-define i1 @no_and_or1_bundef(i1 %a, i1 noundef %b, i1 %c) {
-; CHECK-LABEL: @no_and_or1_bundef(
+define i1 @and_or1_mult

[clang-tools-extra] [InstCombine] Fix transforms of two select patterns (PR #65845)

2023-09-17 Thread Yingwei Zheng via cfe-commits

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


[clang] [InstCombine] Fix transforms of two select patterns (PR #65845)

2023-09-17 Thread Yingwei Zheng via cfe-commits

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


[clang] [InstCombine] Fix transforms of two select patterns (PR #65845)

2023-09-17 Thread Yingwei Zheng via cfe-commits

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


[clang] [InstCombine] Fix transforms of two select patterns (PR #65845)

2023-09-17 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw updated 
https://github.com/llvm/llvm-project/pull/65845

>From 91af70acd72c8e889f542ba6dfff6401b89b2dc5 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Sat, 9 Sep 2023 16:47:24 +0800
Subject: [PATCH 1/2] [InstCombine] Fix transforms of select (~a | c), a, b and
 select (c & b), a, b

---
 .../InstCombine/InstCombineSelect.cpp |  17 +-
 .../Transforms/InstCombine/select-and-or.ll   | 214 +-
 2 files changed, 166 insertions(+), 65 deletions(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index 33d370690e71a8c..7913644d376f80b 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -3086,17 +3086,18 @@ Instruction 
*InstCombinerImpl::foldSelectOfBools(SelectInst &SI) {
 m_c_LogicalOr(m_Deferred(A), m_Deferred(B)
 return BinaryOperator::CreateXor(A, B);
 
-  // select (~a | c), a, b -> and a, (or c, freeze(b))
+  // select (~a | c), a, b -> select a, (select c, true, b), false
   if (match(CondVal, m_c_Or(m_Not(m_Specific(TrueVal)), m_Value(C))) &&
   CondVal->hasOneUse()) {
-FalseVal = Builder.CreateFreeze(FalseVal);
-return BinaryOperator::CreateAnd(TrueVal, Builder.CreateOr(C, FalseVal));
+Value *OrV = Builder.CreateSelect(C, One, FalseVal);
+return SelectInst::Create(TrueVal, OrV, Zero);
   }
-  // select (~c & b), a, b -> and b, (or freeze(a), c)
-  if (match(CondVal, m_c_And(m_Not(m_Value(C)), m_Specific(FalseVal))) &&
-  CondVal->hasOneUse()) {
-TrueVal = Builder.CreateFreeze(TrueVal);
-return BinaryOperator::CreateAnd(FalseVal, Builder.CreateOr(C, TrueVal));
+  // select (c & b), a, b -> select b, (select ~c, true, a), false
+  if (match(CondVal, m_c_And(m_Value(C), m_Specific(FalseVal))) &&
+  CondVal->hasOneUse() && isFreeToInvert(C, C->hasOneUse())) {
+Value *NotC = Builder.CreateNot(C);
+Value *OrV = Builder.CreateSelect(NotC, One, TrueVal);
+return SelectInst::Create(FalseVal, OrV, Zero);
   }
   // select (a | c), a, b -> select a, true, (select ~c, b, false)
   if (match(CondVal, m_c_Or(m_Specific(TrueVal), m_Value(C))) &&
diff --git a/llvm/test/Transforms/InstCombine/select-and-or.ll 
b/llvm/test/Transforms/InstCombine/select-and-or.ll
index fb78f0affcb8f14..7edcd767b86ecba 100644
--- a/llvm/test/Transforms/InstCombine/select-and-or.ll
+++ b/llvm/test/Transforms/InstCombine/select-and-or.ll
@@ -453,9 +453,8 @@ define i1 @demorgan_select_infloop2(i1 %L) {
 
 define i1 @and_or1(i1 %a, i1 %b, i1 %c) {
 ; CHECK-LABEL: @and_or1(
-; CHECK-NEXT:[[TMP1:%.*]] = freeze i1 [[B:%.*]]
-; CHECK-NEXT:[[TMP2:%.*]] = or i1 [[TMP1]], [[C:%.*]]
-; CHECK-NEXT:[[R:%.*]] = and i1 [[TMP2]], [[A:%.*]]
+; CHECK-NEXT:[[TMP1:%.*]] = select i1 [[C:%.*]], i1 true, i1 [[B:%.*]]
+; CHECK-NEXT:[[R:%.*]] = select i1 [[A:%.*]], i1 [[TMP1]], i1 false
 ; CHECK-NEXT:ret i1 [[R]]
 ;
   %nota = xor i1 %a, true
@@ -466,9 +465,8 @@ define i1 @and_or1(i1 %a, i1 %b, i1 %c) {
 
 define i1 @and_or2(i1 %a, i1 %b, i1 %c) {
 ; CHECK-LABEL: @and_or2(
-; CHECK-NEXT:[[TMP1:%.*]] = freeze i1 [[A:%.*]]
-; CHECK-NEXT:[[TMP2:%.*]] = or i1 [[TMP1]], [[C:%.*]]
-; CHECK-NEXT:[[R:%.*]] = and i1 [[TMP2]], [[B:%.*]]
+; CHECK-NEXT:[[TMP1:%.*]] = select i1 [[C:%.*]], i1 true, i1 [[A:%.*]]
+; CHECK-NEXT:[[R:%.*]] = select i1 [[B:%.*]], i1 [[TMP1]], i1 false
 ; CHECK-NEXT:ret i1 [[R]]
 ;
   %notc = xor i1 %c, true
@@ -477,32 +475,32 @@ define i1 @and_or2(i1 %a, i1 %b, i1 %c) {
   ret i1 %r
 }
 
-define i1 @and_or1_bundef(i1 %a, i1 noundef %b, i1 %c) {
-; CHECK-LABEL: @and_or1_bundef(
-; CHECK-NEXT:[[TMP1:%.*]] = or i1 [[C:%.*]], [[B:%.*]]
-; CHECK-NEXT:[[R:%.*]] = and i1 [[TMP1]], [[A:%.*]]
+define i1 @and_or1_commuted(i1 %a, i1 %b, i1 %c) {
+; CHECK-LABEL: @and_or1_commuted(
+; CHECK-NEXT:[[TMP1:%.*]] = select i1 [[C:%.*]], i1 true, i1 [[B:%.*]]
+; CHECK-NEXT:[[R:%.*]] = select i1 [[A:%.*]], i1 [[TMP1]], i1 false
 ; CHECK-NEXT:ret i1 [[R]]
 ;
   %nota = xor i1 %a, true
-  %cond = or i1 %nota, %c
+  %cond = or i1 %c, %nota
   %r = select i1 %cond, i1 %a, i1 %b
   ret i1 %r
 }
 
-define i1 @and_or2_aundef(i1 noundef %a, i1 %b, i1 %c) {
-; CHECK-LABEL: @and_or2_aundef(
-; CHECK-NEXT:[[TMP1:%.*]] = or i1 [[C:%.*]], [[A:%.*]]
-; CHECK-NEXT:[[R:%.*]] = and i1 [[TMP1]], [[B:%.*]]
+define i1 @and_or2_commuted(i1 %a, i1 %b, i1 %c) {
+; CHECK-LABEL: @and_or2_commuted(
+; CHECK-NEXT:[[TMP1:%.*]] = select i1 [[C:%.*]], i1 true, i1 [[A:%.*]]
+; CHECK-NEXT:[[R:%.*]] = select i1 [[B:%.*]], i1 [[TMP1]], i1 false
 ; CHECK-NEXT:ret i1 [[R]]
 ;
   %notc = xor i1 %c, true
-  %cond = and i1 %notc, %b
+  %cond = and i1 %b, %notc
   %r = select i1 %cond, i1 %a, i1 %b
   ret i1 %r
 }
 
-define i1 @no_and_or1_bundef(i1 %a, i1 noundef %b, i1 %c) {
-; CHECK-LABEL: @no_and_or1_bundef(
+define i1 @and_or1_

[clang-tools-extra] [InstCombine] Fix transforms of two select patterns (PR #65845)

2023-09-17 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw updated 
https://github.com/llvm/llvm-project/pull/65845

>From 91af70acd72c8e889f542ba6dfff6401b89b2dc5 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Sat, 9 Sep 2023 16:47:24 +0800
Subject: [PATCH 1/2] [InstCombine] Fix transforms of select (~a | c), a, b and
 select (c & b), a, b

---
 .../InstCombine/InstCombineSelect.cpp |  17 +-
 .../Transforms/InstCombine/select-and-or.ll   | 214 +-
 2 files changed, 166 insertions(+), 65 deletions(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index 33d370690e71a8c..7913644d376f80b 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -3086,17 +3086,18 @@ Instruction 
*InstCombinerImpl::foldSelectOfBools(SelectInst &SI) {
 m_c_LogicalOr(m_Deferred(A), m_Deferred(B)
 return BinaryOperator::CreateXor(A, B);
 
-  // select (~a | c), a, b -> and a, (or c, freeze(b))
+  // select (~a | c), a, b -> select a, (select c, true, b), false
   if (match(CondVal, m_c_Or(m_Not(m_Specific(TrueVal)), m_Value(C))) &&
   CondVal->hasOneUse()) {
-FalseVal = Builder.CreateFreeze(FalseVal);
-return BinaryOperator::CreateAnd(TrueVal, Builder.CreateOr(C, FalseVal));
+Value *OrV = Builder.CreateSelect(C, One, FalseVal);
+return SelectInst::Create(TrueVal, OrV, Zero);
   }
-  // select (~c & b), a, b -> and b, (or freeze(a), c)
-  if (match(CondVal, m_c_And(m_Not(m_Value(C)), m_Specific(FalseVal))) &&
-  CondVal->hasOneUse()) {
-TrueVal = Builder.CreateFreeze(TrueVal);
-return BinaryOperator::CreateAnd(FalseVal, Builder.CreateOr(C, TrueVal));
+  // select (c & b), a, b -> select b, (select ~c, true, a), false
+  if (match(CondVal, m_c_And(m_Value(C), m_Specific(FalseVal))) &&
+  CondVal->hasOneUse() && isFreeToInvert(C, C->hasOneUse())) {
+Value *NotC = Builder.CreateNot(C);
+Value *OrV = Builder.CreateSelect(NotC, One, TrueVal);
+return SelectInst::Create(FalseVal, OrV, Zero);
   }
   // select (a | c), a, b -> select a, true, (select ~c, b, false)
   if (match(CondVal, m_c_Or(m_Specific(TrueVal), m_Value(C))) &&
diff --git a/llvm/test/Transforms/InstCombine/select-and-or.ll 
b/llvm/test/Transforms/InstCombine/select-and-or.ll
index fb78f0affcb8f14..7edcd767b86ecba 100644
--- a/llvm/test/Transforms/InstCombine/select-and-or.ll
+++ b/llvm/test/Transforms/InstCombine/select-and-or.ll
@@ -453,9 +453,8 @@ define i1 @demorgan_select_infloop2(i1 %L) {
 
 define i1 @and_or1(i1 %a, i1 %b, i1 %c) {
 ; CHECK-LABEL: @and_or1(
-; CHECK-NEXT:[[TMP1:%.*]] = freeze i1 [[B:%.*]]
-; CHECK-NEXT:[[TMP2:%.*]] = or i1 [[TMP1]], [[C:%.*]]
-; CHECK-NEXT:[[R:%.*]] = and i1 [[TMP2]], [[A:%.*]]
+; CHECK-NEXT:[[TMP1:%.*]] = select i1 [[C:%.*]], i1 true, i1 [[B:%.*]]
+; CHECK-NEXT:[[R:%.*]] = select i1 [[A:%.*]], i1 [[TMP1]], i1 false
 ; CHECK-NEXT:ret i1 [[R]]
 ;
   %nota = xor i1 %a, true
@@ -466,9 +465,8 @@ define i1 @and_or1(i1 %a, i1 %b, i1 %c) {
 
 define i1 @and_or2(i1 %a, i1 %b, i1 %c) {
 ; CHECK-LABEL: @and_or2(
-; CHECK-NEXT:[[TMP1:%.*]] = freeze i1 [[A:%.*]]
-; CHECK-NEXT:[[TMP2:%.*]] = or i1 [[TMP1]], [[C:%.*]]
-; CHECK-NEXT:[[R:%.*]] = and i1 [[TMP2]], [[B:%.*]]
+; CHECK-NEXT:[[TMP1:%.*]] = select i1 [[C:%.*]], i1 true, i1 [[A:%.*]]
+; CHECK-NEXT:[[R:%.*]] = select i1 [[B:%.*]], i1 [[TMP1]], i1 false
 ; CHECK-NEXT:ret i1 [[R]]
 ;
   %notc = xor i1 %c, true
@@ -477,32 +475,32 @@ define i1 @and_or2(i1 %a, i1 %b, i1 %c) {
   ret i1 %r
 }
 
-define i1 @and_or1_bundef(i1 %a, i1 noundef %b, i1 %c) {
-; CHECK-LABEL: @and_or1_bundef(
-; CHECK-NEXT:[[TMP1:%.*]] = or i1 [[C:%.*]], [[B:%.*]]
-; CHECK-NEXT:[[R:%.*]] = and i1 [[TMP1]], [[A:%.*]]
+define i1 @and_or1_commuted(i1 %a, i1 %b, i1 %c) {
+; CHECK-LABEL: @and_or1_commuted(
+; CHECK-NEXT:[[TMP1:%.*]] = select i1 [[C:%.*]], i1 true, i1 [[B:%.*]]
+; CHECK-NEXT:[[R:%.*]] = select i1 [[A:%.*]], i1 [[TMP1]], i1 false
 ; CHECK-NEXT:ret i1 [[R]]
 ;
   %nota = xor i1 %a, true
-  %cond = or i1 %nota, %c
+  %cond = or i1 %c, %nota
   %r = select i1 %cond, i1 %a, i1 %b
   ret i1 %r
 }
 
-define i1 @and_or2_aundef(i1 noundef %a, i1 %b, i1 %c) {
-; CHECK-LABEL: @and_or2_aundef(
-; CHECK-NEXT:[[TMP1:%.*]] = or i1 [[C:%.*]], [[A:%.*]]
-; CHECK-NEXT:[[R:%.*]] = and i1 [[TMP1]], [[B:%.*]]
+define i1 @and_or2_commuted(i1 %a, i1 %b, i1 %c) {
+; CHECK-LABEL: @and_or2_commuted(
+; CHECK-NEXT:[[TMP1:%.*]] = select i1 [[C:%.*]], i1 true, i1 [[A:%.*]]
+; CHECK-NEXT:[[R:%.*]] = select i1 [[B:%.*]], i1 [[TMP1]], i1 false
 ; CHECK-NEXT:ret i1 [[R]]
 ;
   %notc = xor i1 %c, true
-  %cond = and i1 %notc, %b
+  %cond = and i1 %b, %notc
   %r = select i1 %cond, i1 %a, i1 %b
   ret i1 %r
 }
 
-define i1 @no_and_or1_bundef(i1 %a, i1 noundef %b, i1 %c) {
-; CHECK-LABEL: @no_and_or1_bundef(
+define i1 @and_or1_

[clang] [clang] Enable --print-supported-extensions for all targets (PR #66586)

2023-09-17 Thread Balint Cristian via cfe-commits

https://github.com/cbalint13 updated 
https://github.com/llvm/llvm-project/pull/66586

>From 6111b800196cee9ee45ebb5c800e17e56b843152 Mon Sep 17 00:00:00 2001
From: Balint Cristian 
Date: Sun, 17 Sep 2023 15:24:23 +0300
Subject: [PATCH] [clang] Enable --print-supported-extensions for all targets

Signed-off-by: Balint Cristian 
---
 clang/include/clang/Driver/Options.td |  2 +-
 clang/lib/Driver/Driver.cpp   | 14 ++-
 .../test/Driver/print-supported-extensions.c  |  8 +++---
 clang/tools/driver/cc1_main.cpp   | 25 +++
 llvm/include/llvm/MC/MCSubtargetInfo.h|  6 +
 5 files changed, 22 insertions(+), 33 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 553c7928c4f949e..431f2f5c4109232 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5277,7 +5277,7 @@ def print_supported_cpus : Flag<["-", "--"], 
"print-supported-cpus">,
   MarshallingInfoFlag>;
 def print_supported_extensions : Flag<["-", "--"], 
"print-supported-extensions">,
   Visibility<[ClangOption, CC1Option, CLOption]>,
-  HelpText<"Print supported -march extensions (RISC-V, AArch64 and ARM only)">,
+  HelpText<"Print supported -march extensions">,
   MarshallingInfoFlag>;
 def : Flag<["-"], "mcpu=help">, Alias;
 def : Flag<["-"], "mtune=help">, Alias;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 84b8fc7685fed42..5b6b14d175f5299 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4279,19 +4279,9 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
 // If --print-supported-cpus, -mcpu=? or -mtune=? is specified, build a
 // custom Compile phase that prints out supported cpu models and quits.
 //
-// If --print-supported-extensions is specified, call the helper function
-// RISCVMarchHelp in RISCVISAInfo.cpp that prints out supported extensions
-// and quits.
+// If --print-supported-extensions is specified, list all supported flags
+// within the target and quit.
 if (Arg *A = Args.getLastArg(Opt)) {
-  if (Opt == options::OPT_print_supported_extensions &&
-  !C.getDefaultToolChain().getTriple().isRISCV() &&
-  !C.getDefaultToolChain().getTriple().isAArch64() &&
-  !C.getDefaultToolChain().getTriple().isARM()) {
-C.getDriver().Diag(diag::err_opt_not_valid_on_target)
-<< "--print-supported-extensions";
-return;
-  }
-
   // Use the -mcpu=? flag as the dummy input to cc1.
   Actions.clear();
   Action *InputAc = C.MakeAction(*A, types::TY_C);
diff --git a/clang/test/Driver/print-supported-extensions.c 
b/clang/test/Driver/print-supported-extensions.c
index 8daf4d8a34b8a60..9be228765a0f28c 100644
--- a/clang/test/Driver/print-supported-extensions.c
+++ b/clang/test/Driver/print-supported-extensions.c
@@ -3,16 +3,16 @@
 
 // RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
-// AARCH64: All available -march extensions for AArch64
+// AARCH64: All available -march extensions for aarch64
 
 // RUN: %if riscv-registered-target %{ %clang --target=riscv64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
RISCV %}
-// RISCV: All available -march extensions for RISC-V
+// RISCV: All available -march extensions for riscv64
 
 // RUN: %if arm-registered-target %{ %clang --target=arm-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix ARM 
%}
-// ARM: All available -march extensions for ARM
+// ARM: All available -march extensions for arm
 
 // RUN: %if x86-registered-target %{ not %clang --target=x86_64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix X86 
%}
-// X86: error: option '--print-supported-extensions' cannot be specified on 
this target
\ No newline at end of file
+// X86: All available -march extensions for x86-64
diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp
index f0d7b5c3889dc1f..20542cb9aa7a913 100644
--- a/clang/tools/driver/cc1_main.cpp
+++ b/clang/tools/driver/cc1_main.cpp
@@ -38,16 +38,14 @@
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/TimeProfiler.h"
 #include "llvm/Support/Timer.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetMachine.h"
-#include "llvm/TargetParser/AArch64TargetParser.h"
-#include "llvm/TargetParser/ARMTargetParser.h"
 #include 
+#include 
 
 #ifdef CLANG_HAVE_RLIMITS
 #include 
@@ -197,19 +195,14 @@ static int PrintSupportedExtensions(std::string 
TargetStr) {
   llvm::TargetOptions Options;
   s

[clang] [InstCombine] Fix transforms of two select patterns (PR #65845)

2023-09-17 Thread Yingwei Zheng via cfe-commits

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


[clang-tools-extra] [InstCombine] Fix transforms of two select patterns (PR #65845)

2023-09-17 Thread Yingwei Zheng via cfe-commits

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


[clang] [clang] Enable --print-supported-extensions for all targets (PR #66586)

2023-09-17 Thread Balint Cristian via cfe-commits

https://github.com/cbalint13 updated 
https://github.com/llvm/llvm-project/pull/66586

>From 17f855f12757ee66ff99cf24abe4be0dcffc3532 Mon Sep 17 00:00:00 2001
From: Balint Cristian 
Date: Sun, 17 Sep 2023 15:42:27 +0300
Subject: [PATCH] [clang] Enable --print-supported-extensions for all targets

Signed-off-by: Balint Cristian 
---
 clang/include/clang/Driver/Options.td |  2 +-
 clang/lib/Driver/Driver.cpp   | 14 ++-
 .../test/Driver/print-supported-extensions.c  | 10 
 clang/tools/driver/cc1_main.cpp   | 25 +++
 llvm/include/llvm/MC/MCSubtargetInfo.h|  6 +
 5 files changed, 23 insertions(+), 34 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 553c7928c4f949e..431f2f5c4109232 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5277,7 +5277,7 @@ def print_supported_cpus : Flag<["-", "--"], 
"print-supported-cpus">,
   MarshallingInfoFlag>;
 def print_supported_extensions : Flag<["-", "--"], 
"print-supported-extensions">,
   Visibility<[ClangOption, CC1Option, CLOption]>,
-  HelpText<"Print supported -march extensions (RISC-V, AArch64 and ARM only)">,
+  HelpText<"Print supported -march extensions">,
   MarshallingInfoFlag>;
 def : Flag<["-"], "mcpu=help">, Alias;
 def : Flag<["-"], "mtune=help">, Alias;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 84b8fc7685fed42..5b6b14d175f5299 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4279,19 +4279,9 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
 // If --print-supported-cpus, -mcpu=? or -mtune=? is specified, build a
 // custom Compile phase that prints out supported cpu models and quits.
 //
-// If --print-supported-extensions is specified, call the helper function
-// RISCVMarchHelp in RISCVISAInfo.cpp that prints out supported extensions
-// and quits.
+// If --print-supported-extensions is specified, list all supported flags
+// within the target and quit.
 if (Arg *A = Args.getLastArg(Opt)) {
-  if (Opt == options::OPT_print_supported_extensions &&
-  !C.getDefaultToolChain().getTriple().isRISCV() &&
-  !C.getDefaultToolChain().getTriple().isAArch64() &&
-  !C.getDefaultToolChain().getTriple().isARM()) {
-C.getDriver().Diag(diag::err_opt_not_valid_on_target)
-<< "--print-supported-extensions";
-return;
-  }
-
   // Use the -mcpu=? flag as the dummy input to cc1.
   Actions.clear();
   Action *InputAc = C.MakeAction(*A, types::TY_C);
diff --git a/clang/test/Driver/print-supported-extensions.c 
b/clang/test/Driver/print-supported-extensions.c
index 8daf4d8a34b8a60..d233e9fb783e2e2 100644
--- a/clang/test/Driver/print-supported-extensions.c
+++ b/clang/test/Driver/print-supported-extensions.c
@@ -3,16 +3,16 @@
 
 // RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
-// AARCH64: All available -march extensions for AArch64
+// AARCH64: All available -march extensions for aarch64
 
 // RUN: %if riscv-registered-target %{ %clang --target=riscv64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
RISCV %}
-// RISCV: All available -march extensions for RISC-V
+// RISCV: All available -march extensions for riscv64
 
 // RUN: %if arm-registered-target %{ %clang --target=arm-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix ARM 
%}
-// ARM: All available -march extensions for ARM
+// ARM: All available -march extensions for arm
 
-// RUN: %if x86-registered-target %{ not %clang --target=x86_64-linux-gnu \
+// RUN: %if x86-registered-target %{ %clang --target=x86_64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix X86 
%}
-// X86: error: option '--print-supported-extensions' cannot be specified on 
this target
\ No newline at end of file
+// X86: All available -march extensions for x86-64
diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp
index f0d7b5c3889dc1f..20542cb9aa7a913 100644
--- a/clang/tools/driver/cc1_main.cpp
+++ b/clang/tools/driver/cc1_main.cpp
@@ -38,16 +38,14 @@
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/TimeProfiler.h"
 #include "llvm/Support/Timer.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetMachine.h"
-#include "llvm/TargetParser/AArch64TargetParser.h"
-#include "llvm/TargetParser/ARMTargetParser.h"
 #include 
+#include 
 
 #ifdef CLANG_HAVE_RLIMITS
 #include 
@@ -197,19 +195,14 @@ static int PrintSupport

[clang] [InstSimplify] Simplify `icmp X & C1, X & C2` when `(C1 & C2) == C1/C2` (PR #65905)

2023-09-17 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw updated 
https://github.com/llvm/llvm-project/pull/65905

>From f178af6d47ce6d982c6568ba6e0db517de124291 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Mon, 11 Sep 2023 02:01:12 +0800
Subject: [PATCH] [InstSimplify] Simplify `icmp X & C1, X & C2` when `(C1 & C2)
 == C1/C2`

---
 llvm/lib/Analysis/InstructionSimplify.cpp |  28 ++-
 llvm/test/Transforms/InstSimplify/compare.ll  | 194 ++
 .../InstSimplify/maxmin_intrinsics.ll |  97 +
 3 files changed, 318 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp 
b/llvm/lib/Analysis/InstructionSimplify.cpp
index d0cc56ebc2be319..734029f1ad0bef5 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -3427,7 +3427,7 @@ static Value *simplifyICmpWithBinOp(CmpInst::Predicate 
Pred, Value *LHS,
 switch (LBO->getOpcode()) {
 default:
   break;
-case Instruction::Shl:
+case Instruction::Shl: {
   bool NUW = Q.IIQ.hasNoUnsignedWrap(LBO) && Q.IIQ.hasNoUnsignedWrap(RBO);
   bool NSW = Q.IIQ.hasNoSignedWrap(LBO) && Q.IIQ.hasNoSignedWrap(RBO);
   if (!NUW || (ICmpInst::isSigned(Pred) && !NSW) ||
@@ -3436,6 +3436,32 @@ static Value *simplifyICmpWithBinOp(CmpInst::Predicate 
Pred, Value *LHS,
   if (Value *V = simplifyICmpInst(Pred, LBO->getOperand(1),
   RBO->getOperand(1), Q, MaxRecurse - 1))
 return V;
+  break;
+}
+// icmp X & C1, X & C2 where (C1 & C2) == C1/C2
+// icmp X | C1, X | C2 where (C1 & C2) == C1/C2
+case Instruction::And:
+case Instruction::Or: {
+  if (ICmpInst::isUnsigned(Pred)) {
+const APInt *C1, *C2;
+if (match(LBO->getOperand(1), m_APInt(C1)) &&
+match(RBO->getOperand(1), m_APInt(C2))) {
+  if (C1->isSubsetOf(*C2)) {
+if (Pred == ICmpInst::ICMP_ULE)
+  return ConstantInt::getTrue(getCompareTy(LHS));
+if (Pred == ICmpInst::ICMP_UGT)
+  return ConstantInt::getFalse(getCompareTy(LHS));
+  }
+  if (C2->isSubsetOf(*C1)) {
+if (Pred == ICmpInst::ICMP_UGE)
+  return ConstantInt::getTrue(getCompareTy(LHS));
+if (Pred == ICmpInst::ICMP_ULT)
+  return ConstantInt::getFalse(getCompareTy(LHS));
+  }
+}
+  }
+  break;
+}
 }
   }
 
diff --git a/llvm/test/Transforms/InstSimplify/compare.ll 
b/llvm/test/Transforms/InstSimplify/compare.ll
index c6c104a41c8be70..d21af97494c88bc 100644
--- a/llvm/test/Transforms/InstSimplify/compare.ll
+++ b/llvm/test/Transforms/InstSimplify/compare.ll
@@ -1919,6 +1919,200 @@ define i1 @tautological8(i32 %A, i32 %B) {
   ret i1 %D
 }
 
+define i1 @tautological9(i32 %A) {
+; CHECK-LABEL: @tautological9(
+; CHECK-NEXT:ret i1 false
+;
+  %C1 = and i32 %A, 1
+  %C2 = and i32 %A, 3
+  %D = icmp ugt i32 %C1, %C2
+  ret i1 %D
+}
+
+define <2 x i1> @tautological9_vec(<2 x i32> %A) {
+; CHECK-LABEL: @tautological9_vec(
+; CHECK-NEXT:ret <2 x i1> zeroinitializer
+;
+  %C1 = and <2 x i32> %A, 
+  %C2 = and <2 x i32> %A, 
+  %D = icmp ugt <2 x i32> %C1, %C2
+  ret <2 x i1> %D
+}
+
+define i1 @tautological10(i32 %A) {
+; CHECK-LABEL: @tautological10(
+; CHECK-NEXT:ret i1 true
+;
+  %C1 = and i32 %A, 1
+  %C2 = and i32 %A, 3
+  %D = icmp ule i32 %C1, %C2
+  ret i1 %D
+}
+
+define i1 @tautological11(i32 %A) {
+; CHECK-LABEL: @tautological11(
+; CHECK-NEXT:ret i1 true
+;
+  %C1 = or i32 %A, 1
+  %C2 = or i32 %A, 3
+  %D = icmp ule i32 %C1, %C2
+  ret i1 %D
+}
+
+define i1 @tautological12(i32 %A) {
+; CHECK-LABEL: @tautological12(
+; CHECK-NEXT:ret i1 false
+;
+  %C1 = or i32 %A, 1
+  %C2 = or i32 %A, 3
+  %D = icmp ugt i32 %C1, %C2
+  ret i1 %D
+}
+
+define i1 @tautological13(i32 %A) {
+; CHECK-LABEL: @tautological13(
+; CHECK-NEXT:ret i1 false
+;
+  %C1 = or i32 %A, 1
+  %C2 = or i32 %A, 3
+  %D = icmp ult i32 %C2, %C1
+  ret i1 %D
+}
+
+define i1 @tautological14(i32 %A) {
+; CHECK-LABEL: @tautological14(
+; CHECK-NEXT:ret i1 true
+;
+  %C1 = or i32 %A, 1
+  %C2 = or i32 %A, 3
+  %D = icmp uge i32 %C2, %C1
+  ret i1 %D
+}
+
+define i1 @tautological15(i32 %A) {
+; CHECK-LABEL: @tautological15(
+; CHECK-NEXT:ret i1 true
+;
+  %C1 = and i32 %A, 1
+  %C2 = and i32 %A, 3
+  %D = icmp uge i32 %C2, %C1
+  ret i1 %D
+}
+
+define i1 @tautological16(i32 %A) {
+; CHECK-LABEL: @tautological16(
+; CHECK-NEXT:ret i1 false
+;
+  %C1 = and i32 %A, 1
+  %C2 = and i32 %A, 3
+  %D = icmp ult i32 %C2, %C1
+  ret i1 %D
+}
+
+define i1 @tautological9_negative(i32 %A) {
+; CHECK-LABEL: @tautological9_negative(
+; CHECK-NEXT:[[C1:%.*]] = and i32 [[A:%.*]], 1
+; CHECK-NEXT:[[C2:%.*]] = and i32 [[A]], 2
+; CHECK-NEXT:[[D:%.*]] = icmp ugt i32 [[C1]], [[C2]]
+; CHECK-NEXT:ret i1 [[D]]
+;
+  %C1 = and i32 %A, 1
+  %C2 = and i32 %A, 2
+  %D = icmp ugt i32 %C1, %C2
+  ret i1 %D
+}
+
+define i1 @tautologi

[clang-tools-extra] [InstSimplify] Simplify `icmp X & C1, X & C2` when `(C1 & C2) == C1/C2` (PR #65905)

2023-09-17 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw updated 
https://github.com/llvm/llvm-project/pull/65905

>From f178af6d47ce6d982c6568ba6e0db517de124291 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Mon, 11 Sep 2023 02:01:12 +0800
Subject: [PATCH] [InstSimplify] Simplify `icmp X & C1, X & C2` when `(C1 & C2)
 == C1/C2`

---
 llvm/lib/Analysis/InstructionSimplify.cpp |  28 ++-
 llvm/test/Transforms/InstSimplify/compare.ll  | 194 ++
 .../InstSimplify/maxmin_intrinsics.ll |  97 +
 3 files changed, 318 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp 
b/llvm/lib/Analysis/InstructionSimplify.cpp
index d0cc56ebc2be319..734029f1ad0bef5 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -3427,7 +3427,7 @@ static Value *simplifyICmpWithBinOp(CmpInst::Predicate 
Pred, Value *LHS,
 switch (LBO->getOpcode()) {
 default:
   break;
-case Instruction::Shl:
+case Instruction::Shl: {
   bool NUW = Q.IIQ.hasNoUnsignedWrap(LBO) && Q.IIQ.hasNoUnsignedWrap(RBO);
   bool NSW = Q.IIQ.hasNoSignedWrap(LBO) && Q.IIQ.hasNoSignedWrap(RBO);
   if (!NUW || (ICmpInst::isSigned(Pred) && !NSW) ||
@@ -3436,6 +3436,32 @@ static Value *simplifyICmpWithBinOp(CmpInst::Predicate 
Pred, Value *LHS,
   if (Value *V = simplifyICmpInst(Pred, LBO->getOperand(1),
   RBO->getOperand(1), Q, MaxRecurse - 1))
 return V;
+  break;
+}
+// icmp X & C1, X & C2 where (C1 & C2) == C1/C2
+// icmp X | C1, X | C2 where (C1 & C2) == C1/C2
+case Instruction::And:
+case Instruction::Or: {
+  if (ICmpInst::isUnsigned(Pred)) {
+const APInt *C1, *C2;
+if (match(LBO->getOperand(1), m_APInt(C1)) &&
+match(RBO->getOperand(1), m_APInt(C2))) {
+  if (C1->isSubsetOf(*C2)) {
+if (Pred == ICmpInst::ICMP_ULE)
+  return ConstantInt::getTrue(getCompareTy(LHS));
+if (Pred == ICmpInst::ICMP_UGT)
+  return ConstantInt::getFalse(getCompareTy(LHS));
+  }
+  if (C2->isSubsetOf(*C1)) {
+if (Pred == ICmpInst::ICMP_UGE)
+  return ConstantInt::getTrue(getCompareTy(LHS));
+if (Pred == ICmpInst::ICMP_ULT)
+  return ConstantInt::getFalse(getCompareTy(LHS));
+  }
+}
+  }
+  break;
+}
 }
   }
 
diff --git a/llvm/test/Transforms/InstSimplify/compare.ll 
b/llvm/test/Transforms/InstSimplify/compare.ll
index c6c104a41c8be70..d21af97494c88bc 100644
--- a/llvm/test/Transforms/InstSimplify/compare.ll
+++ b/llvm/test/Transforms/InstSimplify/compare.ll
@@ -1919,6 +1919,200 @@ define i1 @tautological8(i32 %A, i32 %B) {
   ret i1 %D
 }
 
+define i1 @tautological9(i32 %A) {
+; CHECK-LABEL: @tautological9(
+; CHECK-NEXT:ret i1 false
+;
+  %C1 = and i32 %A, 1
+  %C2 = and i32 %A, 3
+  %D = icmp ugt i32 %C1, %C2
+  ret i1 %D
+}
+
+define <2 x i1> @tautological9_vec(<2 x i32> %A) {
+; CHECK-LABEL: @tautological9_vec(
+; CHECK-NEXT:ret <2 x i1> zeroinitializer
+;
+  %C1 = and <2 x i32> %A, 
+  %C2 = and <2 x i32> %A, 
+  %D = icmp ugt <2 x i32> %C1, %C2
+  ret <2 x i1> %D
+}
+
+define i1 @tautological10(i32 %A) {
+; CHECK-LABEL: @tautological10(
+; CHECK-NEXT:ret i1 true
+;
+  %C1 = and i32 %A, 1
+  %C2 = and i32 %A, 3
+  %D = icmp ule i32 %C1, %C2
+  ret i1 %D
+}
+
+define i1 @tautological11(i32 %A) {
+; CHECK-LABEL: @tautological11(
+; CHECK-NEXT:ret i1 true
+;
+  %C1 = or i32 %A, 1
+  %C2 = or i32 %A, 3
+  %D = icmp ule i32 %C1, %C2
+  ret i1 %D
+}
+
+define i1 @tautological12(i32 %A) {
+; CHECK-LABEL: @tautological12(
+; CHECK-NEXT:ret i1 false
+;
+  %C1 = or i32 %A, 1
+  %C2 = or i32 %A, 3
+  %D = icmp ugt i32 %C1, %C2
+  ret i1 %D
+}
+
+define i1 @tautological13(i32 %A) {
+; CHECK-LABEL: @tautological13(
+; CHECK-NEXT:ret i1 false
+;
+  %C1 = or i32 %A, 1
+  %C2 = or i32 %A, 3
+  %D = icmp ult i32 %C2, %C1
+  ret i1 %D
+}
+
+define i1 @tautological14(i32 %A) {
+; CHECK-LABEL: @tautological14(
+; CHECK-NEXT:ret i1 true
+;
+  %C1 = or i32 %A, 1
+  %C2 = or i32 %A, 3
+  %D = icmp uge i32 %C2, %C1
+  ret i1 %D
+}
+
+define i1 @tautological15(i32 %A) {
+; CHECK-LABEL: @tautological15(
+; CHECK-NEXT:ret i1 true
+;
+  %C1 = and i32 %A, 1
+  %C2 = and i32 %A, 3
+  %D = icmp uge i32 %C2, %C1
+  ret i1 %D
+}
+
+define i1 @tautological16(i32 %A) {
+; CHECK-LABEL: @tautological16(
+; CHECK-NEXT:ret i1 false
+;
+  %C1 = and i32 %A, 1
+  %C2 = and i32 %A, 3
+  %D = icmp ult i32 %C2, %C1
+  ret i1 %D
+}
+
+define i1 @tautological9_negative(i32 %A) {
+; CHECK-LABEL: @tautological9_negative(
+; CHECK-NEXT:[[C1:%.*]] = and i32 [[A:%.*]], 1
+; CHECK-NEXT:[[C2:%.*]] = and i32 [[A]], 2
+; CHECK-NEXT:[[D:%.*]] = icmp ugt i32 [[C1]], [[C2]]
+; CHECK-NEXT:ret i1 [[D]]
+;
+  %C1 = and i32 %A, 1
+  %C2 = and i32 %A, 2
+  %D = icmp ugt i32 %C1, %C2
+  ret i1 %D
+}
+
+define i1 @tautologi

[clang] [InstSimplify] Simplify `icmp X & C1, X & C2` when `(C1 & C2) == C1/C2` (PR #65905)

2023-09-17 Thread Yingwei Zheng via cfe-commits

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


[clang] [InstSimplify] Simplify `icmp X & C1, X & C2` when `(C1 & C2) == C1/C2` (PR #65905)

2023-09-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-transforms


Changes

This patch simplifies the pattern `icmp X & C1, X & C2` when one 
constant mask is the subset of the other.
Alive2: https://alive2.llvm.org/ce/z/s-IEK7
Fixes #65833.

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


3 Files Affected:

- (modified) llvm/lib/Analysis/InstructionSimplify.cpp (+27-1) 
- (modified) llvm/test/Transforms/InstSimplify/compare.ll (+9-36) 
- (modified) llvm/test/Transforms/InstSimplify/maxmin_intrinsics.ll (+6-14) 


``diff
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp 
b/llvm/lib/Analysis/InstructionSimplify.cpp
index 2a3011075e47ed7..1ca1f27b9ab992d 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -3427,7 +3427,7 @@ static Value *simplifyICmpWithBinOp(CmpInst::Predicate 
Pred, Value *LHS,
 switch (LBO->getOpcode()) {
 default:
   break;
-case Instruction::Shl:
+case Instruction::Shl: {
   bool NUW = Q.IIQ.hasNoUnsignedWrap(LBO) && Q.IIQ.hasNoUnsignedWrap(RBO);
   bool NSW = Q.IIQ.hasNoSignedWrap(LBO) && Q.IIQ.hasNoSignedWrap(RBO);
   if (!NUW || (ICmpInst::isSigned(Pred) && !NSW) ||
@@ -3436,6 +3436,32 @@ static Value *simplifyICmpWithBinOp(CmpInst::Predicate 
Pred, Value *LHS,
   if (Value *V = simplifyICmpInst(Pred, LBO->getOperand(1),
   RBO->getOperand(1), Q, MaxRecurse - 1))
 return V;
+  break;
+}
+// icmp X & C1, X & C2 where (C1 & C2) == C1/C2
+// icmp X | C1, X | C2 where (C1 & C2) == C1/C2
+case Instruction::And:
+case Instruction::Or: {
+  if (ICmpInst::isUnsigned(Pred)) {
+const APInt *C1, *C2;
+if (match(LBO->getOperand(1), m_APInt(C1)) &&
+match(RBO->getOperand(1), m_APInt(C2))) {
+  if (C1->isSubsetOf(*C2)) {
+if (Pred == ICmpInst::ICMP_ULE)
+  return ConstantInt::getTrue(getCompareTy(LHS));
+if (Pred == ICmpInst::ICMP_UGT)
+  return ConstantInt::getFalse(getCompareTy(LHS));
+  }
+  if (C2->isSubsetOf(*C1)) {
+if (Pred == ICmpInst::ICMP_UGE)
+  return ConstantInt::getTrue(getCompareTy(LHS));
+if (Pred == ICmpInst::ICMP_ULT)
+  return ConstantInt::getFalse(getCompareTy(LHS));
+  }
+}
+  }
+  break;
+}
 }
   }
 
diff --git a/llvm/test/Transforms/InstSimplify/compare.ll 
b/llvm/test/Transforms/InstSimplify/compare.ll
index cb3805932cbc5be..d21af97494c88bc 100644
--- a/llvm/test/Transforms/InstSimplify/compare.ll
+++ b/llvm/test/Transforms/InstSimplify/compare.ll
@@ -1921,10 +1921,7 @@ define i1 @tautological8(i32 %A, i32 %B) {
 
 define i1 @tautological9(i32 %A) {
 ; CHECK-LABEL: @tautological9(
-; CHECK-NEXT:[[C1:%.*]] = and i32 [[A:%.*]], 1
-; CHECK-NEXT:[[C2:%.*]] = and i32 [[A]], 3
-; CHECK-NEXT:[[D:%.*]] = icmp ugt i32 [[C1]], [[C2]]
-; CHECK-NEXT:ret i1 [[D]]
+; CHECK-NEXT:ret i1 false
 ;
   %C1 = and i32 %A, 1
   %C2 = and i32 %A, 3
@@ -1934,10 +1931,7 @@ define i1 @tautological9(i32 %A) {
 
 define <2 x i1> @tautological9_vec(<2 x i32> %A) {
 ; CHECK-LABEL: @tautological9_vec(
-; CHECK-NEXT:[[C1:%.*]] = and <2 x i32> [[A:%.*]], 
-; CHECK-NEXT:[[C2:%.*]] = and <2 x i32> [[A]], 
-; CHECK-NEXT:[[D:%.*]] = icmp ugt <2 x i32> [[C1]], [[C2]]
-; CHECK-NEXT:ret <2 x i1> [[D]]
+; CHECK-NEXT:ret <2 x i1> zeroinitializer
 ;
   %C1 = and <2 x i32> %A, 
   %C2 = and <2 x i32> %A, 
@@ -1947,10 +1941,7 @@ define <2 x i1> @tautological9_vec(<2 x i32> %A) {
 
 define i1 @tautological10(i32 %A) {
 ; CHECK-LABEL: @tautological10(
-; CHECK-NEXT:[[C1:%.*]] = and i32 [[A:%.*]], 1
-; CHECK-NEXT:[[C2:%.*]] = and i32 [[A]], 3
-; CHECK-NEXT:[[D:%.*]] = icmp ule i32 [[C1]], [[C2]]
-; CHECK-NEXT:ret i1 [[D]]
+; CHECK-NEXT:ret i1 true
 ;
   %C1 = and i32 %A, 1
   %C2 = and i32 %A, 3
@@ -1960,10 +1951,7 @@ define i1 @tautological10(i32 %A) {
 
 define i1 @tautological11(i32 %A) {
 ; CHECK-LABEL: @tautological11(
-; CHECK-NEXT:[[C1:%.*]] = or i32 [[A:%.*]], 1
-; CHECK-NEXT:[[C2:%.*]] = or i32 [[A]], 3
-; CHECK-NEXT:[[D:%.*]] = icmp ule i32 [[C1]], [[C2]]
-; CHECK-NEXT:ret i1 [[D]]
+; CHECK-NEXT:ret i1 true
 ;
   %C1 = or i32 %A, 1
   %C2 = or i32 %A, 3
@@ -1973,10 +1961,7 @@ define i1 @tautological11(i32 %A) {
 
 define i1 @tautological12(i32 %A) {
 ; CHECK-LABEL: @tautological12(
-; CHECK-NEXT:[[C1:%.*]] = or i32 [[A:%.*]], 1
-; CHECK-NEXT:[[C2:%.*]] = or i32 [[A]], 3
-; CHECK-NEXT:[[D:%.*]] = icmp ugt i32 [[C1]], [[C2]]
-; CHECK-NEXT:ret i1 [[D]]
+; CHECK-NEXT:ret i1 false
 ;
   %C1 = or i32 %A, 1
   %C2 = or i32 %A, 3
@@ -1986,10 +1971,7 @@ define i1 @tautological12(i32 %A) {
 
 define i1 @tautological13(i32 %A) {
 ; CHECK-LABEL: @tautological13(
-; CHECK-NEXT:[[C1:%.*]] = or i32 [[A:%.*]], 1
-; CHECK-NEXT:[[C2:%.*]] = or i32 [[A]], 3
-; CH

[clang] [InstCombine] Fix transforms of two select patterns (PR #65845)

2023-09-17 Thread Nikita Popov via cfe-commits

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

LGTM

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


[clang] [clang] Enable --print-supported-extensions for all targets (PR #66586)

2023-09-17 Thread Balint Cristian via cfe-commits

https://github.com/cbalint13 updated 
https://github.com/llvm/llvm-project/pull/66586

>From 7bbe54c0649c2abd29d51e538d2b0bf77359d0f8 Mon Sep 17 00:00:00 2001
From: Balint Cristian 
Date: Sun, 17 Sep 2023 16:16:40 +0300
Subject: [PATCH] [clang] Enable --print-supported-extensions for all targets

Signed-off-by: Balint Cristian 
---
 clang/include/clang/Driver/Options.td |  2 +-
 clang/lib/Driver/Driver.cpp   | 14 ++-
 .../test/Driver/print-supported-extensions.c  | 10 
 clang/tools/driver/cc1_main.cpp   | 25 +++
 llvm/include/llvm/MC/MCSubtargetInfo.h|  6 +
 5 files changed, 23 insertions(+), 34 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 553c7928c4f949e..431f2f5c4109232 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5277,7 +5277,7 @@ def print_supported_cpus : Flag<["-", "--"], 
"print-supported-cpus">,
   MarshallingInfoFlag>;
 def print_supported_extensions : Flag<["-", "--"], 
"print-supported-extensions">,
   Visibility<[ClangOption, CC1Option, CLOption]>,
-  HelpText<"Print supported -march extensions (RISC-V, AArch64 and ARM only)">,
+  HelpText<"Print supported -march extensions">,
   MarshallingInfoFlag>;
 def : Flag<["-"], "mcpu=help">, Alias;
 def : Flag<["-"], "mtune=help">, Alias;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 84b8fc7685fed42..5b6b14d175f5299 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4279,19 +4279,9 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
 // If --print-supported-cpus, -mcpu=? or -mtune=? is specified, build a
 // custom Compile phase that prints out supported cpu models and quits.
 //
-// If --print-supported-extensions is specified, call the helper function
-// RISCVMarchHelp in RISCVISAInfo.cpp that prints out supported extensions
-// and quits.
+// If --print-supported-extensions is specified, list all supported flags
+// within the target and quit.
 if (Arg *A = Args.getLastArg(Opt)) {
-  if (Opt == options::OPT_print_supported_extensions &&
-  !C.getDefaultToolChain().getTriple().isRISCV() &&
-  !C.getDefaultToolChain().getTriple().isAArch64() &&
-  !C.getDefaultToolChain().getTriple().isARM()) {
-C.getDriver().Diag(diag::err_opt_not_valid_on_target)
-<< "--print-supported-extensions";
-return;
-  }
-
   // Use the -mcpu=? flag as the dummy input to cc1.
   Actions.clear();
   Action *InputAc = C.MakeAction(*A, types::TY_C);
diff --git a/clang/test/Driver/print-supported-extensions.c 
b/clang/test/Driver/print-supported-extensions.c
index 8daf4d8a34b8a60..d233e9fb783e2e2 100644
--- a/clang/test/Driver/print-supported-extensions.c
+++ b/clang/test/Driver/print-supported-extensions.c
@@ -3,16 +3,16 @@
 
 // RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
-// AARCH64: All available -march extensions for AArch64
+// AARCH64: All available -march extensions for aarch64
 
 // RUN: %if riscv-registered-target %{ %clang --target=riscv64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
RISCV %}
-// RISCV: All available -march extensions for RISC-V
+// RISCV: All available -march extensions for riscv64
 
 // RUN: %if arm-registered-target %{ %clang --target=arm-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix ARM 
%}
-// ARM: All available -march extensions for ARM
+// ARM: All available -march extensions for arm
 
-// RUN: %if x86-registered-target %{ not %clang --target=x86_64-linux-gnu \
+// RUN: %if x86-registered-target %{ %clang --target=x86_64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix X86 
%}
-// X86: error: option '--print-supported-extensions' cannot be specified on 
this target
\ No newline at end of file
+// X86: All available -march extensions for x86-64
diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp
index f0d7b5c3889dc1f..20542cb9aa7a913 100644
--- a/clang/tools/driver/cc1_main.cpp
+++ b/clang/tools/driver/cc1_main.cpp
@@ -38,16 +38,14 @@
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/TimeProfiler.h"
 #include "llvm/Support/Timer.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetMachine.h"
-#include "llvm/TargetParser/AArch64TargetParser.h"
-#include "llvm/TargetParser/ARMTargetParser.h"
 #include 
+#include 
 
 #ifdef CLANG_HAVE_RLIMITS
 #include 
@@ -197,19 +195,14 @@ static int PrintSupport

[clang] [clang] Enable --print-supported-extensions for all targets (PR #66586)

2023-09-17 Thread Balint Cristian via cfe-commits

https://github.com/cbalint13 updated 
https://github.com/llvm/llvm-project/pull/66586

>From 689b322408caff8340ffef4dd526d3640958ea03 Mon Sep 17 00:00:00 2001
From: Balint Cristian 
Date: Sun, 17 Sep 2023 16:52:15 +0300
Subject: [PATCH] [clang] Enable --print-supported-extensions for all targets

Signed-off-by: Balint Cristian 
---
 clang/include/clang/Driver/Options.td |  2 +-
 clang/lib/Driver/Driver.cpp   | 14 ++-
 .../test/Driver/print-supported-extensions.c  | 10 
 clang/tools/driver/cc1_main.cpp   | 25 +++
 llvm/include/llvm/MC/MCSubtargetInfo.h|  6 +
 5 files changed, 23 insertions(+), 34 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 553c7928c4f949e..431f2f5c4109232 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5277,7 +5277,7 @@ def print_supported_cpus : Flag<["-", "--"], 
"print-supported-cpus">,
   MarshallingInfoFlag>;
 def print_supported_extensions : Flag<["-", "--"], 
"print-supported-extensions">,
   Visibility<[ClangOption, CC1Option, CLOption]>,
-  HelpText<"Print supported -march extensions (RISC-V, AArch64 and ARM only)">,
+  HelpText<"Print supported -march extensions">,
   MarshallingInfoFlag>;
 def : Flag<["-"], "mcpu=help">, Alias;
 def : Flag<["-"], "mtune=help">, Alias;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 84b8fc7685fed42..5b6b14d175f5299 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4279,19 +4279,9 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
 // If --print-supported-cpus, -mcpu=? or -mtune=? is specified, build a
 // custom Compile phase that prints out supported cpu models and quits.
 //
-// If --print-supported-extensions is specified, call the helper function
-// RISCVMarchHelp in RISCVISAInfo.cpp that prints out supported extensions
-// and quits.
+// If --print-supported-extensions is specified, list all supported flags
+// within the target and quit.
 if (Arg *A = Args.getLastArg(Opt)) {
-  if (Opt == options::OPT_print_supported_extensions &&
-  !C.getDefaultToolChain().getTriple().isRISCV() &&
-  !C.getDefaultToolChain().getTriple().isAArch64() &&
-  !C.getDefaultToolChain().getTriple().isARM()) {
-C.getDriver().Diag(diag::err_opt_not_valid_on_target)
-<< "--print-supported-extensions";
-return;
-  }
-
   // Use the -mcpu=? flag as the dummy input to cc1.
   Actions.clear();
   Action *InputAc = C.MakeAction(*A, types::TY_C);
diff --git a/clang/test/Driver/print-supported-extensions.c 
b/clang/test/Driver/print-supported-extensions.c
index 8daf4d8a34b8a60..d233e9fb783e2e2 100644
--- a/clang/test/Driver/print-supported-extensions.c
+++ b/clang/test/Driver/print-supported-extensions.c
@@ -3,16 +3,16 @@
 
 // RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
-// AARCH64: All available -march extensions for AArch64
+// AARCH64: All available -march extensions for aarch64
 
 // RUN: %if riscv-registered-target %{ %clang --target=riscv64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
RISCV %}
-// RISCV: All available -march extensions for RISC-V
+// RISCV: All available -march extensions for riscv64
 
 // RUN: %if arm-registered-target %{ %clang --target=arm-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix ARM 
%}
-// ARM: All available -march extensions for ARM
+// ARM: All available -march extensions for arm
 
-// RUN: %if x86-registered-target %{ not %clang --target=x86_64-linux-gnu \
+// RUN: %if x86-registered-target %{ %clang --target=x86_64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix X86 
%}
-// X86: error: option '--print-supported-extensions' cannot be specified on 
this target
\ No newline at end of file
+// X86: All available -march extensions for x86-64
diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp
index f0d7b5c3889dc1f..eabc2beaf04f2fb 100644
--- a/clang/tools/driver/cc1_main.cpp
+++ b/clang/tools/driver/cc1_main.cpp
@@ -28,6 +28,7 @@
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/LinkAllPasses.h"
+#include "llvm/MC/MCSubtargetInfo.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Option/Arg.h"
 #include "llvm/Option/ArgList.h"
@@ -38,15 +39,12 @@
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/TimeProfiler.h"
 #include "llvm/Support/Timer.h"
 #include "llvm/Support/r

[PATCH] D70401: [RISCV] CodeGen of RVE and ilp32e/lp64e ABIs

2023-09-17 Thread Luo Jia via Phabricator via cfe-commits
luojia added a comment.

In D70401#4635875 , @koute wrote:

> I know that there are still open issues regarding the psABI, but considering 
> how slow it's been going, couldn't we merge this in anyway and mark it as 
> experimental and subject to change? Please?
>
> The patch is simple enough to not become a maintenance burden, and GCC 
> already has it even though the ABI's unfinished, and the RV32E target itself 
> is most likely going to be used for standalone bare metal programs where the 
> exact ABI shouldn't matter too much as long as it works.
>
> I'm asking because I'd **really** like to have this merged so that I could 
> use Rust to target RV32E/RV64E. Right now I have to maintain my own 
> toolchain, which is painful; if this got merged (even in an experimental 
> fashion, like GCC has) I could just get upstream Rust to support it 
> out-of-box.

I agree. Lots of our Rust work on low-level RISC-V cores (embedded, monitor 
hart, etc.) rely on RVE and they depend on RVE support on LLVM. We've waited 
for LLVM upstream support for an amount of years; considering how much time the 
community have waited for, RVE codegen can be accepted even if it's marked 
experimental.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70401/new/

https://reviews.llvm.org/D70401

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


[PATCH] D74094: Reapply: [IRGen] Emit lifetime intrinsics around temporary aggregate argument allocas

2023-09-17 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In D74094#4646975 , @xbolva00 wrote:

>>> So we can start by giving these objects full-expression lifetime, chase 
>>> down any program bugs that that uncovers (which will all *unquestionably* 
>>> be program bugs under the standard), and then gradually work on landing the 
>>> more aggressive rule (perhaps even for non-trivial types).
>
> maybe provide a new flag to control this behaviour?

You mean for when we start limiting lifetimes to the call rather than the 
full-expression?  I don't know that we want such a flag in the long term, but 
having at least a -cc1 flag is usually helpful when we're bringing up 
new/stricter optimizations, yeah.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74094/new/

https://reviews.llvm.org/D74094

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


[PATCH] D74094: Reapply: [IRGen] Emit lifetime intrinsics around temporary aggregate argument allocas

2023-09-17 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

Yes, cc1 flag would be useful.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74094/new/

https://reviews.llvm.org/D74094

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


[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)

2023-09-17 Thread via cfe-commits

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


[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)

2023-09-17 Thread via cfe-commits

https://github.com/5chmidti updated 
https://github.com/llvm/llvm-project/pull/66583

>From 8f5e9e6024b0db8f251625669adbc5d607da83cb Mon Sep 17 00:00:00 2001
From: Julian Schmidt <44101708+5chmi...@users.noreply.github.com>
Date: Sat, 16 Sep 2023 16:24:13 +0200
Subject: [PATCH 1/5] [clang-tidy] add modernize-use-std-numbers check

This check finds constants and function calls to math functions that can be 
replaced
with c++20's mathematical constants ('numbers' header) and offers fixit-hints.
Does not match the use of variables or macros with that value and instead, 
offers a replacement
at the definition of said variables and macros.
---
 .../clang-tidy/modernize/CMakeLists.txt   |   1 +
 .../modernize/ModernizeTidyModule.cpp |   3 +
 .../modernize/UseStdNumbersCheck.cpp  | 377 ++
 .../clang-tidy/modernize/UseStdNumbersCheck.h |  37 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |   6 +
 .../docs/clang-tidy/checks/list.rst   |   3 +-
 .../checks/modernize/use-std-numbers.rst  |  25 ++
 .../checkers/modernize/use-std-numbers.cpp| 205 ++
 8 files changed, 656 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
 create mode 100644 clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-numbers.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-numbers.cpp

diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 717c400c4790330..d82353d74fbd0d4 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -16,6 +16,7 @@ add_clang_library(clangTidyModernizeModule
   MakeSharedCheck.cpp
   MakeSmartPtrCheck.cpp
   MakeUniqueCheck.cpp
+  UseStdNumbersCheck.cpp
   ModernizeTidyModule.cpp
   PassByValueCheck.cpp
   RawStringLiteralCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 73751cf2705068d..73584e20166f66a 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -18,6 +18,7 @@
 #include "MacroToEnumCheck.h"
 #include "MakeSharedCheck.h"
 #include "MakeUniqueCheck.h"
+#include "UseStdNumbersCheck.h"
 #include "PassByValueCheck.h"
 #include "RawStringLiteralCheck.h"
 #include "RedundantVoidArgCheck.h"
@@ -65,6 +66,8 @@ class ModernizeModule : public ClangTidyModule {
 CheckFactories.registerCheck("modernize-macro-to-enum");
 CheckFactories.registerCheck("modernize-make-shared");
 CheckFactories.registerCheck("modernize-make-unique");
+CheckFactories.registerCheck(
+"modernize-use-std-numbers");
 CheckFactories.registerCheck("modernize-pass-by-value");
 CheckFactories.registerCheck("modernize-use-std-print");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
new file mode 100644
index 000..c23dc6671013bc3
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
@@ -0,0 +1,377 @@
+//===--- UseStdNumbersCheck.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 "UseStdNumbersCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersInternal.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/TokenKinds.h"
+#include "clang/Lex/PPCallbacks.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/Token.h"
+#include "clang/Tooling/Transformer/RewriteRule.h"
+#include "clang/Tooling/Transformer/Stencil.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/MathExtras.h"
+#include 
+#include 
+
+namespace {
+using namespace clang::ast_matchers;
+using clang::ast_matchers::internal::Matcher;
+using clang::transformer::addInclude;
+using clang::transformer::applyFirst;
+using clang::transformer::ASTEdit;
+using clang::transformer::cat;
+using clang::transformer::changeTo;
+using clang::transformer::edit;
+using clang::transformer::EditGenerator;
+using clang::transformer::flattenVector;
+using clang::transformer::RewriteRuleWith;
+using llvm::StringRef;
+
+constexpr double Pi = 3.1415926535897932384

[clang] [AArch64]: Refactor target parser to use Bitset. (PR #65423)

2023-09-17 Thread Craig Topper via cfe-commits


@@ -96,65 +97,67 @@ static_assert(FEAT_MAX <= 64,
 // Arch extension modifiers for CPUs. These are labelled with their Arm ARM
 // feature name (though the canonical reference for those is AArch64.td)
 // clang-format off
-enum ArchExtKind : uint64_t {
-  AEK_NONE =1,
-  AEK_CRC = 1 << 1,  // FEAT_CRC32
-  AEK_CRYPTO =  1 << 2,
-  AEK_FP =  1 << 3,  // FEAT_FP
-  AEK_SIMD =1 << 4,  // FEAT_AdvSIMD
-  AEK_FP16 =1 << 5,  // FEAT_FP16
-  AEK_PROFILE = 1 << 6,  // FEAT_SPE
-  AEK_RAS = 1 << 7,  // FEAT_RAS, FEAT_RASv1p1
-  AEK_LSE = 1 << 8,  // FEAT_LSE
-  AEK_SVE = 1 << 9,  // FEAT_SVE
-  AEK_DOTPROD = 1 << 10, // FEAT_DotProd
-  AEK_RCPC =1 << 11, // FEAT_LRCPC
-  AEK_RDM = 1 << 12, // FEAT_RDM
-  AEK_SM4 = 1 << 13, // FEAT_SM4, FEAT_SM3
-  AEK_SHA3 =1 << 14, // FEAT_SHA3, FEAT_SHA512
-  AEK_SHA2 =1 << 15, // FEAT_SHA1, FEAT_SHA256
-  AEK_AES = 1 << 16, // FEAT_AES, FEAT_PMULL
-  AEK_FP16FML = 1 << 17, // FEAT_FHM
-  AEK_RAND =1 << 18, // FEAT_RNG
-  AEK_MTE = 1 << 19, // FEAT_MTE, FEAT_MTE2
-  AEK_SSBS =1 << 20, // FEAT_SSBS, FEAT_SSBS2
-  AEK_SB =  1 << 21, // FEAT_SB
-  AEK_PREDRES = 1 << 22, // FEAT_SPECRES
-  AEK_SVE2 =1 << 23, // FEAT_SVE2
-  AEK_SVE2AES = 1 << 24, // FEAT_SVE_AES, FEAT_SVE_PMULL128
-  AEK_SVE2SM4 = 1 << 25, // FEAT_SVE_SM4
-  AEK_SVE2SHA3 =1 << 26, // FEAT_SVE_SHA3
-  AEK_SVE2BITPERM = 1 << 27, // FEAT_SVE_BitPerm
-  AEK_TME = 1 << 28, // FEAT_TME
-  AEK_BF16 =1 << 29, // FEAT_BF16
-  AEK_I8MM =1 << 30, // FEAT_I8MM
-  AEK_F32MM =   1ULL << 31, // FEAT_F32MM
-  AEK_F64MM =   1ULL << 32, // FEAT_F64MM
-  AEK_LS64 =1ULL << 33, // FEAT_LS64, FEAT_LS64_V, FEAT_LS64_ACCDATA
-  AEK_BRBE =1ULL << 34, // FEAT_BRBE
-  AEK_PAUTH =   1ULL << 35, // FEAT_PAuth
-  AEK_FLAGM =   1ULL << 36, // FEAT_FlagM
-  AEK_SME = 1ULL << 37, // FEAT_SME
-  AEK_SMEF64F64 =   1ULL << 38, // FEAT_SME_F64F64
-  AEK_SMEI16I64 =   1ULL << 39, // FEAT_SME_I16I64
-  AEK_HBC = 1ULL << 40, // FEAT_HBC
-  AEK_MOPS =1ULL << 41, // FEAT_MOPS
-  AEK_PERFMON = 1ULL << 42, // FEAT_PMUv3
-  AEK_SME2 =1ULL << 43, // FEAT_SME2
-  AEK_SVE2p1 =  1ULL << 44, // FEAT_SVE2p1
-  AEK_SME2p1 =  1ULL << 45, // FEAT_SME2p1
-  AEK_B16B16 =  1ULL << 46, // FEAT_B16B16
-  AEK_SMEF16F16 =   1ULL << 47, // FEAT_SMEF16F16
-  AEK_CSSC =1ULL << 48, // FEAT_CSSC
-  AEK_RCPC3 =   1ULL << 49, // FEAT_LRCPC3
-  AEK_THE = 1ULL << 50, // FEAT_THE
-  AEK_D128 =1ULL << 51, // FEAT_D128
-  AEK_LSE128 =  1ULL << 52, // FEAT_LSE128
-  AEK_SPECRES2 =1ULL << 53, // FEAT_SPECRES2
-  AEK_RASv2 =   1ULL << 54, // FEAT_RASv2
-  AEK_ITE = 1ULL << 55, // FEAT_ITE
-  AEK_GCS = 1ULL << 56, // FEAT_GCS
+enum ArchExtKind : unsigned {
+  AEK_NONE =  1,

topperc wrote:

Why is bit 0 skipped?

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


[clang-tools-extra] [InstSimplify] Simplify `icmp X & C1, X & C2` when `(C1 & C2) == C1/C2` (PR #65905)

2023-09-17 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw updated 
https://github.com/llvm/llvm-project/pull/65905

>From f178af6d47ce6d982c6568ba6e0db517de124291 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Mon, 11 Sep 2023 02:01:12 +0800
Subject: [PATCH 1/2] [InstSimplify] Simplify `icmp X & C1, X & C2` when `(C1 &
 C2) == C1/C2`

---
 llvm/lib/Analysis/InstructionSimplify.cpp |  28 ++-
 llvm/test/Transforms/InstSimplify/compare.ll  | 194 ++
 .../InstSimplify/maxmin_intrinsics.ll |  97 +
 3 files changed, 318 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp 
b/llvm/lib/Analysis/InstructionSimplify.cpp
index d0cc56ebc2be319..734029f1ad0bef5 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -3427,7 +3427,7 @@ static Value *simplifyICmpWithBinOp(CmpInst::Predicate 
Pred, Value *LHS,
 switch (LBO->getOpcode()) {
 default:
   break;
-case Instruction::Shl:
+case Instruction::Shl: {
   bool NUW = Q.IIQ.hasNoUnsignedWrap(LBO) && Q.IIQ.hasNoUnsignedWrap(RBO);
   bool NSW = Q.IIQ.hasNoSignedWrap(LBO) && Q.IIQ.hasNoSignedWrap(RBO);
   if (!NUW || (ICmpInst::isSigned(Pred) && !NSW) ||
@@ -3436,6 +3436,32 @@ static Value *simplifyICmpWithBinOp(CmpInst::Predicate 
Pred, Value *LHS,
   if (Value *V = simplifyICmpInst(Pred, LBO->getOperand(1),
   RBO->getOperand(1), Q, MaxRecurse - 1))
 return V;
+  break;
+}
+// icmp X & C1, X & C2 where (C1 & C2) == C1/C2
+// icmp X | C1, X | C2 where (C1 & C2) == C1/C2
+case Instruction::And:
+case Instruction::Or: {
+  if (ICmpInst::isUnsigned(Pred)) {
+const APInt *C1, *C2;
+if (match(LBO->getOperand(1), m_APInt(C1)) &&
+match(RBO->getOperand(1), m_APInt(C2))) {
+  if (C1->isSubsetOf(*C2)) {
+if (Pred == ICmpInst::ICMP_ULE)
+  return ConstantInt::getTrue(getCompareTy(LHS));
+if (Pred == ICmpInst::ICMP_UGT)
+  return ConstantInt::getFalse(getCompareTy(LHS));
+  }
+  if (C2->isSubsetOf(*C1)) {
+if (Pred == ICmpInst::ICMP_UGE)
+  return ConstantInt::getTrue(getCompareTy(LHS));
+if (Pred == ICmpInst::ICMP_ULT)
+  return ConstantInt::getFalse(getCompareTy(LHS));
+  }
+}
+  }
+  break;
+}
 }
   }
 
diff --git a/llvm/test/Transforms/InstSimplify/compare.ll 
b/llvm/test/Transforms/InstSimplify/compare.ll
index c6c104a41c8be70..d21af97494c88bc 100644
--- a/llvm/test/Transforms/InstSimplify/compare.ll
+++ b/llvm/test/Transforms/InstSimplify/compare.ll
@@ -1919,6 +1919,200 @@ define i1 @tautological8(i32 %A, i32 %B) {
   ret i1 %D
 }
 
+define i1 @tautological9(i32 %A) {
+; CHECK-LABEL: @tautological9(
+; CHECK-NEXT:ret i1 false
+;
+  %C1 = and i32 %A, 1
+  %C2 = and i32 %A, 3
+  %D = icmp ugt i32 %C1, %C2
+  ret i1 %D
+}
+
+define <2 x i1> @tautological9_vec(<2 x i32> %A) {
+; CHECK-LABEL: @tautological9_vec(
+; CHECK-NEXT:ret <2 x i1> zeroinitializer
+;
+  %C1 = and <2 x i32> %A, 
+  %C2 = and <2 x i32> %A, 
+  %D = icmp ugt <2 x i32> %C1, %C2
+  ret <2 x i1> %D
+}
+
+define i1 @tautological10(i32 %A) {
+; CHECK-LABEL: @tautological10(
+; CHECK-NEXT:ret i1 true
+;
+  %C1 = and i32 %A, 1
+  %C2 = and i32 %A, 3
+  %D = icmp ule i32 %C1, %C2
+  ret i1 %D
+}
+
+define i1 @tautological11(i32 %A) {
+; CHECK-LABEL: @tautological11(
+; CHECK-NEXT:ret i1 true
+;
+  %C1 = or i32 %A, 1
+  %C2 = or i32 %A, 3
+  %D = icmp ule i32 %C1, %C2
+  ret i1 %D
+}
+
+define i1 @tautological12(i32 %A) {
+; CHECK-LABEL: @tautological12(
+; CHECK-NEXT:ret i1 false
+;
+  %C1 = or i32 %A, 1
+  %C2 = or i32 %A, 3
+  %D = icmp ugt i32 %C1, %C2
+  ret i1 %D
+}
+
+define i1 @tautological13(i32 %A) {
+; CHECK-LABEL: @tautological13(
+; CHECK-NEXT:ret i1 false
+;
+  %C1 = or i32 %A, 1
+  %C2 = or i32 %A, 3
+  %D = icmp ult i32 %C2, %C1
+  ret i1 %D
+}
+
+define i1 @tautological14(i32 %A) {
+; CHECK-LABEL: @tautological14(
+; CHECK-NEXT:ret i1 true
+;
+  %C1 = or i32 %A, 1
+  %C2 = or i32 %A, 3
+  %D = icmp uge i32 %C2, %C1
+  ret i1 %D
+}
+
+define i1 @tautological15(i32 %A) {
+; CHECK-LABEL: @tautological15(
+; CHECK-NEXT:ret i1 true
+;
+  %C1 = and i32 %A, 1
+  %C2 = and i32 %A, 3
+  %D = icmp uge i32 %C2, %C1
+  ret i1 %D
+}
+
+define i1 @tautological16(i32 %A) {
+; CHECK-LABEL: @tautological16(
+; CHECK-NEXT:ret i1 false
+;
+  %C1 = and i32 %A, 1
+  %C2 = and i32 %A, 3
+  %D = icmp ult i32 %C2, %C1
+  ret i1 %D
+}
+
+define i1 @tautological9_negative(i32 %A) {
+; CHECK-LABEL: @tautological9_negative(
+; CHECK-NEXT:[[C1:%.*]] = and i32 [[A:%.*]], 1
+; CHECK-NEXT:[[C2:%.*]] = and i32 [[A]], 2
+; CHECK-NEXT:[[D:%.*]] = icmp ugt i32 [[C1]], [[C2]]
+; CHECK-NEXT:ret i1 [[D]]
+;
+  %C1 = and i32 %A, 1
+  %C2 = and i32 %A, 2
+  %D = icmp ugt i32 %C1, %C2
+  ret i1 %D
+}
+
+define i1 @tauto

[clang-tools-extra] [InstSimplify] Simplify `icmp X & C1, X & C2` when `(C1 & C2) == C1/C2` (PR #65905)

2023-09-17 Thread Yingwei Zheng via cfe-commits

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


[clang] [InstSimplify] Simplify `icmp X & C1, X & C2` when `(C1 & C2) == C1/C2` (PR #65905)

2023-09-17 Thread Yingwei Zheng via cfe-commits

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


[clang-tools-extra] [InstSimplify] Simplify `icmp X & C1, X & C2` when `(C1 & C2) == C1/C2` (PR #65905)

2023-09-17 Thread Yingwei Zheng via cfe-commits

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


[clang] [InstSimplify] Simplify `icmp X & C1, X & C2` when `(C1 & C2) == C1/C2` (PR #65905)

2023-09-17 Thread Yingwei Zheng via cfe-commits

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


[clang-tools-extra] [InstSimplify] Simplify `icmp X & C1, X & C2` when `(C1 & C2) == C1/C2` (PR #65905)

2023-09-17 Thread Yingwei Zheng via cfe-commits

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


[clang-tools-extra] [InstSimplify] Fold icmp of `X and/or C1` and `X and/or C2` into constant (PR #65905)

2023-09-17 Thread Yingwei Zheng via cfe-commits

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


[clang] [InstSimplify] Fold icmp of `X and/or C1` and `X and/or C2` into constant (PR #65905)

2023-09-17 Thread Yingwei Zheng via cfe-commits

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


[clang] [InstSimplify] Fold icmp of `X and/or C1` and `X and/or C2` into constant (PR #65905)

2023-09-17 Thread Yingwei Zheng via cfe-commits

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


[clang-tools-extra] [InstSimplify] Fold icmp of `X and/or C1` and `X and/or C2` into constant (PR #65905)

2023-09-17 Thread Yingwei Zheng via cfe-commits

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


[clang] [InstCombine] Fix transforms of two select patterns (PR #65845)

2023-09-17 Thread Yingwei Zheng via cfe-commits

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


[clang-tools-extra] [clang-tidy] Update llvmlibc-implementation-in-namespace to new rules (PR #66504)

2023-09-17 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp commented:

Should this change be reflected in the Release Notes?

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


[clang-tools-extra] [clang-tidy] Fix bug in modernize-use-emplace (PR #66169)

2023-09-17 Thread Carlos Galvez via cfe-commits


@@ -1332,6 +1337,17 @@ void testBracedInitTemporaries() {
   v3.push_back(NonTrivialWithCtor{{}});
   v3.push_back({{0}});
   v3.push_back({{}});
+
+  std::vector v4;
+
+  // These should not be noticed or fixed; after the correction, the code won't
+  // compile.
+  v4.push_back(NonTrivialWithIntAndVector{1, {}});
+  // CHECK-FIXES: v4.push_back(NonTrivialWithIntAndVector{1, {}});
+  v4.push_back(NonTrivialWithIntAndVector{});
+  // CHECK-FIXES: v4.push_back(NonTrivialWithIntAndVector{});

carlosgalvezp wrote:

We typically do not use `CHECK-FIXES` to ensure the code has not changed - the 
fact that a warning is not triggered should be enough (see rest of file).

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


[clang-tools-extra] [clang-tidy] Fix bug in modernize-use-emplace (PR #66169)

2023-09-17 Thread Carlos Galvez via cfe-commits


@@ -207,11 +211,13 @@ void UseEmplaceCheck::registerMatchers(MatchFinder 
*Finder) {
   auto HasConstructExpr = has(ignoringImplicit(SoughtConstructExpr));
 
   // allow for T{} to be replaced, even if no CTOR is declared
-  auto HasConstructInitListExpr = has(initListExpr(anyOf(
-  allOf(has(SoughtConstructExpr),
-has(cxxConstructExpr(argumentCountIs(0,
-  has(cxxBindTemporaryExpr(has(SoughtConstructExpr),
-   has(cxxConstructExpr(argumentCountIs(0;
+  auto HasConstructInitListExpr =
+  has(initListExpr(anyOf(initCountIs(0), initCountIs(1)),

carlosgalvezp wrote:

Would it make sense to briefly document this choice of init list of exactly 0 
or 1 arguments in the line above?

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


[clang-tools-extra] [clang-tidy] Fix bug in modernize-use-emplace (PR #66169)

2023-09-17 Thread Carlos Galvez via cfe-commits


@@ -207,11 +211,13 @@ void UseEmplaceCheck::registerMatchers(MatchFinder 
*Finder) {
   auto HasConstructExpr = has(ignoringImplicit(SoughtConstructExpr));
 
   // allow for T{} to be replaced, even if no CTOR is declared
-  auto HasConstructInitListExpr = has(initListExpr(anyOf(
-  allOf(has(SoughtConstructExpr),
-has(cxxConstructExpr(argumentCountIs(0,
-  has(cxxBindTemporaryExpr(has(SoughtConstructExpr),
-   has(cxxConstructExpr(argumentCountIs(0;
+  auto HasConstructInitListExpr =
+  has(initListExpr(anyOf(initCountIs(0), initCountIs(1)),

carlosgalvezp wrote:

Nit: would it be simpler/more readable with something like `initCountLeq(1)`?

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


[PATCH] D149677: [clang][TypePrinter] Add option to skip over elaborated types

2023-09-17 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

This was never mentioned in the review, but I have a late question: Why did we 
need to implement a new flag, instead of using `getFullyQualifiedName` from 
`QualTypeNames.cpp`?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149677/new/

https://reviews.llvm.org/D149677

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


[clang-tools-extra] 4b5366c - [clang-tidy] Avoid checking magic numbers if _BitInt (#65888)

2023-09-17 Thread via cfe-commits

Author: vabridgers
Date: 2023-09-17T14:00:57-05:00
New Revision: 4b5366c9512aa273a5272af1d833961e1ed156e7

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

LOG: [clang-tidy] Avoid checking magic numbers if _BitInt (#65888)

Recent changes to add _BitInt support have caused our internal random
testing to fail. This change just avoids a readability magic numbers
check for now if a _BitInt. The crash seen (edited for clarity) is shown
below.

/llvm/include/llvm/ADT/APInt.h:1488:
  uint64_t llvm::APInt::getZExtValue() const: Assertion `getActiveBits()
  <= 64 && "Too many bits for uint64_t"' failed.

...
 #9  llvm::APInt::getZExtValue() const
  /llvm/include/llvm/ADT/APInt.h:1488:5
  clang::IntegerLiteral const*) const

/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp:198:47
(clang::ast_matchers::MatchFinder::MatchResult
  const&, char const*)

/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.h:67:5
  clang::ast_matchers::MatchFinder::MatchResult const&)

/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp:152:35
...

Reviewed By: donat.nagy

Added: 
clang-tools-extra/test/clang-tidy/checkers/readability/bitint-no-crash.c

Modified: 
clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
index 7f3c2cb9a0434cc..97c20cf200fa21c 100644
--- a/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
@@ -191,6 +191,9 @@ bool MagicNumbersCheck::isConstant(const 
MatchFinder::MatchResult &Result,
 }
 
 bool MagicNumbersCheck::isIgnoredValue(const IntegerLiteral *Literal) const {
+  if (Literal->getType()->isBitIntType()) {
+return true;
+  }
   const llvm::APInt IntValue = Literal->getValue();
   const int64_t Value = IntValue.getZExtValue();
   if (Value == 0)

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/bitint-no-crash.c 
b/clang-tools-extra/test/clang-tidy/checkers/readability/bitint-no-crash.c
new file mode 100644
index 000..f8660924cbef5a0
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/bitint-no-crash.c
@@ -0,0 +1,6 @@
+// RUN: %check_clang_tidy %s readability-magic-numbers %t --
+
+// Don't crash
+
+_BitInt(128) A = 4533629751480627964421wb;
+// CHECK-MESSAGES: warning



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


[clang-tools-extra] [clang-tidy] Avoid checking magic numbers if _BitInt (PR #65888)

2023-09-17 Thread via cfe-commits

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


[clang] [analyzer] Do not use APInt methods on _BitInt() Types (PR #65887)

2023-09-17 Thread via cfe-commits


@@ -0,0 +1,11 @@
+ // RUN: %clang_analyze_cc1 -analyzer-checker=core \
+ // RUN:   -analyzer-checker=debug.ExprInspection \
+ // RUN:   -verify %s
+
+// Don't crash when using _BitInt()
+// expected-no-diagnostics
+_BitInt(256) a;
+_BitInt(129) b;
+void c() {
+  b = a;
+}

vabridgers wrote:

Hi Donat, if you mean something like this, this does not crash. 

__int128 a;
__int128 b;
void c() {
  b = a;
}


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


[clang] [analyzer] Do not use APInt methods on _BitInt() Types (PR #65887)

2023-09-17 Thread via cfe-commits

https://github.com/vabridgers updated 
https://github.com/llvm/llvm-project/pull/65887

>From ae0b0a015778e38041ee0a0d00f7be38c2c81226 Mon Sep 17 00:00:00 2001
From: Vince Bridgers 
Date: Sat, 9 Sep 2023 21:08:47 +0200
Subject: [PATCH] [analyzer] Do not use APInt methods on _BitInt() Types

evalIntegralCast is using APInt method to get the value of _BitInt()
values after _BitInt() changes were introduced. Some of those methods
assume values are less than or equal to 64-bits, which is not true for
_BitInt() types. This change simply side steps that issue if the
_BitInt() type is greater than 64 bits.

This was caught with our internal randomized testing.

/llvm/include/llvm/ADT/APInt.h:1510:
  int64_t llvm::APInt::getSExtValue() const: Assertion
  `getSignificantBits() <= 64 && "Too many bits for int64_t"' failed.a

...
 #9  llvm::APInt::getSExtValue() const
  /llvm/include/llvm/ADT/APInt.h:1510:5
  llvm::IntrusiveRefCntPtr,
  clang::ento::SVal, clang::QualType, clang::QualType)
  /clang/lib/StaticAnalyzer/Core/SValBuilder.cpp:607:24
  clang::Expr const*, clang::ento::ExplodedNode*, clang::ento::ExplodedNodeSet&)
  /clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp:413:61
...

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

 Reviewed By: donat.nagy
---
 clang/lib/StaticAnalyzer/Core/SValBuilder.cpp |  8 +++-
 clang/test/Analysis/bitint-no-crash.c | 11 +++
 2 files changed, 14 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/Analysis/bitint-no-crash.c

diff --git a/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp 
b/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
index 4fe828bdf7681fc..f827f43eaa7da67 100644
--- a/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -598,11 +598,9 @@ SVal SValBuilder::evalIntegralCast(ProgramStateRef state, 
SVal val,
   APSIntType ToType(getContext().getTypeSize(castTy),
 castTy->isUnsignedIntegerType());
   llvm::APSInt ToTypeMax = ToType.getMaxValue();
-  NonLoc ToTypeMaxVal =
-  makeIntVal(ToTypeMax.isUnsigned() ? ToTypeMax.getZExtValue()
-: ToTypeMax.getSExtValue(),
- castTy)
-  .castAs();
+
+  NonLoc ToTypeMaxVal = makeIntVal(ToTypeMax);
+
   // Check the range of the symbol being casted against the maximum value of 
the
   // target type.
   NonLoc FromVal = val.castAs();
diff --git a/clang/test/Analysis/bitint-no-crash.c 
b/clang/test/Analysis/bitint-no-crash.c
new file mode 100644
index 000..6fa041974a3c981
--- /dev/null
+++ b/clang/test/Analysis/bitint-no-crash.c
@@ -0,0 +1,11 @@
+ // RUN: %clang_analyze_cc1 -analyzer-checker=core \
+ // RUN:   -analyzer-checker=debug.ExprInspection \
+ // RUN:   -verify %s
+
+// Don't crash when using _BitInt()
+// expected-no-diagnostics
+_BitInt(256) a;
+_BitInt(129) b;
+void c() {
+  b = a;
+}

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


[clang] [analyzer] Do not use APInt methods on _BitInt() Types (PR #65887)

2023-09-17 Thread via cfe-commits


@@ -598,6 +598,12 @@ SVal SValBuilder::evalIntegralCast(ProgramStateRef state, 
SVal val,
   APSIntType ToType(getContext().getTypeSize(castTy),
 castTy->isUnsignedIntegerType());
   llvm::APSInt ToTypeMax = ToType.getMaxValue();
+  // With the introduction of _BitInt(), integral types can be
+  // > 64 bits. So check for this and skip the size checks
+  // falling back to making a non loc return type.
+  if (ToTypeMax.getSignificantBits() > 64) {
+return makeNonLoc(se, originalTy, castTy);
+  }
   NonLoc ToTypeMaxVal =
   makeIntVal(ToTypeMax.isUnsigned() ? ToTypeMax.getZExtValue()

vabridgers wrote:

I think I fixed this, but it seems my push may not have worked as I expected :/ 
Checking this.

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


[clang] [analyzer] Do not use APInt methods on _BitInt() Types (PR #65887)

2023-09-17 Thread via cfe-commits

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


[clang] [analyzer] Do not use APInt methods on _BitInt() Types (PR #65887)

2023-09-17 Thread via cfe-commits

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


[clang] [clang] [C23] Fix crash with _BitInt running clang-tidy (PR #65889)

2023-09-17 Thread via cfe-commits

https://github.com/vabridgers updated 
https://github.com/llvm/llvm-project/pull/65889

>From 753f8fd0fba767a5ba1abd30d35df379292e454c Mon Sep 17 00:00:00 2001
From: Vince Bridgers 
Date: Sat, 9 Sep 2023 12:19:07 +0200
Subject: [PATCH] [clang] [C23] Fix crash with _BitInt running clang-tidy

This crash was exposed recently in our randomized testing. _BitInts were
not being handled properly during IntegerLiteral visitation. This patch
addresses the problem for now.

The BitIntType has no getKind() method, so the FoldingSetID is taken
from the APInt value representing the _BitInt(), similar to other
methods in StmtProfile.cpp.

Crash seen (summary form):

clang-tidy: /llvm/include/llvm/Support/Casting.h:566:
decltype(auto) llvm::cast(const From&) [with To = clang::BuiltinType;
>From = clang::QualType]: Assertion `isa(Val) && "cast() argument
of incompatible type!"' failed

...
  #9  decltype(auto) llvm::cast(clang::QualType const&)
   /llvm/include/llvm/Support/Casting.h:566:3
 #10  clang::BuiltinType const* 
clang::Type::castAs() const
   /tools/clang/include/clang/AST/TypeNodes.inc:86:1
 #11  (anonymous namespace)::StmtProfiler::VisitIntegerLiteral(
   clang::IntegerLiteral const*)
   /clang/lib/AST/StmtProfile.cpp:1362:64
 #12  clang::StmtVisitorBase::Visit(clang::Stmt const*)
   /clang/include/clang/AST/StmtNodes.inc:1225:1
...

Reviewed By: donat.nagy
---
 .../bugprone/inc-dec-in-conditions-bitint-no-crash.c | 9 +
 clang/lib/AST/StmtProfile.cpp| 9 -
 2 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/inc-dec-in-conditions-bitint-no-crash.c

diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/inc-dec-in-conditions-bitint-no-crash.c
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/inc-dec-in-conditions-bitint-no-crash.c
new file mode 100644
index 000..cfb64c10fe46cea
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/inc-dec-in-conditions-bitint-no-crash.c
@@ -0,0 +1,9 @@
+// RUN: %check_clang_tidy %s bugprone-inc-dec-in-conditions %t
+
+_BitInt(8) v_401_0() {
+  0 && ({
+_BitInt(5) y = 0;
+16777215wb ?: ++y;
+  });
+}
+// CHECK-MESSAGES: warning 
diff --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp
index 27f71edd6f99b32..9c14553437b3f14 100644
--- a/clang/lib/AST/StmtProfile.cpp
+++ b/clang/lib/AST/StmtProfile.cpp
@@ -1333,7 +1333,14 @@ void StmtProfiler::VisitPredefinedExpr(const 
PredefinedExpr *S) {
 void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
   VisitExpr(S);
   S->getValue().Profile(ID);
-  ID.AddInteger(S->getType()->castAs()->getKind());
+
+  QualType T = S->getType();
+  if (auto BitIntT = T->getAs()) {
+BitIntT->Profile(ID, BitIntT->isSigned(), BitIntT->getNumBits());
+  } else {
+ID.AddBoolean(false);
+ID.AddInteger(T->castAs()->getKind());
+  }
 }
 
 void StmtProfiler::VisitFixedPointLiteral(const FixedPointLiteral *S) {

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


[clang-tools-extra] [clang] [C23] Fix crash with _BitInt running clang-tidy (PR #65889)

2023-09-17 Thread via cfe-commits

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


[clang] [clang] [C23] Fix crash with _BitInt running clang-tidy (PR #65889)

2023-09-17 Thread via cfe-commits


@@ -0,0 +1,10 @@
+// RUN: %check_clang_tidy %s bugprone-inc-dec-in-conditions %t
+
+#define foo(x) \
+  ({   \
+_BitInt(5) y = x;  \
+16777215wb ?: ++y; \
+  })
+
+_BitInt(8) v_401_0() { 0 && foo(0); }

vabridgers wrote:

Done, thank you

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


[clang] [clang] [C23] Fix crash with _BitInt running clang-tidy (PR #65889)

2023-09-17 Thread via cfe-commits

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


[clang-tools-extra] [clang] [C23] Fix crash with _BitInt running clang-tidy (PR #65889)

2023-09-17 Thread via cfe-commits


@@ -1333,7 +1333,15 @@ void StmtProfiler::VisitPredefinedExpr(const 
PredefinedExpr *S) {
 void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
   VisitExpr(S);
   S->getValue().Profile(ID);
-  ID.AddInteger(S->getType()->castAs()->getKind());
+
+  int FoldingSetID = 0;
+
+  if (S->getType()->isBitIntType())
+FoldingSetID = S->getValue().getSExtValue();
+  else
+FoldingSetID = S->getType()->castAs()->getKind();
+
+  ID.AddInteger(FoldingSetID);

vabridgers wrote:

I believe I've addressed the comments in this thread. I'm resolving this 
conversation. Please reopen if you disagree. 

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


[PATCH] D153131: [clang analysis][thread-safety] Handle return-by-reference...

2023-09-17 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a comment.

Sorry for letting this collect dust. I think it's a valuable addition, and 
looks pretty good, except that I think we should use the expected exit set 
instead of the entry set. These can be legitimately different for appropriately 
annotated functions, i.e. with `acquire_(shared_)capability` or 
`release_(shared_)capability`.

Apart from the bug mentioned earlier, which should now be fixed, this looks 
good on our code base. I have to admit a separate flag could be nice for 
migration, but it should be included by default in `-Wthread-safety-reference`. 
But I'm not sure if we need it.




Comment at: clang/include/clang/Basic/DiagnosticGroups.td:1046
 def ThreadSafetyPrecise: DiagGroup<"thread-safety-precise">;
 def ThreadSafetyReference  : DiagGroup<"thread-safety-reference">;
+def ThreadSafetyReturn : DiagGroup<"thread-safety-return">;

courbet wrote:
> aaronpuchert wrote:
> > courbet wrote:
> > > aaronpuchert wrote:
> > > > courbet wrote:
> > > > > aaronpuchert wrote:
> > > > > > Why not under `-Wthread-safety-reference`, as it's 
> > > > > > return-by-reference that you're warning on? This seems too small 
> > > > > > for a separate flag to me.
> > > > > The main reason it so that we provide a soft transition period for 
> > > > > users: If we put that in `-Wthread-safety-reference`, we'll start 
> > > > > breaking compile for people who use `-Werror`, while a separate flag 
> > > > > allows a transition period where people opt into the new feature.
> > > > Transition flags can end up resulting in more churn, assuming that we 
> > > > eventually want to put this under `-Wthread-safety-reference`, because 
> > > > then you have two categories of users:
> > > > * those that opted in will eventually have to remove the flag again, and
> > > > * those that didn't will get hard errors on updating the compiler at 
> > > > that point.
> > > > Of course you might argue that the latter case can be prevented by 
> > > > carefully reading the release notes, but we know how often that happens.
> > > > 
> > > > I'd argue that if you're using `-Wthread-safety-reference`, you're 
> > > > already opting into warnings on escaping references, and not warning on 
> > > > `return` is a false negative.
> > > > 
> > > > A separate flag would make sense to me if we want to keep it, for 
> > > > example because this produces a substantial amount of false positives 
> > > > under some circumstances. Did you try this on a larger code base that's 
> > > > using the annotations? I could try it on our code, and maybe we can get 
> > > > some Googler to test it on theirs, which is also heavily using Thread 
> > > > Safety Analysis. (Though I'm not sure whether they use 
> > > > `-Wthread-safety-reference`.)
> > > I don't have a strong opinion for where the warning should go.  We are 
> > > indeed using `-Wthread-safety-reference`, though we're not enabling 
> > > -Werror on these, so adding more warnings is fine for us.
> > > 
> > > I've run the check on a small sample of our codebase (which I don;t claim 
> > > to be representative, I can do a larger analysis if needed). The warnings 
> > > are more or less evenly split between missing annotations and actual 
> > > bugs. I don't think any of the things I've seen qualify as false 
> > > positives.
> > > 
> > > Among the missing annotations, most of the warnings are missing 
> > > `ABSL_EXCLUSIVE_LOCKS_REQUIRED` on the function. In a small number of 
> > > cases, the pattern is that a variable is lazily initialized under a lock 
> > > and then returned by reference:
> > > 
> > > ```
> > > struct LazyImmutableThing {
> > >   const Thing& Get() {
> > > {
> > >   MutexLock lock(&mutex_);
> > >   thing_->Initialize();
> > > }
> > > 
> > > return thing_;
> > >   }
> > >   
> > >   Mutex mutex_;
> > >   Thing thing_ GUARDED_BY(mutex_);
> > > };
> > > ```
> > > 
> > > I consider this to be a missing annotation as the returned value is 
> > > dynamically immutable, the proper fix would be `return 
> > > TS_UNCHECKED_READ(thing_)`.
> > > 
> > > 
> > > Most actual bugs are along the lines of:
> > > 
> > > ```
> > > struct S {
> > >   T& Get() const {
> > > MutexLock lock(&mutex_);
> > > return obj_;
> > >   }
> > > 
> > >   Mutex mutex_;
> > >   T obj_ GUARDED_BY(mutex_);
> > > };
> > > ```
> > > 
> > > though some are missing the guard altogether (`T& Get() const { return 
> > > obj_; }`).
> > > 
> > > There are a few possible fixes. In rough order of occurrence:
> > >  - Return by value as the copy is not too expensive and memory ordering 
> > > does not matter.
> > >  - Let the caller take the lock and annotate with 
> > > `ABSL_EXCLUSIVE_LOCKS_REQUIRED` when the `Get` method is not called too 
> > > often.
> > >  - Let `Get` take a callback and process the value under the lock instead 
> > > of returning it (when ordering matters).
> > > 
> > > In a small number of cases, the pattern is

[clang] [InstSimplify] Fold icmp of `X and/or C1` and `X and/or C2` into constant (PR #65905)

2023-09-17 Thread via cfe-commits

goldsteinn wrote:

LGTM, but please cleanup commits.

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


[clang-tools-extra] [InstSimplify] Fold icmp of `X and/or C1` and `X and/or C2` into constant (PR #65905)

2023-09-17 Thread via cfe-commits

goldsteinn wrote:

LGTM, but please cleanup commits.

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


[clang-tools-extra] [InstSimplify] Fold icmp of `X and/or C1` and `X and/or C2` into constant (PR #65905)

2023-09-17 Thread via cfe-commits

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


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


[clang] [InstSimplify] Fold icmp of `X and/or C1` and `X and/or C2` into constant (PR #65905)

2023-09-17 Thread via cfe-commits

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


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


[PATCH] D157572: [clang] Add `[[clang::library_extension]]` attribute

2023-09-17 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik abandoned this revision.
philnik added a comment.

Abandoning, since it seems like we want to extend `diagnose_if` instead.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157572/new/

https://reviews.llvm.org/D157572

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


[clang] [analyzer] TaintPropagation checker strlen() should not propagate (PR #66086)

2023-09-17 Thread Balazs Benics via cfe-commits

steakhal wrote:

As I'm not a maintainer, I could not push to your branch.
Here is a patch that I think has the missing pieces to satisfy my review.
[0001-fixup-analyzer-TaintPropagation-checker-strlen-shoul.patch.txt](https://github.com/llvm/llvm-project/files/12645128/0001-fixup-analyzer-TaintPropagation-checker-strlen-shoul.patch.txt)
Apply it to your branch by `git am 
0001-fixup-analyzer-TaintPropagation-checker-strlen-shoul.patch.txt`.
After that, I'm okay to squash merge this PR, if you are also okay with my 
suggestions.


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


[clang] Introduce paged vector (PR #66430)

2023-09-17 Thread Giulio Eulisse via cfe-commits

https://github.com/ktf updated https://github.com/llvm/llvm-project/pull/66430

>From b952f0577dfe8112f394bd5392212f843c0cc86e Mon Sep 17 00:00:00 2001
From: Giulio Eulisse <10544+...@users.noreply.github.com>
Date: Thu, 14 Sep 2023 21:58:21 +0200
Subject: [PATCH 01/15] Introduce PagedVector class

The goal of the class is to be an (almost) drop in replacement for
SmallVector and std::vector when those are presized and filled later,
as it happens in SourceManager and ASTReader.

By splitting the actual vector in pages of the same size and allocating
the pages only when they are needed, using this containers reduces the
memory usage by a factor 4 for the cases relevant to the ALICE
experiment ROOT / cling usage.
---
 llvm/include/llvm/ADT/PagedVector.h | 96 +
 1 file changed, 96 insertions(+)
 create mode 100644 llvm/include/llvm/ADT/PagedVector.h

diff --git a/llvm/include/llvm/ADT/PagedVector.h 
b/llvm/include/llvm/ADT/PagedVector.h
new file mode 100644
index 000..dab0d249aa706e4
--- /dev/null
+++ b/llvm/include/llvm/ADT/PagedVector.h
@@ -0,0 +1,96 @@
+//===- llvm/ADT/PagedVector.h - 'Lazyly allocated' vectors *- C++
+//-*-===//
+//
+// 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
+//
+//===--===//
+//
+// This file defines the PagedVector class.
+//
+//===--===//
+#ifndef LLVM_ADT_PAGEDVECTOR_H
+#define LLVM_ADT_PAGEDVECTOR_H
+
+#include 
+
+// Notice that this does not have iterators, because if you
+// have iterators it probably means you are going to touch
+// all the memory in any case, so better use a std::vector in
+// the first place.
+template  class PagedVector {
+  size_t Size = 0;
+  // Index of where to find a given page in the data
+  mutable std::vector Lookup;
+  // Actual data
+  mutable std::vector Data;
+
+public:
+  // Add a range to the vector.
+  // When vector is accessed, it will call the callback to fill the range
+  // with data.
+
+  // Lookup an element at position i.
+  // If the given range is not filled, it will be filled.
+  // If the given range is filled, return the element.
+  T &operator[](int Index) const { return at(Index); }
+
+  T &at(int Index) const {
+auto &PageId = Lookup[Index / PAGE_SIZE];
+// If the range is not filled, fill it
+if (PageId == -1) {
+  int OldSize = Data.size();
+  PageId = OldSize / PAGE_SIZE;
+  // Allocate the memory
+  Data.resize(OldSize + PAGE_SIZE);
+  // Fill the whole capacity with empty elements
+  for (int I = 0; I < PAGE_SIZE; ++I) {
+Data[I + OldSize] = T();
+  }
+}
+// Return the element
+return Data[Index % PAGE_SIZE + PAGE_SIZE * PageId];
+  }
+
+  // Return the size of the vector
+  size_t capacity() const { return Lookup.size() * PAGE_SIZE; }
+
+  size_t size() const { return Size; }
+
+  // Expands the vector to the given size.
+  // If the vector is already bigger, does nothing.
+  void expand(size_t NewSize) {
+// You cannot shrink the vector, otherwise
+// you would have to invalidate
+assert(NewSize >= Size);
+if (NewSize <= Size) {
+  return;
+}
+if (NewSize <= capacity()) {
+  Size = NewSize;
+  return;
+}
+auto Pages = NewSize / PAGE_SIZE;
+auto Remainder = NewSize % PAGE_SIZE;
+if (Remainder) {
+  Pages += 1;
+}
+assert(Pages > Lookup.size());
+Lookup.resize(Pages, -1);
+Size = NewSize;
+  }
+
+  // Return true if the vector is empty
+  bool empty() const { return Size == 0; }
+  /// Clear the vector
+  void clear() {
+Size = 0;
+Lookup.clear();
+Data.clear();
+  }
+
+  std::vector const &materialised() const { return Data; }
+};
+
+#endif // LLVM_ADT_PAGEDVECTOR_H

>From f0c75c8af0fea27b5b758e2e5775787f33595de3 Mon Sep 17 00:00:00 2001
From: Giulio Eulisse <10544+...@users.noreply.github.com>
Date: Thu, 14 Sep 2023 22:20:29 +0200
Subject: [PATCH 02/15] Use PagedVector to reduce memory usage of sparsely
 populated vectors

---
 clang/include/clang/Basic/SourceManager.h |  3 ++-
 clang/include/clang/Serialization/ASTReader.h |  5 +++--
 clang/lib/Basic/SourceManager.cpp | 12 ++--
 clang/lib/Serialization/ASTReader.cpp |  9 +
 4 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Basic/SourceManager.h 
b/clang/include/clang/Basic/SourceManager.h
index 2f846502d6f3327..b1942a3d86afc37 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -43,6 +43,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/PagedVector.h"
 #include "llvm/ADT/PointerIntPai

[clang] Introduce paged vector (PR #66430)

2023-09-17 Thread Giulio Eulisse via cfe-commits

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


[clang] [analyzer] Fix StackAddrEscapeChecker crash on temporary object fields (PR #66493)

2023-09-17 Thread Balazs Benics via cfe-commits

https://github.com/steakhal updated 
https://github.com/llvm/llvm-project/pull/66493

>From cfdbc40487481b341d42f0472e196ff4bd33 Mon Sep 17 00:00:00 2001
From: Balazs Benics 
Date: Fri, 15 Sep 2023 12:42:39 +0200
Subject: [PATCH 1/2] [analyzer] Fix StackAddrEscapeChecker crash on temporary
 object fields

Basically, the issue was that we should have unwrap the base region
before we special handle temp object regions.

Fixes https://github.com/llvm/llvm-project/issues/66221
---
 .../Checkers/StackAddrEscapeChecker.cpp   |  6 +++--
 clang/test/Analysis/stackaddrleak.cpp | 24 +++
 2 files changed, 28 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Analysis/stackaddrleak.cpp

diff --git a/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
index 19ff8c8e2a171ae..23a774931b21dec 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
@@ -369,7 +369,7 @@ void StackAddrEscapeChecker::checkEndFunction(const 
ReturnStmt *RS,
   "Stack address stored into global variable");
 
   for (const auto &P : Cb.V) {
-const MemRegion *Referrer = P.first;
+const MemRegion *Referrer = P.first->getBaseRegion();
 const MemRegion *Referred = P.second;
 
 // Generate a report for this bug.
@@ -384,6 +384,8 @@ void StackAddrEscapeChecker::checkEndFunction(const 
ReturnStmt *RS,
   << CommonSuffix;
   auto Report =
   std::make_unique(*BT_stackleak, Out.str(), 
N);
+  if (Range.isValid())
+Report->addRange(Range);
   Ctx.emitReport(std::move(Report));
   return;
 }
@@ -398,7 +400,7 @@ void StackAddrEscapeChecker::checkEndFunction(const 
ReturnStmt *RS,
 }(Referrer->getMemorySpace());
 
 // This cast supposed to succeed.
-const VarRegion *ReferrerVar = cast(Referrer->getBaseRegion());
+const auto *ReferrerVar = cast(Referrer);
 const std::string ReferrerVarName =
 ReferrerVar->getDecl()->getDeclName().getAsString();
 
diff --git a/clang/test/Analysis/stackaddrleak.cpp 
b/clang/test/Analysis/stackaddrleak.cpp
new file mode 100644
index 000..5828f2ac6e78c8d
--- /dev/null
+++ b/clang/test/Analysis/stackaddrleak.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core -verify %s
+
+void *operator new(unsigned long, void *p) { return p; }
+
+struct myfunction {
+  union storage_t {
+char buffer[100];
+unsigned long long max_align;
+  } storage;
+
+  template  myfunction(Func fn) {
+new (&storage.buffer) Func(fn);
+  }
+  void operator()();
+};
+
+myfunction create_func() {
+  int n;
+  auto c = [&n] {};
+  return c; // expected-warning {{Address of stack memory associated with 
local variable 'n' is still referred to by a temporary object on the stack upon 
returning to the caller.  This will be a dangling reference}}
+}
+void gh_66221() {
+  create_func()();
+}

>From d569f78eb0cf3abbac13c7d8518173c4c08f4789 Mon Sep 17 00:00:00 2001
From: Balazs Benics 
Date: Mon, 18 Sep 2023 08:43:03 +0200
Subject: [PATCH 2/2] Assert if asserted build, continue otherwise

---
 .../StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
index 23a774931b21dec..ea09c43cc5ce90d 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
@@ -399,8 +399,14 @@ void StackAddrEscapeChecker::checkEndFunction(const 
ReturnStmt *RS,
   return "stack";
 }(Referrer->getMemorySpace());
 
-// This cast supposed to succeed.
-const auto *ReferrerVar = cast(Referrer);
+// We should really only have VarRegions here.
+// Anything else is really surprising, and we should get notified if such
+// ever happens.
+const auto *ReferrerVar = dyn_cast(Referrer);
+if (!ReferrerVar) {
+  assert(false && "We should have a VarRegion here");
+  continue; // Defensively skip this one.
+}
 const std::string ReferrerVarName =
 ReferrerVar->getDecl()->getDeclName().getAsString();
 

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


[clang] Introduce paged vector (PR #66430)

2023-09-17 Thread Giulio Eulisse via cfe-commits


@@ -1625,6 +1625,35 @@ SmallVector has grown a few other minor advantages over 
std::vector, causing
and is no longer "private to the implementation". A name like
``SmallVectorHeader`` might be more appropriate.
 
+.. _dss_pagedvector:
+
+llvm/ADT/PagedVector.h
+^^
+
+``PagedVector`` is a random access container that allocates 
(PageSize) elements
+of type Type when the first element of a page is accessed via the 
``operator[]`` or the ``at()``
+method.  This is useful for the case in which the number of elements is known 
in advance and 
+their actual initialization is expensive and sparse so that it's only done 
lazily when the element is 
+accessed. When the number of used pages is small significant memory savings 
can be achieved.
+
+The main advantage is that a PagedVector allows to delay the actual allocation 
of the page until it's needed,
+at the extra cost of one integer per page and one extra indirection when 
accessing elements with their positional
+index. 
+
+In order to maximise the memory footprint of this container, it's important to 
balance the PageSize so that 
+it's not too small (otherwise the overhead of the integer per page might 
become too high) and not too big 
+(otherwise the memory is wasted if the page is not fully used).
+
+The PagedVector can only be expanded at the end, and it's not possible to 
shrink it, to keep the implementation
+simple and not give the false hope that the resize operation is cheap.
+
+Moreover, while retaining the oder of the elements based on their insertion 
index, like a vector, iterating over

ktf wrote:

Fixed.

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


[clang] [analyzer] Fix StackAddrEscapeChecker crash on temporary object fields (PR #66493)

2023-09-17 Thread Balazs Benics via cfe-commits

steakhal wrote:

Let me know if you are still okay with the latest change. @DonatNagyE 
@Xazax-hun 

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


[clang] Introduce paged vector (PR #66430)

2023-09-17 Thread Giulio Eulisse via cfe-commits


@@ -0,0 +1,131 @@
+//===- llvm/ADT/PagedVector.h - 'Lazyly allocated' vectors *- C++
+//-*-===//
+//
+// 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
+//
+//===--===//
+//
+// This file defines the PagedVector class.
+//
+//===--===//
+#ifndef LLVM_ADT_PAGEDVECTOR_H
+#define LLVM_ADT_PAGEDVECTOR_H
+
+#include 
+#include 
+
+namespace llvm {
+// A vector that allocates memory in pages.
+// Order is kept, but memory is allocated only when one element of the page is
+// accessed. This introduces a level of indirection, but it is useful when you
+// have a sparsely initialised vector where the full size is allocated upfront
+// with the default constructor and elements are initialised later, on first
+// access.
+//
+// Notice that this does not have iterators, because if you
+// have iterators it probably means you are going to touch
+// all the memory in any case, so better use a std::vector in
+// the first place.
+template 

ktf wrote:

It should be handled by the latest commit.

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


[clang] Introduce paged vector (PR #66430)

2023-09-17 Thread Giulio Eulisse via cfe-commits


@@ -0,0 +1,133 @@
+//===- llvm/ADT/PagedVector.h - 'Lazyly allocated' vectors *- C++
+//-*-===//
+//
+// 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
+//
+//===--===//
+//
+// This file defines the PagedVector class.
+//
+//===--===//
+#ifndef LLVM_ADT_PAGEDVECTOR_H
+#define LLVM_ADT_PAGEDVECTOR_H
+
+#include 
+#include 
+
+namespace llvm {
+// A vector that allocates memory in pages.
+// Order is kept, but memory is allocated only when one element of the page is
+// accessed. This introduces a level of indirection, but it is useful when you
+// have a sparsely initialised vector where the full size is allocated upfront
+// with the default constructor and elements are initialised later, on first
+// access.
+//
+// Notice that this does not have iterators, because if you
+// have iterators it probably means you are going to touch
+// all the memory in any case, so better use a std::vector in
+// the first place.
+template  class PagedVector {
+  // The actual number of element in the vector which can be accessed.
+  std::size_t Size = 0;
+  // The position of the initial element of the page in the Data vector.
+  // Pages are allocated contiguously in the Data vector.
+  mutable std::vector Lookup;
+  // Actual page data. All the page elements are added to this vector on the
+  // first access of any of the elements of the page. Elements default
+  // constructed and elements of the page are stored contiguously. The oder of
+  // the elements however depends on the order of access of the pages.
+  mutable std::vector Data;

ktf wrote:

I can try to use the allocator, indeed.

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


[clang] [clang][docs] Pass full path of source TD file to gen_rst_from_td. [NFC] (PR #66497)

2023-09-17 Thread Francesco Petrogalli via cfe-commits

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


[clang] [clang][docs] Pass full path of source TD file to gen_rst_from_td. [NFC] (PR #66497)

2023-09-17 Thread Francesco Petrogalli via cfe-commits

fpetrogalli wrote:

Hi @tstellar  - this is the wrong approach, I will abandon the patch. Apologies 
for the noise!

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