Re: [clang] 2dbcfd2 - Revert "[clang][Interp][NFC] Move CheckDivRem() implementation into Interp.cpp"

2023-01-19 Thread Roman Lebedev via cfe-commits
Reminder to please always mention the reason for the revert/recommit
in the commit message.

On Thu, Jan 19, 2023 at 2:37 PM Timm Bäder via cfe-commits
 wrote:
>
>
> Author: Timm Bäder
> Date: 2023-01-19T12:37:20+01:00
> New Revision: 2dbcfd298f7cb1454ca16f544b7df980ec8fc17d
>
> URL: 
> https://github.com/llvm/llvm-project/commit/2dbcfd298f7cb1454ca16f544b7df980ec8fc17d
> DIFF: 
> https://github.com/llvm/llvm-project/commit/2dbcfd298f7cb1454ca16f544b7df980ec8fc17d.diff
>
> LOG: Revert "[clang][Interp][NFC] Move CheckDivRem() implementation into 
> Interp.cpp"
>
> This reverts commit 9ee0d7494eb35f5addefcb730cdf5c002ddeacd2.
>
> Added:
>
>
> Modified:
> clang/lib/AST/Interp/Interp.cpp
> clang/lib/AST/Interp/Interp.h
>
> Removed:
>
>
>
> 
> diff  --git a/clang/lib/AST/Interp/Interp.cpp 
> b/clang/lib/AST/Interp/Interp.cpp
> index d7195148d015..76ade4401e08 100644
> --- a/clang/lib/AST/Interp/Interp.cpp
> +++ b/clang/lib/AST/Interp/Interp.cpp
> @@ -422,26 +422,6 @@ bool CheckShift(InterpState , CodePtr OpPC, const RT 
> , unsigned Bits) {
>return true;
>  }
>
> -template 
> -bool CheckDivRem(InterpState , CodePtr OpPC, const T , const T ) {
> -  if (RHS.isZero()) {
> -const SourceInfo  = S.Current->getSource(OpPC);
> -S.FFDiag(Loc, diag::note_expr_divide_by_zero);
> -return false;
> -  }
> -
> -  if (LHS.isSigned() && LHS.isMin() && RHS.isNegative() && RHS.isMinusOne()) 
> {
> -APSInt LHSInt = LHS.toAPSInt();
> -SmallString<32> Trunc;
> -(-LHSInt.extend(LHSInt.getBitWidth() + 1)).toString(Trunc, 10);
> -const SourceInfo  = S.Current->getSource(OpPC);
> -const Expr *E = S.Current->getExpr(OpPC);
> -S.CCEDiag(Loc, diag::note_constexpr_overflow) << Trunc << E->getType();
> -return false;
> -  }
> -  return true;
> -}
> -
>  static void DiagnoseUninitializedSubobject(InterpState , const SourceInfo 
> ,
> QualType SubObjType,
> SourceLocation SubObjLoc) {
>
> diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
> index 3fa977d4a02e..903c68f4511c 100644
> --- a/clang/lib/AST/Interp/Interp.h
> +++ b/clang/lib/AST/Interp/Interp.h
> @@ -100,7 +100,24 @@ bool CheckShift(InterpState , CodePtr OpPC, const RT 
> , unsigned Bits);
>
>  /// Checks if Div/Rem operation on LHS and RHS is valid.
>  template 
> -bool CheckDivRem(InterpState , CodePtr OpPC, const T , const T );
> +bool CheckDivRem(InterpState , CodePtr OpPC, const T , const T ) {
> +  if (RHS.isZero()) {
> +const SourceInfo  = S.Current->getSource(OpPC);
> +S.FFDiag(Loc, diag::note_expr_divide_by_zero);
> +return false;
> +  }
> +
> +  if (LHS.isSigned() && LHS.isMin() && RHS.isNegative() && RHS.isMinusOne()) 
> {
> +APSInt LHSInt = LHS.toAPSInt();
> +SmallString<32> Trunc;
> +(-LHSInt.extend(LHSInt.getBitWidth() + 1)).toString(Trunc, 10);
> +const SourceInfo  = S.Current->getSource(OpPC);
> +const Expr *E = S.Current->getExpr(OpPC);
> +S.CCEDiag(Loc, diag::note_constexpr_overflow) << Trunc << E->getType();
> +return false;
> +  }
> +  return true;
> +}
>
>  /// Interpreter entry point.
>  bool Interpret(InterpState , APValue );
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang] a033dbb - [Clang] Give Clang the ability to use a shared stat cache

2023-01-18 Thread Roman Lebedev via cfe-commits
Looks like my comments on the review got completely ignored and not
even acknowledged.

On Thu, Jan 19, 2023 at 1:35 AM Fred Riss via cfe-commits
 wrote:
>
>
> Author: Fred Riss
> Date: 2023-01-18T14:31:27-08:00
> New Revision: a033dbbe5c43247b60869b008e67ed86ed230eaa
>
> URL: 
> https://github.com/llvm/llvm-project/commit/a033dbbe5c43247b60869b008e67ed86ed230eaa
> DIFF: 
> https://github.com/llvm/llvm-project/commit/a033dbbe5c43247b60869b008e67ed86ed230eaa.diff
>
> LOG: [Clang] Give Clang the ability to use a shared stat cache
>
> Every Clang instance uses an internal FileSystemStatCache to avoid
> stating the same content multiple times. However, different instances
> of Clang will contend for filesystem access for their initial stats
> during HeaderSearch or module validation.
>
> On some workloads, the time spent in the kernel in these concurrent
> stat calls has been measured to be over 20% of the overall compilation
> time. This is extremly wassteful when most of the stat calls target
> mostly immutable content like a SDK.
>
> This commit introduces a new tool `clang-stat-cache` able to generate
> an OnDiskHashmap containing the stat data for a given filesystem
> hierarchy.
>
> The driver part of this has been modeled after -ivfsoverlay given
> the similarities with what it influences. It introduces a new
> -ivfsstatcache driver option to instruct Clang to use a stat cache
> generated by `clang-stat-cache`. These stat caches are inserted at
> the bottom of the VFS stack (right above the real filesystem).
>
> Differential Revision: https://reviews.llvm.org/D136651
>
> Added:
> clang/test/Driver/vfsstatcache.c
> clang/test/clang-stat-cache/cache-effects.c
> clang/test/clang-stat-cache/errors.test
> clang/tools/clang-stat-cache/CMakeLists.txt
> clang/tools/clang-stat-cache/clang-stat-cache.cpp
> llvm/include/llvm/Support/StatCacheFileSystem.h
> llvm/lib/Support/StatCacheFileSystem.cpp
>
> Modified:
> clang/include/clang/Basic/DiagnosticFrontendKinds.td
> clang/include/clang/Driver/Options.td
> clang/include/clang/Frontend/CompilerInvocation.h
> clang/include/clang/Lex/HeaderSearchOptions.h
> clang/lib/Frontend/ASTUnit.cpp
> clang/lib/Frontend/CompilerInvocation.cpp
> clang/test/CMakeLists.txt
> clang/tools/CMakeLists.txt
> llvm/lib/Support/CMakeLists.txt
> llvm/unittests/Support/VirtualFileSystemTest.cpp
>
> Removed:
>
>
>
> 
> diff  --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
> b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
> index d0f672ae5a1bd..e106858688ac7 100644
> --- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
> +++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
> @@ -256,6 +256,11 @@ def err_test_module_file_extension_version : Error<
>"test module file extension '%0' has
> diff erent version (%1.%2) than expected "
>"(%3.%4)">;
>
> +def err_missing_vfs_stat_cache_file : Error<
> +  "stat cache file '%0' not found">, DefaultFatal;
> +def err_invalid_vfs_stat_cache : Error<
> +  "invalid stat cache file '%0'">, DefaultFatal;
> +
>  def err_missing_vfs_overlay_file : Error<
>"virtual filesystem overlay file '%0' not found">, DefaultFatal;
>  def err_invalid_vfs_overlay : Error<
>
> diff  --git a/clang/include/clang/Driver/Options.td 
> b/clang/include/clang/Driver/Options.td
> index ba49b335cf287..9334e6319d57b 100644
> --- a/clang/include/clang/Driver/Options.td
> +++ b/clang/include/clang/Driver/Options.td
> @@ -3357,6 +3357,8 @@ def iwithsysroot : JoinedOrSeparate<["-"], 
> "iwithsysroot">, Group
>HelpText<"Add directory to SYSTEM include search path, "
> "absolute paths are relative to -isysroot">, 
> MetaVarName<"">,
>Flags<[CC1Option]>;
> +def ivfsstatcache : JoinedOrSeparate<["-"], "ivfsstatcache">, 
> Group, Flags<[CC1Option]>,
> +  HelpText<"Use the stat data cached in file instead of doing filesystem 
> syscalls. See clang-stat-cache utility.">;
>  def ivfsoverlay : JoinedOrSeparate<["-"], "ivfsoverlay">, 
> Group, Flags<[CC1Option]>,
>HelpText<"Overlay the virtual filesystem described by file over the real 
> file system">;
>  def imultilib : Separate<["-"], "imultilib">, Group;
>
> diff  --git a/clang/include/clang/Frontend/CompilerInvocation.h 
> b/clang/include/clang/Frontend/CompilerInvocation.h
> index 254f048ed3c7e..9cc6aa5c4d8a1 100644
> --- a/clang/include/clang/Frontend/CompilerInvocation.h
> +++ b/clang/include/clang/Frontend/CompilerInvocation.h
> @@ -296,6 +296,7 @@ IntrusiveRefCntPtr 
> createVFSFromCompilerInvocation(
>
>  IntrusiveRefCntPtr
>  createVFSFromOverlayFiles(ArrayRef VFSOverlayFiles,
> +  ArrayRef VFSStatCacheFiles,
>DiagnosticsEngine ,
>IntrusiveRefCntPtr BaseFS);
>
>
> diff  --git a/clang/include/clang/Lex/HeaderSearchOptions.h 
> 

Re: [clang] f2d301f - Revert "[codegen] Store address of indirect arguments on the stack"

2023-01-16 Thread Roman Lebedev via cfe-commits
Reminder to please always mention the reason for the revert/recommit
in the commit message.

On Mon, Jan 16, 2023 at 7:05 PM Felipe de Azevedo Piovezan via
cfe-commits  wrote:
>
>
> Author: Felipe de Azevedo Piovezan
> Date: 2023-01-16T13:05:22-03:00
> New Revision: f2d301fe82869f881b86b51da7b4752972c66707
>
> URL: 
> https://github.com/llvm/llvm-project/commit/f2d301fe82869f881b86b51da7b4752972c66707
> DIFF: 
> https://github.com/llvm/llvm-project/commit/f2d301fe82869f881b86b51da7b4752972c66707.diff
>
> LOG: Revert "[codegen] Store address of indirect arguments on the stack"
>
> This reverts commit 7e4447a17db4a070f01c8f8a87505a4b2a1b0e3a.
>
> Added:
>
>
> Modified:
> clang/docs/ReleaseNotes.rst
> clang/lib/CodeGen/CGDebugInfo.cpp
> clang/lib/CodeGen/CGDebugInfo.h
> clang/lib/CodeGen/CGDecl.cpp
> clang/test/CodeGen/aarch64-ls64.c
> clang/test/CodeGen/atomic-arm64.c
> clang/test/CodeGenCXX/amdgcn-func-arg.cpp
> clang/test/CodeGenCXX/debug-info.cpp
> clang/test/CodeGenCXX/derived-to-base-conv.cpp
> clang/test/CodeGenCoroutines/coro-params-exp-namespace.cpp
> clang/test/CodeGenCoroutines/coro-params.cpp
> clang/test/OpenMP/for_firstprivate_codegen.cpp
> clang/test/OpenMP/parallel_firstprivate_codegen.cpp
> clang/test/OpenMP/sections_firstprivate_codegen.cpp
> clang/test/OpenMP/single_firstprivate_codegen.cpp
> clang/test/OpenMP/target_teams_distribute_firstprivate_codegen.cpp
> 
> clang/test/OpenMP/target_teams_distribute_parallel_for_firstprivate_codegen.cpp
> 
> clang/test/OpenMP/target_teams_distribute_parallel_for_simd_firstprivate_codegen.cpp
> clang/test/OpenMP/target_teams_distribute_simd_firstprivate_codegen.cpp
> clang/test/OpenMP/teams_distribute_firstprivate_codegen.cpp
> clang/test/OpenMP/teams_distribute_parallel_for_firstprivate_codegen.cpp
> 
> clang/test/OpenMP/teams_distribute_parallel_for_simd_firstprivate_codegen.cpp
> clang/test/OpenMP/teams_distribute_simd_firstprivate_codegen.cpp
> clang/test/OpenMP/teams_firstprivate_codegen.cpp
>
> Removed:
>
>
>
> 
> diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
> index 731d10ac64a3f..3bbab951e8a8c 100644
> --- a/clang/docs/ReleaseNotes.rst
> +++ b/clang/docs/ReleaseNotes.rst
> @@ -500,9 +500,6 @@ Non-comprehensive list of changes in this release
>  - Clang can now generate a PCH when using ``-fdelayed-template-parsing`` for
>code with templates containing loop hint pragmas, OpenMP pragmas, and
>``#pragma unused``.
> -- Clang now saves the address of ABI-indirect function parameters on the 
> stack,
> -  improving the debug information available in programs compiled without
> -  optimizations.
>
>
>  New Compiler Flags
>
> diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
> b/clang/lib/CodeGen/CGDebugInfo.cpp
> index f2d558456fde4..f53a9d00ae5fd 100644
> --- a/clang/lib/CodeGen/CGDebugInfo.cpp
> +++ b/clang/lib/CodeGen/CGDebugInfo.cpp
> @@ -4822,10 +4822,9 @@ void CGDebugInfo::EmitDeclareOfBlockDeclRefVariable(
>
>  llvm::DILocalVariable *
>  CGDebugInfo::EmitDeclareOfArgVariable(const VarDecl *VD, llvm::Value *AI,
> -  unsigned ArgNo, CGBuilderTy ,
> -  const bool UsePointerValue) {
> +  unsigned ArgNo, CGBuilderTy ) {
>assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
> -  return EmitDeclare(VD, AI, ArgNo, Builder, UsePointerValue);
> +  return EmitDeclare(VD, AI, ArgNo, Builder);
>  }
>
>  namespace {
>
> diff  --git a/clang/lib/CodeGen/CGDebugInfo.h 
> b/clang/lib/CodeGen/CGDebugInfo.h
> index 10660a2550b56..95484a060cd88 100644
> --- a/clang/lib/CodeGen/CGDebugInfo.h
> +++ b/clang/lib/CodeGen/CGDebugInfo.h
> @@ -487,9 +487,10 @@ class CGDebugInfo {
>
>/// Emit call to \c llvm.dbg.declare for an argument variable
>/// declaration.
> -  llvm::DILocalVariable *
> -  EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI, unsigned 
> ArgNo,
> -   CGBuilderTy , bool UsePointerValue = 
> false);
> +  llvm::DILocalVariable *EmitDeclareOfArgVariable(const VarDecl *Decl,
> +  llvm::Value *AI,
> +  unsigned ArgNo,
> +  CGBuilderTy );
>
>/// Emit call to \c llvm.dbg.declare for the block-literal argument
>/// to a block invocation function.
>
> diff  --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
> index a70997f5b27b8..ceaddc4e694ac 100644
> --- a/clang/lib/CodeGen/CGDecl.cpp
> +++ b/clang/lib/CodeGen/CGDecl.cpp
> @@ -2476,8 +2476,6 @@ void CodeGenFunction::EmitParmDecl(const VarDecl , 
> ParamValue Arg,
>Address AllocaPtr = Address::invalid();
>bool DoStore = false;
>bool IsScalar = hasScalarEvaluationKind(Ty);
> -  

Re: [clang] 596f76a - Revert "[C2x] reject type definitions in offsetof"

2023-01-16 Thread Roman Lebedev via cfe-commits
Reminder to please always mention the reason for the revert/recommit
in the commit message.

On Mon, Jan 16, 2023 at 11:53 AM Yingchi Long via cfe-commits
 wrote:
>
>
> Author: Yingchi Long
> Date: 2023-01-16T16:52:50+08:00
> New Revision: 596f76a799c933927eec4d8ac8a83c44efff9854
>
> URL: 
> https://github.com/llvm/llvm-project/commit/596f76a799c933927eec4d8ac8a83c44efff9854
> DIFF: 
> https://github.com/llvm/llvm-project/commit/596f76a799c933927eec4d8ac8a83c44efff9854.diff
>
> LOG: Revert "[C2x] reject type definitions in offsetof"
>
> This reverts commit e327b52766ed497e4779f4e652b9ad237dfda8e6.
>
> Added:
>
>
> Modified:
> clang/docs/ReleaseNotes.rst
> clang/include/clang/Basic/DiagnosticSemaKinds.td
> clang/include/clang/Parse/Parser.h
> clang/include/clang/Parse/RAIIObjectsForParser.h
> clang/include/clang/Sema/Sema.h
> clang/lib/Parse/ParseDecl.cpp
> clang/lib/Parse/ParseDeclCXX.cpp
> clang/lib/Parse/ParseExpr.cpp
> clang/lib/Sema/SemaDecl.cpp
> clang/lib/Sema/SemaDeclCXX.cpp
> clang/lib/Sema/SemaTemplate.cpp
> clang/test/C/drs/dr4xx.c
> clang/test/Parser/declarators.c
> clang/test/SemaCXX/offsetof.cpp
>
> Removed:
> clang/test/C/C2x/n2350.c
>
>
> 
> diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
> index a75bc1df2d7c9..09133f967f01f 100644
> --- a/clang/docs/ReleaseNotes.rst
> +++ b/clang/docs/ReleaseNotes.rst
> @@ -670,9 +670,6 @@ C2x Feature Support
>va_start(list); // Invalid in C17 and earlier, valid in C2x and later.
>va_end(list);
>  }
> -
> -- Reject type definitions in the ``type`` argument of ``__builtin_offsetof``
> -  according to `WG14 N2350 
> `_.
>
>  C++ Language Changes in Clang
>  -
>
> diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
> b/clang/include/clang/Basic/DiagnosticSemaKinds.td
> index 862ac845bda45..02afb098b2395 100644
> --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
> +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
> @@ -1650,8 +1650,6 @@ def err_type_defined_in_condition : Error<
>"%0 cannot be defined in a condition">;
>  def err_type_defined_in_enum : Error<
>"%0 cannot be defined in an enumeration">;
> -def err_type_defined_in_offsetof : Error<
> -  "%0 cannot be defined in '%select{__builtin_offsetof|offsetof}1'">;
>
>  def note_pure_virtual_function : Note<
>"unimplemented pure virtual method %0 in %1">;
>
> diff  --git a/clang/include/clang/Parse/Parser.h 
> b/clang/include/clang/Parse/Parser.h
> index 6f9581b9ea1fc..7a33532eec14e 100644
> --- a/clang/include/clang/Parse/Parser.h
> +++ b/clang/include/clang/Parse/Parser.h
> @@ -62,7 +62,6 @@ class Parser : public CodeCompletionHandler {
>friend class ColonProtectionRAIIObject;
>friend class ParsingOpenMPDirectiveRAII;
>friend class InMessageExpressionRAIIObject;
> -  friend class OffsetOfStateRAIIObject;
>friend class PoisonSEHIdentifiersRAIIObject;
>friend class ObjCDeclContextSwitch;
>friend class ParenBraceBracketBalancer;
> @@ -249,8 +248,6 @@ class Parser : public CodeCompletionHandler {
>/// function call.
>bool CalledSignatureHelp = false;
>
> -  Sema::OffsetOfKind OffsetOfState = Sema::OffsetOfKind::OOK_Outside;
> -
>/// The "depth" of the template parameters currently being parsed.
>unsigned TemplateParameterDepth;
>
>
> diff  --git a/clang/include/clang/Parse/RAIIObjectsForParser.h 
> b/clang/include/clang/Parse/RAIIObjectsForParser.h
> index cb525c9d0edd6..5ae609e600734 100644
> --- a/clang/include/clang/Parse/RAIIObjectsForParser.h
> +++ b/clang/include/clang/Parse/RAIIObjectsForParser.h
> @@ -341,19 +341,6 @@ namespace clang {
>  }
>};
>
> -  class OffsetOfStateRAIIObject {
> -Sema::OffsetOfKind 
> -Sema::OffsetOfKind OldValue;
> -
> -  public:
> -OffsetOfStateRAIIObject(Parser , Sema::OffsetOfKind Value)
> -: OffsetOfState(P.OffsetOfState), OldValue(P.OffsetOfState) {
> -  OffsetOfState = Value;
> -}
> -
> -~OffsetOfStateRAIIObject() { OffsetOfState = OldValue; }
> -  };
> -
>/// RAII object that makes sure paren/bracket/brace count is correct
>/// after declaration/statement parsing, even when there's a parsing error.
>class ParenBraceBracketBalancer {
>
> diff  --git a/clang/include/clang/Sema/Sema.h 
> b/clang/include/clang/Sema/Sema.h
> index 35e319879a98d..30c5ea608f7a0 100644
> --- a/clang/include/clang/Sema/Sema.h
> +++ b/clang/include/clang/Sema/Sema.h
> @@ -3304,16 +3304,6 @@ class Sema final {
>  TUK_Friend   // Friend declaration:  'friend struct foo;'
>};
>
> -  enum OffsetOfKind {
> -// Not parsing a type within __builtin_offsetof.
> -OOK_Outside,
> -// Parsing a type within __builtin_offsetof.
> -OOK_Builtin,
> -// Parsing a type within macro "offsetof", 

Re: [clang] 6809af1 - Revert "[OpenMP][OMPIRBuilder] Move SIMD alignment calculation to LLVM Frontend"

2023-01-13 Thread Roman Lebedev via cfe-commits
Reminder to please always mention the reason for the revert/recommit
in the commit message.

On Fri, Jan 13, 2023 at 11:40 PM Dominik Adamski via cfe-commits
 wrote:
>
>
> Author: Dominik Adamski
> Date: 2023-01-13T14:38:17-06:00
> New Revision: 6809af1a232bc5ac71358e4b874759ddaae056a1
>
> URL: 
> https://github.com/llvm/llvm-project/commit/6809af1a232bc5ac71358e4b874759ddaae056a1
> DIFF: 
> https://github.com/llvm/llvm-project/commit/6809af1a232bc5ac71358e4b874759ddaae056a1.diff
>
> LOG: Revert "[OpenMP][OMPIRBuilder] Move SIMD alignment calculation to LLVM 
> Frontend"
>
> This reverts commit ed01de67433174d3157e9d239d59dd465d52c6a5.
>
> Added:
>
>
> Modified:
> clang/include/clang/Basic/TargetInfo.h
> clang/lib/AST/ASTContext.cpp
> clang/lib/Basic/TargetInfo.cpp
> clang/lib/Basic/Targets/PPC.h
> clang/lib/Basic/Targets/WebAssembly.h
> clang/lib/Basic/Targets/X86.cpp
> lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
> llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
> llvm/include/llvm/Target/TargetMachine.h
> llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
> llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
> llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
> llvm/lib/Target/X86/X86TargetMachine.cpp
>
> Removed:
>
>
>
> 
> diff  --git a/clang/include/clang/Basic/TargetInfo.h 
> b/clang/include/clang/Basic/TargetInfo.h
> index def708daac8d2..a5aea33d84751 100644
> --- a/clang/include/clang/Basic/TargetInfo.h
> +++ b/clang/include/clang/Basic/TargetInfo.h
> @@ -226,6 +226,7 @@ class TargetInfo : public virtual TransferrableTargetInfo,
>bool HasStrictFP;
>
>unsigned char MaxAtomicPromoteWidth, MaxAtomicInlineWidth;
> +  unsigned short SimdDefaultAlign;
>std::string DataLayoutString;
>const char *UserLabelPrefix;
>const char *MCountName;
> @@ -794,6 +795,10 @@ class TargetInfo : public virtual 
> TransferrableTargetInfo,
>
>/// Return the maximum vector alignment supported for the given target.
>unsigned getMaxVectorAlign() const { return MaxVectorAlign; }
> +  /// Return default simd alignment for the given target. Generally, this
> +  /// value is type-specific, but this alignment can be used for most of the
> +  /// types for the given target.
> +  unsigned getSimdDefaultAlign() const { return SimdDefaultAlign; }
>
>unsigned getMaxOpenCLWorkGroupSize() const { return 
> MaxOpenCLWorkGroupSize; }
>
>
> diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
> index 6b97407236ca5..15a43807c3603 100644
> --- a/clang/lib/AST/ASTContext.cpp
> +++ b/clang/lib/AST/ASTContext.cpp
> @@ -79,7 +79,6 @@
>  #include "llvm/ADT/StringExtras.h"
>  #include "llvm/ADT/StringRef.h"
>  #include "llvm/ADT/Triple.h"
> -#include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
>  #include "llvm/Support/Capacity.h"
>  #include "llvm/Support/Casting.h"
>  #include "llvm/Support/Compiler.h"
> @@ -94,7 +93,6 @@
>  #include 
>  #include 
>  #include 
> -#include 
>  #include 
>  #include 
>  #include 
> @@ -2465,16 +2463,7 @@ unsigned ASTContext::getTypeUnadjustedAlign(const Type 
> *T) const {
>  }
>
>  unsigned ASTContext::getOpenMPDefaultSimdAlign(QualType T) const {
> -  const std::vector  =
> -  Target->getTargetOpts().Features;
> -  std::string TargetFeaturesString = std::accumulate(
> -  TargetFeatures.cbegin(), TargetFeatures.cend(), std::string(),
> -  [](const std::string , const std::string ) {
> -return s1.empty() ? s2 : s1 + "," + s2;
> -  });
> -  unsigned SimdAlign = llvm::OpenMPIRBuilder ::getSimdDefaultAlignment(
> -  getTargetInfo().getTriple().str(), Target->getTargetOpts().CPU,
> -  TargetFeaturesString);
> +  unsigned SimdAlign = getTargetInfo().getSimdDefaultAlign();
>return SimdAlign;
>  }
>
>
> diff  --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
> index fa5e568d599d0..8ee43261fc1d3 100644
> --- a/clang/lib/Basic/TargetInfo.cpp
> +++ b/clang/lib/Basic/TargetInfo.cpp
> @@ -119,6 +119,7 @@ TargetInfo::TargetInfo(const llvm::Triple ) : Triple(T) 
> {
>MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 0;
>MaxVectorAlign = 0;
>MaxTLSAlign = 0;
> +  SimdDefaultAlign = 0;
>SizeType = UnsignedLong;
>PtrDiffType = SignedLong;
>IntMaxType = SignedLongLong;
>
> diff  --git a/clang/lib/Basic/Targets/PPC.h b/clang/lib/Basic/Targets/PPC.h
> index 4c02183feb4c1..cc185fdadfcbc 100644
> --- a/clang/lib/Basic/Targets/PPC.h
> +++ b/clang/lib/Basic/Targets/PPC.h
> @@ -87,6 +87,7 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public 
> TargetInfo {
>PPCTargetInfo(const llvm::Triple , const TargetOptions &)
>: TargetInfo(Triple) {
>  SuitableAlign = 128;
> +SimdDefaultAlign = 128;
>  LongDoubleWidth = LongDoubleAlign = 128;
>  LongDoubleFormat = ::APFloat::PPCDoubleDouble();
>  HasStrictFP = true;
>
> diff  --git 

Re: [clang] 8bd65e5 - Revert "[TargetParser] Generate the defs for RISCV CPUs using llvm-tblgen."

2023-01-11 Thread Roman Lebedev via cfe-commits
Reminder to please always mention the reason for the revert/recommit
in the commit message.

On Wed, Jan 11, 2023 at 12:23 PM Francesco Petrogalli via cfe-commits
 wrote:
>
>
> Author: Francesco Petrogalli
> Date: 2023-01-11T10:22:56+01:00
> New Revision: 8bd65e535fb33bc48805bafed8217b16a853e158
>
> URL: 
> https://github.com/llvm/llvm-project/commit/8bd65e535fb33bc48805bafed8217b16a853e158
> DIFF: 
> https://github.com/llvm/llvm-project/commit/8bd65e535fb33bc48805bafed8217b16a853e158.diff
>
> LOG: Revert "[TargetParser] Generate the defs for RISCV CPUs using 
> llvm-tblgen."
>
> This reverts commit cf7a8305a2b4ddfd299c748136cb9a2960ef7089.
>
> Added:
> llvm/include/llvm/TargetParser/RISCVTargetParser.def
>
> Modified:
> clang/lib/Basic/Targets/RISCV.cpp
> clang/lib/Driver/ToolChains/Arch/RISCV.cpp
> llvm/include/llvm/CMakeLists.txt
> llvm/include/llvm/TargetParser/TargetParser.h
> llvm/include/llvm/module.extern.modulemap
> llvm/include/llvm/module.install.modulemap
> llvm/include/llvm/module.modulemap
> llvm/lib/Target/RISCV/RISCV.td
> llvm/lib/Target/RISCV/RISCVISelLowering.h
> llvm/lib/TargetParser/CMakeLists.txt
> llvm/lib/TargetParser/TargetParser.cpp
> llvm/utils/TableGen/CMakeLists.txt
> llvm/utils/TableGen/TableGen.cpp
> llvm/utils/TableGen/TableGenBackends.h
>
> Removed:
> llvm/include/llvm/TargetParser/CMakeLists.txt
> llvm/include/llvm/TargetParser/RISCVTargetParser.h
> llvm/lib/TargetParser/RISCVTargetParser.cpp
> llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
>
>
> 
> diff  --git a/clang/lib/Basic/Targets/RISCV.cpp 
> b/clang/lib/Basic/Targets/RISCV.cpp
> index a9adafddb7e54..7713398c83b20 100644
> --- a/clang/lib/Basic/Targets/RISCV.cpp
> +++ b/clang/lib/Basic/Targets/RISCV.cpp
> @@ -15,8 +15,8 @@
>  #include "clang/Basic/MacroBuilder.h"
>  #include "clang/Basic/TargetBuiltins.h"
>  #include "llvm/ADT/StringSwitch.h"
> +#include "llvm/Support/TargetParser.h"
>  #include "llvm/Support/raw_ostream.h"
> -#include "llvm/TargetParser/RISCVTargetParser.h"
>  #include 
>
>  using namespace clang;
>
> diff  --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
> b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
> index 5c11064d81d59..4724e5c5a37ec 100644
> --- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
> +++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
> @@ -17,8 +17,8 @@
>  #include "llvm/Support/Error.h"
>  #include "llvm/Support/Host.h"
>  #include "llvm/Support/RISCVISAInfo.h"
> +#include "llvm/Support/TargetParser.h"
>  #include "llvm/Support/raw_ostream.h"
> -#include "llvm/TargetParser/RISCVTargetParser.h"
>
>  using namespace clang::driver;
>  using namespace clang::driver::tools;
>
> diff  --git a/llvm/include/llvm/CMakeLists.txt 
> b/llvm/include/llvm/CMakeLists.txt
> index d1dc0a99463ba..b46319f24fc8e 100644
> --- a/llvm/include/llvm/CMakeLists.txt
> +++ b/llvm/include/llvm/CMakeLists.txt
> @@ -1,7 +1,6 @@
>  add_subdirectory(IR)
>  add_subdirectory(Support)
>  add_subdirectory(Frontend)
> -add_subdirectory(TargetParser)
>
>  # If we're doing an out-of-tree build, copy a module map for generated
>  # header files into the build area.
>
> diff  --git a/llvm/include/llvm/TargetParser/CMakeLists.txt 
> b/llvm/include/llvm/TargetParser/CMakeLists.txt
> deleted file mode 100644
> index d102dcf4dde7e..0
> --- a/llvm/include/llvm/TargetParser/CMakeLists.txt
> +++ /dev/null
> @@ -1,4 +0,0 @@
> -set(LLVM_TARGET_DEFINITIONS ${CMAKE_SOURCE_DIR}/lib/Target/RISCV/RISCV.td)
> -tablegen(LLVM RISCVTargetParserDef.inc -gen-riscv-target-def -I 
> ${CMAKE_SOURCE_DIR}/lib/Target/RISCV/)
> -add_public_tablegen_target(RISCVTargetParserTableGen)
> -
>
> diff  --git a/llvm/include/llvm/TargetParser/RISCVTargetParser.def 
> b/llvm/include/llvm/TargetParser/RISCVTargetParser.def
> new file mode 100644
> index 0..6d65ac1c398e7
> --- /dev/null
> +++ b/llvm/include/llvm/TargetParser/RISCVTargetParser.def
> @@ -0,0 +1,35 @@
> +#ifndef PROC
> +#define PROC(ENUM, NAME, FEATURES, DEFAULT_MARCH)
> +#endif
> +
> +PROC(INVALID, {"invalid"}, FK_INVALID, {""})
> +PROC(GENERIC_RV32, {"generic-rv32"}, FK_NONE, {""})
> +PROC(GENERIC_RV64, {"generic-rv64"}, FK_64BIT, {""})
> +PROC(ROCKET_RV32, {"rocket-rv32"}, FK_NONE, {""})
> +PROC(ROCKET_RV64, {"rocket-rv64"}, FK_64BIT, {""})
> +PROC(SIFIVE_E20, {"sifive-e20"}, FK_NONE, {"rv32imc"})
> +PROC(SIFIVE_E21, {"sifive-e21"}, FK_NONE, {"rv32imac"})
> +PROC(SIFIVE_E24, {"sifive-e24"}, FK_NONE, {"rv32imafc"})
> +PROC(SIFIVE_E31, {"sifive-e31"}, FK_NONE, {"rv32imac"})
> +PROC(SIFIVE_E34, {"sifive-e34"}, FK_NONE, {"rv32imafc"})
> +PROC(SIFIVE_E76, {"sifive-e76"}, FK_NONE, {"rv32imafc"})
> +PROC(SIFIVE_S21, {"sifive-s21"}, FK_64BIT, {"rv64imac"})
> +PROC(SIFIVE_S51, {"sifive-s51"}, FK_64BIT, {"rv64imac"})
> +PROC(SIFIVE_S54, {"sifive-s54"}, FK_64BIT, {"rv64gc"})
> +PROC(SIFIVE_S76, {"sifive-s76"}, FK_64BIT, {"rv64gc"})

Re: [clang] b597992 - Revert "[perf-training] Check extension in findFilesWithExtension"

2023-01-10 Thread Roman Lebedev via cfe-commits
Reminder to please always mention the reason for the revert/recommit
in the commit message.

On Wed, Jan 11, 2023 at 1:22 AM Amir Aupov via cfe-commits
 wrote:
>
>
> Author: Amir Aupov
> Date: 2023-01-10T14:22:36-08:00
> New Revision: b59799241b3902a460c3b1156477af369934a13e
>
> URL: 
> https://github.com/llvm/llvm-project/commit/b59799241b3902a460c3b1156477af369934a13e
> DIFF: 
> https://github.com/llvm/llvm-project/commit/b59799241b3902a460c3b1156477af369934a13e.diff
>
> LOG: Revert "[perf-training] Check extension in findFilesWithExtension"
>
> This reverts commit 1fbbf92e4fda3c7a3be1c02e1f7240135557846d.
>
> Added:
>
>
> Modified:
> clang/utils/perf-training/perf-helper.py
>
> Removed:
>
>
>
> 
> diff  --git a/clang/utils/perf-training/perf-helper.py 
> b/clang/utils/perf-training/perf-helper.py
> index d68ab3c72806e..c6a815e654736 100644
> --- a/clang/utils/perf-training/perf-helper.py
> +++ b/clang/utils/perf-training/perf-helper.py
> @@ -23,7 +23,7 @@ def findFilesWithExtension(path, extension):
>filenames = []
>for root, dirs, files in os.walk(path):
>  for filename in files:
> -  if os.path.splitext(filename)[1] == extension:
> +  if filename.endswith(extension):
>  filenames.append(os.path.join(root, filename))
>return filenames
>
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang-tools-extra] ef9aa34 - Revert "Remove the ThreadLocal template from LLVM."

2023-01-10 Thread Roman Lebedev via cfe-commits
Reminder to please always mention the reason for the revert/recommit
in the commit message.

On Tue, Jan 10, 2023 at 7:22 AM Owen Anderson via cfe-commits
 wrote:
>
>
> Author: Owen Anderson
> Date: 2023-01-09T21:21:38-07:00
> New Revision: ef9aa34f0274cdbfa82c47f8ab99f02679fd0d13
>
> URL: 
> https://github.com/llvm/llvm-project/commit/ef9aa34f0274cdbfa82c47f8ab99f02679fd0d13
> DIFF: 
> https://github.com/llvm/llvm-project/commit/ef9aa34f0274cdbfa82c47f8ab99f02679fd0d13.diff
>
> LOG: Revert "Remove the ThreadLocal template from LLVM."
>
> This reverts commit 54d78b639b9c18b42abd4fac5c6e76105f06b3ef.
>
> Added:
> llvm/include/llvm/Support/ThreadLocal.h
> llvm/lib/Support/ThreadLocal.cpp
> llvm/lib/Support/Unix/ThreadLocal.inc
> llvm/lib/Support/Windows/ThreadLocal.inc
> llvm/unittests/Support/ThreadLocalTest.cpp
>
> Modified:
> clang-tools-extra/clangd/support/ThreadCrashReporter.cpp
> llvm/lib/Support/CMakeLists.txt
> llvm/lib/Support/CrashRecoveryContext.cpp
> llvm/unittests/Support/CMakeLists.txt
> mlir/include/mlir/Support/ThreadLocalCache.h
>
> Removed:
>
>
>
> 
> diff  --git a/clang-tools-extra/clangd/support/ThreadCrashReporter.cpp 
> b/clang-tools-extra/clangd/support/ThreadCrashReporter.cpp
> index 9551bbfda43c1..05afb3b25f28e 100644
> --- a/clang-tools-extra/clangd/support/ThreadCrashReporter.cpp
> +++ b/clang-tools-extra/clangd/support/ThreadCrashReporter.cpp
> @@ -7,6 +7,7 @@
>  
> //===--===//
>
>  #include "support/ThreadCrashReporter.h"
> +#include "llvm/Support/ThreadLocal.h"
>  #include 
>
>  namespace clang {
>
> diff  --git a/llvm/include/llvm/Support/ThreadLocal.h 
> b/llvm/include/llvm/Support/ThreadLocal.h
> new file mode 100644
> index 0..d6838c15fc345
> --- /dev/null
> +++ b/llvm/include/llvm/Support/ThreadLocal.h
> @@ -0,0 +1,62 @@
> +//===- llvm/Support/ThreadLocal.h - Thread Local Data *- 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 declares the llvm::sys::ThreadLocal class.
> +//
> +//===--===//
> +
> +#ifndef LLVM_SUPPORT_THREADLOCAL_H
> +#define LLVM_SUPPORT_THREADLOCAL_H
> +
> +#include "llvm/Support/DataTypes.h"
> +#include "llvm/Support/Threading.h"
> +#include 
> +
> +namespace llvm {
> +  namespace sys {
> +// ThreadLocalImpl - Common base class of all ThreadLocal instantiations.
> +// YOU SHOULD NEVER USE THIS DIRECTLY.
> +class ThreadLocalImpl {
> +  typedef uint64_t ThreadLocalDataTy;
> +  /// Platform-specific thread local data.
> +  ///
> +  /// This is embedded in the class and we avoid malloc'ing/free'ing it,
> +  /// to make this class more safe for use along with 
> CrashRecoveryContext.
> +  union {
> +char data[sizeof(ThreadLocalDataTy)];
> +ThreadLocalDataTy align_data;
> +  };
> +public:
> +  ThreadLocalImpl();
> +  virtual ~ThreadLocalImpl();
> +  void setInstance(const void* d);
> +  void *getInstance();
> +  void removeInstance();
> +};
> +
> +/// ThreadLocal - A class used to abstract thread-local storage.  It 
> holds,
> +/// for each thread, a pointer a single object of type T.
> +template
> +class ThreadLocal : public ThreadLocalImpl {
> +public:
> +  ThreadLocal() : ThreadLocalImpl() { }
> +
> +  /// get - Fetches a pointer to the object associated with the current
> +  /// thread.  If no object has yet been associated, it returns NULL;
> +  T* get() { return static_cast(getInstance()); }
> +
> +  // set - Associates a pointer to an object with the current thread.
> +  void set(T* d) { setInstance(d); }
> +
> +  // erase - Removes the pointer associated with the current thread.
> +  void erase() { removeInstance(); }
> +};
> +  }
> +}
> +
> +#endif
>
> diff  --git a/llvm/lib/Support/CMakeLists.txt 
> b/llvm/lib/Support/CMakeLists.txt
> index 9b5402fa54f0f..46469c6e9e624 100644
> --- a/llvm/lib/Support/CMakeLists.txt
> +++ b/llvm/lib/Support/CMakeLists.txt
> @@ -260,6 +260,7 @@ add_llvm_component_library(LLVMSupport
>Program.cpp
>RWMutex.cpp
>Signals.cpp
> +  ThreadLocal.cpp
>Threading.cpp
>Valgrind.cpp
>Watchdog.cpp
>
> diff  --git a/llvm/lib/Support/CrashRecoveryContext.cpp 
> b/llvm/lib/Support/CrashRecoveryContext.cpp
> index 9e792d1f51777..c7c384c9edc22 100644
> --- a/llvm/lib/Support/CrashRecoveryContext.cpp
> +++ b/llvm/lib/Support/CrashRecoveryContext.cpp
> @@ -11,6 +11,7 @@
>  #include 

Re: [clang] f58b025 - Revert "[-Wunsafe-buffer-usage] Add a new `forEachDescendant` matcher that skips callable declarations"

2023-01-04 Thread Roman Lebedev via cfe-commits
Reminder to please always mention the reason for the revert/recommit
in the commit message.

On Thu, Jan 5, 2023 at 4:24 AM Ziqing Luo via cfe-commits
 wrote:
>
>
> Author: Ziqing Luo
> Date: 2023-01-04T17:16:21-08:00
> New Revision: f58b025354ee2d3bcd7ab2399a11429ec940c1e0
>
> URL: 
> https://github.com/llvm/llvm-project/commit/f58b025354ee2d3bcd7ab2399a11429ec940c1e0
> DIFF: 
> https://github.com/llvm/llvm-project/commit/f58b025354ee2d3bcd7ab2399a11429ec940c1e0.diff
>
> LOG: Revert "[-Wunsafe-buffer-usage] Add a new `forEachDescendant` matcher 
> that skips callable declarations"
>
> This reverts commit b2ac5fd724c44cf662caed84bd8f84af574b981d.
>
> Added:
>
>
> Modified:
> clang/lib/Analysis/UnsafeBufferUsage.cpp
> clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp
>
> Removed:
>
>
>
> 
> diff  --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
> b/clang/lib/Analysis/UnsafeBufferUsage.cpp
> index 29c8dbb45fe9..a699d27c1544 100644
> --- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
> +++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
> @@ -8,111 +8,12 @@
>
>  #include "clang/Analysis/Analyses/UnsafeBufferUsage.h"
>  #include "clang/ASTMatchers/ASTMatchFinder.h"
> -#include "clang/AST/RecursiveASTVisitor.h"
>  #include "llvm/ADT/SmallVector.h"
>
>  using namespace llvm;
>  using namespace clang;
>  using namespace ast_matchers;
>
> -namespace clang::ast_matchers::internal {
> -// A `RecursiveASTVisitor` that traverses all descendants of a given node "n"
> -// except for those belonging to a
> diff erent callable of "n".
> -class MatchDescendantVisitor
> -: public RecursiveASTVisitor {
> -public:
> -  typedef RecursiveASTVisitor VisitorBase;
> -
> -  // Creates an AST visitor that matches `Matcher` on all
> -  // descendants of a given node "n" except for the ones
> -  // belonging to a
> diff erent callable of "n".
> -  MatchDescendantVisitor(const DynTypedMatcher *Matcher, ASTMatchFinder 
> *Finder,
> - BoundNodesTreeBuilder *Builder,
> - ASTMatchFinder::BindKind Bind)
> -  : Matcher(Matcher), Finder(Finder), Builder(Builder), Bind(Bind),
> -Matches(false) {}
> -
> -  // Returns true if a match is found in a subtree of `DynNode`, which 
> belongs
> -  // to the same callable of `DynNode`.
> -  bool findMatch(const DynTypedNode ) {
> -Matches = false;
> -if (const Stmt *StmtNode = DynNode.get()) {
> -  TraverseStmt(const_cast(StmtNode));
> -  *Builder = ResultBindings;
> -  return Matches;
> -}
> -return false;
> -  }
> -
> -  // The following are overriding methods from the base visitor class.
> -  // They are public only to allow CRTP to work. They are *not *part
> -  // of the public API of this class.
> -
> -  // For the matchers so far used in safe buffers, we only need to match
> -  // `Stmt`s.  To override more as needed.
> -
> -  bool TraverseDecl(Decl *Node) {
> -if (!Node)
> -  return true;
> -if (!match(*Node))
> -  return false;
> -// To skip callables:
> -if (isa(Node))
> -  return true;
> -// Traverse descendants
> -return VisitorBase::TraverseDecl(Node);
> -  }
> -
> -  bool TraverseStmt(Stmt *Node, DataRecursionQueue *Queue = nullptr) {
> -if (!Node)
> -  return true;
> -if (!match(*Node))
> -  return false;
> -// To skip callables:
> -if (isa(Node))
> -  return true;
> -return VisitorBase::TraverseStmt(Node);
> -  }
> -
> -  bool shouldVisitTemplateInstantiations() const { return true; }
> -  bool shouldVisitImplicitCode() const {
> -// TODO: let's ignore implicit code for now
> -return false;
> -  }
> -
> -private:
> -  // Sets 'Matched' to true if 'Matcher' matches 'Node'
> -  //
> -  // Returns 'true' if traversal should continue after this function
> -  // returns, i.e. if no match is found or 'Bind' is 'BK_All'.
> -  template  bool match(const T ) {
> -BoundNodesTreeBuilder RecursiveBuilder(*Builder);
> -
> -if (Matcher->matches(DynTypedNode::create(Node), Finder,
> - )) {
> -  ResultBindings.addMatch(RecursiveBuilder);
> -  Matches = true;
> -  if (Bind != ASTMatchFinder::BK_All)
> -return false; // Abort as soon as a match is found.
> -}
> -return true;
> -  }
> -
> -  const DynTypedMatcher *const Matcher;
> -  ASTMatchFinder *const Finder;
> -  BoundNodesTreeBuilder *const Builder;
> -  BoundNodesTreeBuilder ResultBindings;
> -  const ASTMatchFinder::BindKind Bind;
> -  bool Matches;
> -};
> -
> -AST_MATCHER_P(Stmt, forEveryDescendant, Matcher, innerMatcher) {
> -  MatchDescendantVisitor Visitor(new DynTypedMatcher(innerMatcher), Finder,
> - Builder, ASTMatchFinder::BK_All);
> -  return Visitor.findMatch(DynTypedNode::create(Node));
> -}
> -} // namespace clang::ast_matchers::internal
> -
>  namespace {
>  // Because the analysis revolves around 

[clang] 96d3c82 - Revert "[SROA] `isVectorPromotionViable()`: memory intrinsics operate on vectors of bytes (take 3)"

2022-12-16 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2022-12-16T22:58:41+03:00
New Revision: 96d3c82645cf41a38543c5128cc15cda5761a76a

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

LOG: Revert "[SROA] `isVectorPromotionViable()`: memory intrinsics operate on 
vectors of bytes (take 3)"

While the PPC litte-endian miscompile did get addressed
by https://reviews.llvm.org/D140046
the PPV big-endian bots are still unhappy.
https://lab.llvm.org/buildbot/#/builders/93/builds/12560

This reverts commit 7bd358bcb4e358b4351c69e02ef76939e08acdc7.

Added: 


Modified: 
clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
llvm/lib/Transforms/Scalar/SROA.cpp
llvm/test/CodeGen/AMDGPU/v1024.ll
llvm/test/DebugInfo/Generic/assignment-tracking/sroa/memcpy.ll

llvm/test/DebugInfo/Generic/assignment-tracking/sroa/memmove-to-from-same-alloca.ll
llvm/test/DebugInfo/Generic/assignment-tracking/sroa/store.ll
llvm/test/DebugInfo/Generic/assignment-tracking/sroa/user-memcpy.ll
llvm/test/DebugInfo/Generic/assignment-tracking/sroa/vec-2.ll
llvm/test/DebugInfo/X86/sroasplit-1.ll
llvm/test/DebugInfo/X86/sroasplit-4.ll
llvm/test/Transforms/PhaseOrdering/instcombine-sroa-inttoptr.ll
llvm/test/Transforms/SROA/address-spaces.ll
llvm/test/Transforms/SROA/alignment.ll
llvm/test/Transforms/SROA/alloca-address-space.ll
llvm/test/Transforms/SROA/basictest.ll
llvm/test/Transforms/SROA/pointer-offset-size.ll
llvm/test/Transforms/SROA/scalable-vectors.ll
llvm/test/Transforms/SROA/slice-width.ll
llvm/test/Transforms/SROA/tbaa-struct.ll
llvm/test/Transforms/SROA/tbaa-struct2.ll
llvm/test/Transforms/SROA/vector-promotion.ll

Removed: 




diff  --git a/clang/test/CodeGenOpenCL/amdgpu-nullptr.cl 
b/clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
index 859e81f08d6bd..65f6f2e7d8c24 100644
--- a/clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
+++ b/clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
@@ -515,17 +515,13 @@ typedef struct {
   private char *p;
 } StructTy3;
 
-// CHECK-LABEL: @test_memset_private(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = bitcast [[STRUCT_STRUCTTY3:%.*]] 
addrspace(5)* [[PTR:%.*]] to i8 addrspace(5)*
-// CHECK-NEXT:[[S3_SROA_0_SROA_0_0_S3_SROA_0_0__SROA_CAST2_SROA_CAST:%.*]] 
= bitcast [[STRUCT_STRUCTTY3]] addrspace(5)* [[PTR]] to <32 x i8> addrspace(5)*
-// CHECK-NEXT:store <32 x i8> zeroinitializer, <32 x i8> addrspace(5)* 
[[S3_SROA_0_SROA_0_0_S3_SROA_0_0__SROA_CAST2_SROA_CAST]], align 8, !tbaa.struct 
!9
-// CHECK-NEXT:[[S3_SROA_4_0__SROA_IDX6:%.*]] = getelementptr inbounds 
[[STRUCT_STRUCTTY3]], [[STRUCT_STRUCTTY3]] addrspace(5)* [[PTR]], i32 0, i32 4
-// CHECK-NEXT:store i8 addrspace(5)* addrspacecast (i8* null to i8 
addrspace(5)*), i8 addrspace(5)* addrspace(5)* [[S3_SROA_4_0__SROA_IDX6]], 
align 8, !tbaa.struct !12
-// CHECK-NEXT:[[S3_SROA_5_0__SROA_IDX:%.*]] = getelementptr inbounds i8, 
i8 addrspace(5)* [[TMP0]], i32 36
-// CHECK-NEXT:[[S3_SROA_5_0__SROA_CAST8:%.*]] = bitcast i8 addrspace(5)* 
[[S3_SROA_5_0__SROA_IDX]] to i32 addrspace(5)*
-// CHECK-NEXT:store i32 0, i32 addrspace(5)* [[S3_SROA_5_0__SROA_CAST8]], 
align 4, !tbaa.struct !13
-// CHECK-NEXT:ret void
+// CHECK-LABEL: test_memset_private
+// CHECK: call void @llvm.memset.p5i8.i64(i8 addrspace(5)* noundef align 8 
{{.*}}, i8 0, i64 32, i1 false)
+// CHECK: [[GEP:%.*]] = getelementptr inbounds %struct.StructTy3, 
%struct.StructTy3 addrspace(5)* %ptr, i32 0, i32 4
+// CHECK: store i8 addrspace(5)* addrspacecast (i8* null to i8 addrspace(5)*), 
i8 addrspace(5)* addrspace(5)* [[GEP]]
+// CHECK: [[GEP1:%.*]] = getelementptr inbounds i8, i8 addrspace(5)* {{.*}}, 
i32 36
+// CHECK: [[GEP1_CAST:%.*]] = bitcast i8 addrspace(5)* [[GEP1]] to i32 
addrspace(5)*
+// CHECK: store i32 0, i32 addrspace(5)* [[GEP1_CAST]], align 4
 void test_memset_private(private StructTy3 *ptr) {
   StructTy3 S3 = {0, 0, 0, 0, 0};
   *ptr = S3;

diff  --git a/llvm/lib/Transforms/Scalar/SROA.cpp 
b/llvm/lib/Transforms/Scalar/SROA.cpp
index a9a0f444aec03..748b8627be7ed 100644
--- a/llvm/lib/Transforms/Scalar/SROA.cpp
+++ b/llvm/lib/Transforms/Scalar/SROA.cpp
@@ -2029,10 +2029,8 @@ static bool isVectorPromotionViableForSlice(Partition 
, const Slice ,
   ? Ty->getElementType()
   : FixedVectorType::get(Ty->getElementType(), 
NumElements);
 
-  Type *SplitIntTy = nullptr;
-  if (uint64_t Bitwidth = NumElements * ElementSize * 8;
-  Bitwidth <= IntegerType::MAX_INT_BITS)
-SplitIntTy = Type::getIntNTy(Ty->getContext(), Bitwidth);
+  Type *SplitIntTy =
+  Type::getIntNTy(Ty->getContext(), NumElements * ElementSize * 8);
 
   Use *U = S.getUse();
 
@@ -2051,8 +2049,7 @@ static bool isVectorPromotionViableForSlice(Partition , 
const 

[clang] cfd594f - [SROA] `isVectorPromotionViable()`: memory intrinsics operate on vectors of bytes (take 3)

2022-12-16 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2022-12-16T19:27:38+03:00
New Revision: cfd594f8bb5e779c81171e7c1e61ae8436efabd3

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

LOG: [SROA] `isVectorPromotionViable()`: memory intrinsics operate on vectors 
of bytes (take 3)

* This is a recommit of 3c4d2a03968ccf5889bacffe02d6fa2443b0260f,
* which was reverted in 25f01d593ce296078f57e872778b77d074ae5888,
  because it exposed a miscompile in PPC backend,  which was resolved
  in https://reviews.llvm.org/D140089 / 
cb3f415cd2019df7d14683842198bc4b7a492bc5.
* which was a recommit of cf624b23bc5d5a6161706d1663def49380ff816a,
* which was reverted in 5cfc22cafe3f2465e0bb324f8daba82ffcabd0df,
  because the cut-off on the number of vector elements was not low enough,
  and it triggered both SDAG SDNode operand number assertions,
  5and caused compile time explosions in some cases.

Let's try with something really *REALLY* conservative first,
just to get somewhere, and try to bump it later.

FIXME: should this respect TTI reg width * num vec regs?

Original commit message:

Now, there's a big caveat here - these bytes
are abstract bytes, not the i8 we have in LLVM,
so strictly speaking this is not exactly legal,
see e.g. https://github.com/AliveToolkit/alive2/issues/860
^ the "bytes" "could" have been a pointer,
and loading it as an integer inserts an implicit ptrtoint.

But at the same time,
InstCombine's `InstCombinerImpl::SimplifyAnyMemTransfer()`
would expand a memtransfer of 1/2/4/8 bytes
into integer-typed load+store,
so this isn't exactly a new problem.

Note that in memory, poison is byte-wise,
so we really can't widen elements,
but SROA seems to be inconsistent here.

Fixes #59116.

Added: 


Modified: 
clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
llvm/lib/Transforms/Scalar/SROA.cpp
llvm/test/CodeGen/AMDGPU/v1024.ll
llvm/test/DebugInfo/Generic/assignment-tracking/sroa/memcpy.ll

llvm/test/DebugInfo/Generic/assignment-tracking/sroa/memmove-to-from-same-alloca.ll
llvm/test/DebugInfo/Generic/assignment-tracking/sroa/store.ll
llvm/test/DebugInfo/Generic/assignment-tracking/sroa/user-memcpy.ll
llvm/test/DebugInfo/Generic/assignment-tracking/sroa/vec-2.ll
llvm/test/DebugInfo/X86/sroasplit-1.ll
llvm/test/DebugInfo/X86/sroasplit-4.ll
llvm/test/Transforms/PhaseOrdering/instcombine-sroa-inttoptr.ll
llvm/test/Transforms/SROA/address-spaces.ll
llvm/test/Transforms/SROA/alignment.ll
llvm/test/Transforms/SROA/alloca-address-space.ll
llvm/test/Transforms/SROA/basictest.ll
llvm/test/Transforms/SROA/pointer-offset-size.ll
llvm/test/Transforms/SROA/scalable-vectors.ll
llvm/test/Transforms/SROA/slice-width.ll
llvm/test/Transforms/SROA/tbaa-struct.ll
llvm/test/Transforms/SROA/tbaa-struct2.ll
llvm/test/Transforms/SROA/vector-promotion.ll

Removed: 




diff  --git a/clang/test/CodeGenOpenCL/amdgpu-nullptr.cl 
b/clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
index 65f6f2e7d8c24..859e81f08d6bd 100644
--- a/clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
+++ b/clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
@@ -515,13 +515,17 @@ typedef struct {
   private char *p;
 } StructTy3;
 
-// CHECK-LABEL: test_memset_private
-// CHECK: call void @llvm.memset.p5i8.i64(i8 addrspace(5)* noundef align 8 
{{.*}}, i8 0, i64 32, i1 false)
-// CHECK: [[GEP:%.*]] = getelementptr inbounds %struct.StructTy3, 
%struct.StructTy3 addrspace(5)* %ptr, i32 0, i32 4
-// CHECK: store i8 addrspace(5)* addrspacecast (i8* null to i8 addrspace(5)*), 
i8 addrspace(5)* addrspace(5)* [[GEP]]
-// CHECK: [[GEP1:%.*]] = getelementptr inbounds i8, i8 addrspace(5)* {{.*}}, 
i32 36
-// CHECK: [[GEP1_CAST:%.*]] = bitcast i8 addrspace(5)* [[GEP1]] to i32 
addrspace(5)*
-// CHECK: store i32 0, i32 addrspace(5)* [[GEP1_CAST]], align 4
+// CHECK-LABEL: @test_memset_private(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = bitcast [[STRUCT_STRUCTTY3:%.*]] 
addrspace(5)* [[PTR:%.*]] to i8 addrspace(5)*
+// CHECK-NEXT:[[S3_SROA_0_SROA_0_0_S3_SROA_0_0__SROA_CAST2_SROA_CAST:%.*]] 
= bitcast [[STRUCT_STRUCTTY3]] addrspace(5)* [[PTR]] to <32 x i8> addrspace(5)*
+// CHECK-NEXT:store <32 x i8> zeroinitializer, <32 x i8> addrspace(5)* 
[[S3_SROA_0_SROA_0_0_S3_SROA_0_0__SROA_CAST2_SROA_CAST]], align 8, !tbaa.struct 
!9
+// CHECK-NEXT:[[S3_SROA_4_0__SROA_IDX6:%.*]] = getelementptr inbounds 
[[STRUCT_STRUCTTY3]], [[STRUCT_STRUCTTY3]] addrspace(5)* [[PTR]], i32 0, i32 4
+// CHECK-NEXT:store i8 addrspace(5)* addrspacecast (i8* null to i8 
addrspace(5)*), i8 addrspace(5)* addrspace(5)* [[S3_SROA_4_0__SROA_IDX6]], 
align 8, !tbaa.struct !12
+// CHECK-NEXT:[[S3_SROA_5_0__SROA_IDX:%.*]] = getelementptr inbounds i8, 
i8 addrspace(5)* [[TMP0]], i32 36
+// CHECK-NEXT:

Re: [clang] 91b5d50 - Revert "[clang-format] Link the braces of a block in UnwrappedLineParser"

2022-12-10 Thread Roman Lebedev via cfe-commits
Reminder to please always mention the reason for the revert in the
commit message.

On Sat, Dec 10, 2022 at 1:32 PM Owen Pan via cfe-commits
 wrote:
>
>
> Author: Owen Pan
> Date: 2022-12-10T02:31:53-08:00
> New Revision: 91b5d508e350a26028b7fc1397f21334e49dda5d
>
> URL: 
> https://github.com/llvm/llvm-project/commit/91b5d508e350a26028b7fc1397f21334e49dda5d
> DIFF: 
> https://github.com/llvm/llvm-project/commit/91b5d508e350a26028b7fc1397f21334e49dda5d.diff
>
> LOG: Revert "[clang-format] Link the braces of a block in UnwrappedLineParser"
>
> This reverts commit e33243c950ac40d027ad8facbf7ccf0624604a16 but
> keeps the added test case and also adds another test case.
>
> Fixes #59417.
>
> Differential Revision: https://reviews.llvm.org/D139760
>
> Added:
>
>
> Modified:
> clang/lib/Format/UnwrappedLineParser.cpp
> clang/unittests/Format/BracesRemoverTest.cpp
>
> Removed:
>
>
>
> 
> diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
> b/clang/lib/Format/UnwrappedLineParser.cpp
> index df8cff6748b17..3be4ef7ca6a1a 100644
> --- a/clang/lib/Format/UnwrappedLineParser.cpp
> +++ b/clang/lib/Format/UnwrappedLineParser.cpp
> @@ -934,9 +934,6 @@ FormatToken *UnwrappedLineParser::parseBlock(
>  return IfLBrace;
>}
>
> -  Tok->MatchingParen = FormatTok;
> -  FormatTok->MatchingParen = Tok;
> -
>const bool IsFunctionRBrace =
>FormatTok->is(tok::r_brace) && Tok->is(TT_FunctionLBrace);
>
> @@ -970,7 +967,10 @@ FormatToken *UnwrappedLineParser::parseBlock(
>  }
>  return mightFitOnOneLine((*CurrentLines)[Index], Tok);
>};
> -  Tok->Optional = RemoveBraces();
> +  if (RemoveBraces()) {
> +Tok->MatchingParen = FormatTok;
> +FormatTok->MatchingParen = Tok;
> +  }
>
>size_t PPEndHash = computePPHash();
>
> @@ -2707,20 +2707,10 @@ static void markOptionalBraces(FormatToken 
> *LeftBrace) {
>
>assert(RightBrace->is(tok::r_brace));
>assert(RightBrace->MatchingParen == LeftBrace);
> +  assert(LeftBrace->Optional == RightBrace->Optional);
>
> -  RightBrace->Optional = LeftBrace->Optional;
> -}
> -
> -static void resetOptional(FormatToken *LeftBrace) {
> -  if (!LeftBrace)
> -return;
> -
> -  const auto *RightBrace = LeftBrace->MatchingParen;
> -  const bool IsOptionalRightBrace = RightBrace && RightBrace->Optional;
> -  assert(LeftBrace->Optional || !IsOptionalRightBrace);
> -
> -  if (!IsOptionalRightBrace)
> -LeftBrace->Optional = false;
> +  LeftBrace->Optional = true;
> +  RightBrace->Optional = true;
>  }
>
>  void UnwrappedLineParser::handleAttributes() {
> @@ -2788,7 +2778,8 @@ FormatToken 
> *UnwrappedLineParser::parseIfThenElse(IfStmtKind *IfKind,
>
>if (Style.RemoveBracesLLVM) {
>  assert(!NestedTooDeep.empty());
> -KeepIfBraces = KeepIfBraces || (IfLeftBrace && !IfLeftBrace->Optional) ||
> +KeepIfBraces = KeepIfBraces ||
> +   (IfLeftBrace && !IfLeftBrace->MatchingParen) ||
> NestedTooDeep.back() || IfBlockKind == IfStmtKind::IfOnly 
> ||
> IfBlockKind == IfStmtKind::IfElseIf;
>}
> @@ -2819,9 +2810,8 @@ FormatToken 
> *UnwrappedLineParser::parseIfThenElse(IfStmtKind *IfKind,
>   ElseBlockKind == IfStmtKind::IfElseIf;
>} else if (FollowedByIf && IfLBrace && !IfLBrace->Optional) {
>  KeepElseBraces = true;
> -assert(ElseLeftBrace->Optional);
>  assert(ElseLeftBrace->MatchingParen);
> -ElseLeftBrace->MatchingParen->Optional = true;
> +markOptionalBraces(ElseLeftBrace);
>}
>addUnwrappedLine();
>  } else if (FormatTok->is(tok::kw_if)) {
> @@ -2856,7 +2846,7 @@ FormatToken 
> *UnwrappedLineParser::parseIfThenElse(IfStmtKind *IfKind,
>
>assert(!NestedTooDeep.empty());
>KeepElseBraces = KeepElseBraces ||
> -   (ElseLeftBrace && !ElseLeftBrace->Optional) ||
> +   (ElseLeftBrace && !ElseLeftBrace->MatchingParen) ||
> NestedTooDeep.back();
>
>NestedTooDeep.pop_back();
> @@ -2864,11 +2854,17 @@ FormatToken 
> *UnwrappedLineParser::parseIfThenElse(IfStmtKind *IfKind,
>if (!KeepIfBraces && !KeepElseBraces) {
>  markOptionalBraces(IfLeftBrace);
>  markOptionalBraces(ElseLeftBrace);
> +  } else if (IfLeftBrace) {
> +FormatToken *IfRightBrace = IfLeftBrace->MatchingParen;
> +if (IfRightBrace) {
> +  assert(IfRightBrace->MatchingParen == IfLeftBrace);
> +  assert(!IfLeftBrace->Optional);
> +  assert(!IfRightBrace->Optional);
> +  IfLeftBrace->MatchingParen = nullptr;
> +  IfRightBrace->MatchingParen = nullptr;
> +}
>}
>
> -  resetOptional(IfLeftBrace);
> -  resetOptional(ElseLeftBrace);
> -
>if (IfKind)
>  *IfKind = Kind;
>
> @@ -3083,7 +3079,6 @@ void UnwrappedLineParser::parseLoopBody(bool 
> KeepBraces, bool WrapRightBrace) {
>if (!NestedTooDeep.back())
>  markOptionalBraces(LeftBrace);

Re: [clang] e0fd86d - Revert "[OpenMP] Clang Support for taskwait nowait clause"

2022-12-09 Thread Roman Lebedev via cfe-commits
Reminder to please always mention the reason for the revert in the
commit message.

On Fri, Dec 9, 2022 at 8:07 PM Chi Chun Chen via cfe-commits
 wrote:
>
>
> Author: Chi Chun Chen
> Date: 2022-12-09T11:06:45-06:00
> New Revision: e0fd86db09a87f25df0eff6c1c755d86434dea0b
>
> URL: 
> https://github.com/llvm/llvm-project/commit/e0fd86db09a87f25df0eff6c1c755d86434dea0b
> DIFF: 
> https://github.com/llvm/llvm-project/commit/e0fd86db09a87f25df0eff6c1c755d86434dea0b.diff
>
> LOG: Revert "[OpenMP] Clang Support for taskwait nowait clause"
>
> This reverts commit 100dfe7a8ad3789a98df623482b88d9a3a02e176.
>
> Added:
>
>
> Modified:
> clang/lib/CodeGen/CGOpenMPRuntime.cpp
> clang/lib/CodeGen/CGOpenMPRuntime.h
> clang/lib/CodeGen/CGStmtOpenMP.cpp
> clang/test/OpenMP/target_depend_codegen.cpp
> clang/test/OpenMP/target_enter_data_depend_codegen.cpp
> clang/test/OpenMP/target_exit_data_depend_codegen.cpp
> clang/test/OpenMP/target_parallel_depend_codegen.cpp
> clang/test/OpenMP/target_parallel_for_depend_codegen.cpp
> clang/test/OpenMP/target_parallel_for_simd_depend_codegen.cpp
> clang/test/OpenMP/target_simd_depend_codegen.cpp
> clang/test/OpenMP/target_teams_depend_codegen.cpp
> clang/test/OpenMP/target_teams_distribute_depend_codegen.cpp
> clang/test/OpenMP/target_teams_distribute_parallel_for_depend_codegen.cpp
> 
> clang/test/OpenMP/target_teams_distribute_parallel_for_simd_depend_codegen.cpp
> clang/test/OpenMP/target_teams_distribute_simd_depend_codegen.cpp
> clang/test/OpenMP/target_update_depend_codegen.cpp
> clang/test/OpenMP/task_codegen.cpp
> clang/test/OpenMP/task_if_codegen.cpp
> clang/test/OpenMP/taskwait_ast_print.cpp
> clang/test/OpenMP/taskwait_codegen.cpp
> clang/test/OpenMP/taskwait_depend_codegen.cpp
> llvm/include/llvm/Frontend/OpenMP/OMP.td
> llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
> llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
> llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
> mlir/test/Target/LLVMIR/openmp-llvm.mlir
> openmp/runtime/src/dllexports
> openmp/runtime/src/kmp.h
> openmp/runtime/src/kmp_taskdeps.cpp
> openmp/runtime/src/kmp_tasking.cpp
>
> Removed:
> clang/test/OpenMP/taskwait_depend_nowait_codegen.cpp
> clang/test/OpenMP/taskwait_nowait_codegen.cpp
>
>
> 
> diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
> b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
> index 396075183102d..a75e31f40e074 100644
> --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
> +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
> @@ -4756,7 +4756,7 @@ void CGOpenMPRuntime::emitTaskCall(CodeGenFunction 
> , SourceLocation Loc,
>Region->emitUntiedSwitch(CGF);
>};
>
> -  llvm::Value *DepWaitTaskArgs[7];
> +  llvm::Value *DepWaitTaskArgs[6];
>if (!Data.Dependences.empty()) {
>  DepWaitTaskArgs[0] = UpLoc;
>  DepWaitTaskArgs[1] = ThreadID;
> @@ -4764,8 +4764,6 @@ void CGOpenMPRuntime::emitTaskCall(CodeGenFunction 
> , SourceLocation Loc,
>  DepWaitTaskArgs[3] = DependenciesArray.getPointer();
>  DepWaitTaskArgs[4] = CGF.Builder.getInt32(0);
>  DepWaitTaskArgs[5] = llvm::ConstantPointerNull::get(CGF.VoidPtrTy);
> -DepWaitTaskArgs[6] =
> -llvm::ConstantInt::get(CGF.Int32Ty, Data.HasNowaitClause);
>}
>auto  = CGM.getModule();
>auto & = [this, , , ThreadID, NewTaskNewTaskTTy,
> @@ -4777,9 +4775,9 @@ void CGOpenMPRuntime::emitTaskCall(CodeGenFunction 
> , SourceLocation Loc,
>  // ndeps_noalias, kmp_depend_info_t *noalias_dep_list); if dependence 
> info
>  // is specified.
>  if (!Data.Dependences.empty())
> -  CGF.EmitRuntimeCall(OMPBuilder.getOrCreateRuntimeFunction(
> -  M, OMPRTL___kmpc_omp_taskwait_deps_51),
> -  DepWaitTaskArgs);
> +  CGF.EmitRuntimeCall(
> +  OMPBuilder.getOrCreateRuntimeFunction(M, 
> OMPRTL___kmpc_omp_wait_deps),
> +  DepWaitTaskArgs);
>  // Call proxy_task_entry(gtid, new_task);
>  auto & = [TaskEntry, ThreadID, NewTaskNewTaskTTy,
>Loc](CodeGenFunction , PrePostActionTy ) {
> @@ -5818,7 +5816,7 @@ void CGOpenMPRuntime::emitTaskwaitCall(CodeGenFunction 
> , SourceLocation Loc,
>
>if (CGF.CGM.getLangOpts().OpenMPIRBuilder && Data.Dependences.empty()) {
>  // TODO: Need to support taskwait with dependences in the 
> OpenMPIRBuilder.
> -OMPBuilder.createTaskwait(CGF.Builder, Data.HasNowaitClause);
> +OMPBuilder.createTaskwait(CGF.Builder);
>} else {
>  llvm::Value *ThreadID = getThreadID(CGF, Loc);
>  llvm::Value *UpLoc = emitUpdateLocation(CGF, Loc);
> @@ -5827,38 +5825,34 @@ void 
> CGOpenMPRuntime::emitTaskwaitCall(CodeGenFunction , SourceLocation Loc,
>  llvm::Value *NumOfElements;
>  std::tie(NumOfElements, DependenciesArray) =
>  emitDependClause(CGF, Data.Dependences, Loc);

Re: [clang] d881fdf - Revert "Recommit of 8ae18303f97d5dcfaecc90b4d87effb2011ed82e - part 2"

2022-12-09 Thread Roman Lebedev via cfe-commits
Also, when recommiting these patches, please fix the commit message,
the current one is very non-descriptive.

On Fri, Dec 9, 2022 at 12:15 PM via cfe-commits
 wrote:
>
>
> Author: serge-sans-paille
> Date: 2022-12-09T10:15:41+01:00
> New Revision: d881fdf72047fd18b88c6a65d0966cad542c95cd
>
> URL: 
> https://github.com/llvm/llvm-project/commit/d881fdf72047fd18b88c6a65d0966cad542c95cd
> DIFF: 
> https://github.com/llvm/llvm-project/commit/d881fdf72047fd18b88c6a65d0966cad542c95cd.diff
>
> LOG: Revert "Recommit of 8ae18303f97d5dcfaecc90b4d87effb2011ed82e - part 2"
>
> This reverts commit 4faf6cf989f3ae212912994022c0486a2dc4.
>
> Added:
>
>
> Modified:
> clang/lib/Driver/ToolChains/Gnu.cpp
> lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
> llvm/include/llvm/Option/OptTable.h
> llvm/lib/Option/OptTable.cpp
> llvm/unittests/Option/OptionMarshallingTest.cpp
> llvm/utils/TableGen/OptParserEmitter.cpp
>
> Removed:
>
>
>
> 
> diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
> b/clang/lib/Driver/ToolChains/Gnu.cpp
> index 60d62e2b9c5c1..4621850f13772 100644
> --- a/clang/lib/Driver/ToolChains/Gnu.cpp
> +++ b/clang/lib/Driver/ToolChains/Gnu.cpp
> @@ -331,8 +331,8 @@ static bool getStaticPIE(const ArgList , const 
> ToolChain ) {
>if (HasStaticPIE && Args.hasArg(options::OPT_nopie)) {
>  const Driver  = TC.getDriver();
>  const llvm::opt::OptTable  = D.getOpts();
> -StringRef StaticPIEName = Opts.getOptionName(options::OPT_static_pie);
> -StringRef NoPIEName = Opts.getOptionName(options::OPT_nopie);
> +const char *StaticPIEName = Opts.getOptionName(options::OPT_static_pie);
> +const char *NoPIEName = Opts.getOptionName(options::OPT_nopie);
>  D.Diag(diag::err_drv_cannot_mix_options) << StaticPIEName << NoPIEName;
>}
>return HasStaticPIE;
>
> diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp 
> b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
> index fde098840be4b..9d89148616be1 100644
> --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
> +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
> @@ -1055,7 +1055,7 @@ void 
> PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(
>// Only add the version-min options if we got a version from somewhere
>if (!version.empty() && sdk_type != XcodeSDK::Type::Linux) {
>  #define OPTION(PREFIX, NAME, VAR, ...)   
>   \
> -  llvm::StringRef opt_##VAR = NAME;  
>   \
> +  const char *opt_##VAR = NAME;  
>   \
>(void)opt_##VAR;
>  #include "clang/Driver/Options.inc"
>  #undef OPTION
>
> diff  --git a/llvm/include/llvm/Option/OptTable.h 
> b/llvm/include/llvm/Option/OptTable.h
> index 390462d762e61..07d9870f71b33 100644
> --- a/llvm/include/llvm/Option/OptTable.h
> +++ b/llvm/include/llvm/Option/OptTable.h
> @@ -102,7 +102,9 @@ class OptTable {
>const Option getOption(OptSpecifier Opt) const;
>
>/// Lookup the name of the given option.
> -  StringRef getOptionName(OptSpecifier id) const { return getInfo(id).Name; }
> +  const char *getOptionName(OptSpecifier id) const {
> +return getInfo(id).Name;
> +  }
>
>/// Get the kind of the given option.
>unsigned getOptionKind(OptSpecifier id) const {
>
> diff  --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp
> index f4426bc34b3f9..ef4873eb7f9c4 100644
> --- a/llvm/lib/Option/OptTable.cpp
> +++ b/llvm/lib/Option/OptTable.cpp
> @@ -36,10 +36,16 @@ namespace opt {
>  // Ordering on Info. The ordering is *almost* case-insensitive lexicographic,
>  // with an exception. '\0' comes at the end of the alphabet instead of the
>  // beginning (thus options precede any other options which prefix them).
> -static int StrCmpOptionNameIgnoreCase(StringRef A, StringRef B) {
> -  size_t MinSize = std::min(A.size(), B.size());
> -  if (int Res = A.substr(0, MinSize).compare_insensitive(B.substr(0, 
> MinSize)))
> -return Res;
> +static int StrCmpOptionNameIgnoreCase(const char *A, const char *B) {
> +  const char *X = A, *Y = B;
> +  char a = tolower(*A), b = tolower(*B);
> +  while (a == b) {
> +if (a == '\0')
> +  return 0;
> +
> +a = tolower(*++X);
> +b = tolower(*++Y);
> +  }
>
>if (a == '\0') // A is a prefix of B.
>  return 1;
> @@ -54,7 +60,7 @@ static int StrCmpOptionNameIgnoreCase(StringRef A, 
> StringRef B) {
>  static int StrCmpOptionName(const char *A, const char *B) {
>if (int N = StrCmpOptionNameIgnoreCase(A, B))
>  return N;
> -  return A.compare(B);
> +  return strcmp(A, B);
>  }
>
>  static inline bool operator<(const OptTable::Info , const OptTable::Info 
> ) {
> @@ -180,7 +186,7 @@ static unsigned matchOption(const OptTable::Info *I, 
> StringRef Str,
>bool Matched = IgnoreCase ? Rest.startswith_insensitive(I->Name)
>   

Re: [clang] d881fdf - Revert "Recommit of 8ae18303f97d5dcfaecc90b4d87effb2011ed82e - part 2"

2022-12-09 Thread Roman Lebedev via cfe-commits
Reminder to please always mention the reason for the revert in the
commit message.

On Fri, Dec 9, 2022 at 12:15 PM via cfe-commits
 wrote:
>
>
> Author: serge-sans-paille
> Date: 2022-12-09T10:15:41+01:00
> New Revision: d881fdf72047fd18b88c6a65d0966cad542c95cd
>
> URL: 
> https://github.com/llvm/llvm-project/commit/d881fdf72047fd18b88c6a65d0966cad542c95cd
> DIFF: 
> https://github.com/llvm/llvm-project/commit/d881fdf72047fd18b88c6a65d0966cad542c95cd.diff
>
> LOG: Revert "Recommit of 8ae18303f97d5dcfaecc90b4d87effb2011ed82e - part 2"
>
> This reverts commit 4faf6cf989f3ae212912994022c0486a2dc4.
>
> Added:
>
>
> Modified:
> clang/lib/Driver/ToolChains/Gnu.cpp
> lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
> llvm/include/llvm/Option/OptTable.h
> llvm/lib/Option/OptTable.cpp
> llvm/unittests/Option/OptionMarshallingTest.cpp
> llvm/utils/TableGen/OptParserEmitter.cpp
>
> Removed:
>
>
>
> 
> diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
> b/clang/lib/Driver/ToolChains/Gnu.cpp
> index 60d62e2b9c5c1..4621850f13772 100644
> --- a/clang/lib/Driver/ToolChains/Gnu.cpp
> +++ b/clang/lib/Driver/ToolChains/Gnu.cpp
> @@ -331,8 +331,8 @@ static bool getStaticPIE(const ArgList , const 
> ToolChain ) {
>if (HasStaticPIE && Args.hasArg(options::OPT_nopie)) {
>  const Driver  = TC.getDriver();
>  const llvm::opt::OptTable  = D.getOpts();
> -StringRef StaticPIEName = Opts.getOptionName(options::OPT_static_pie);
> -StringRef NoPIEName = Opts.getOptionName(options::OPT_nopie);
> +const char *StaticPIEName = Opts.getOptionName(options::OPT_static_pie);
> +const char *NoPIEName = Opts.getOptionName(options::OPT_nopie);
>  D.Diag(diag::err_drv_cannot_mix_options) << StaticPIEName << NoPIEName;
>}
>return HasStaticPIE;
>
> diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp 
> b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
> index fde098840be4b..9d89148616be1 100644
> --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
> +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
> @@ -1055,7 +1055,7 @@ void 
> PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(
>// Only add the version-min options if we got a version from somewhere
>if (!version.empty() && sdk_type != XcodeSDK::Type::Linux) {
>  #define OPTION(PREFIX, NAME, VAR, ...)   
>   \
> -  llvm::StringRef opt_##VAR = NAME;  
>   \
> +  const char *opt_##VAR = NAME;  
>   \
>(void)opt_##VAR;
>  #include "clang/Driver/Options.inc"
>  #undef OPTION
>
> diff  --git a/llvm/include/llvm/Option/OptTable.h 
> b/llvm/include/llvm/Option/OptTable.h
> index 390462d762e61..07d9870f71b33 100644
> --- a/llvm/include/llvm/Option/OptTable.h
> +++ b/llvm/include/llvm/Option/OptTable.h
> @@ -102,7 +102,9 @@ class OptTable {
>const Option getOption(OptSpecifier Opt) const;
>
>/// Lookup the name of the given option.
> -  StringRef getOptionName(OptSpecifier id) const { return getInfo(id).Name; }
> +  const char *getOptionName(OptSpecifier id) const {
> +return getInfo(id).Name;
> +  }
>
>/// Get the kind of the given option.
>unsigned getOptionKind(OptSpecifier id) const {
>
> diff  --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp
> index f4426bc34b3f9..ef4873eb7f9c4 100644
> --- a/llvm/lib/Option/OptTable.cpp
> +++ b/llvm/lib/Option/OptTable.cpp
> @@ -36,10 +36,16 @@ namespace opt {
>  // Ordering on Info. The ordering is *almost* case-insensitive lexicographic,
>  // with an exception. '\0' comes at the end of the alphabet instead of the
>  // beginning (thus options precede any other options which prefix them).
> -static int StrCmpOptionNameIgnoreCase(StringRef A, StringRef B) {
> -  size_t MinSize = std::min(A.size(), B.size());
> -  if (int Res = A.substr(0, MinSize).compare_insensitive(B.substr(0, 
> MinSize)))
> -return Res;
> +static int StrCmpOptionNameIgnoreCase(const char *A, const char *B) {
> +  const char *X = A, *Y = B;
> +  char a = tolower(*A), b = tolower(*B);
> +  while (a == b) {
> +if (a == '\0')
> +  return 0;
> +
> +a = tolower(*++X);
> +b = tolower(*++Y);
> +  }
>
>if (a == '\0') // A is a prefix of B.
>  return 1;
> @@ -54,7 +60,7 @@ static int StrCmpOptionNameIgnoreCase(StringRef A, 
> StringRef B) {
>  static int StrCmpOptionName(const char *A, const char *B) {
>if (int N = StrCmpOptionNameIgnoreCase(A, B))
>  return N;
> -  return A.compare(B);
> +  return strcmp(A, B);
>  }
>
>  static inline bool operator<(const OptTable::Info , const OptTable::Info 
> ) {
> @@ -180,7 +186,7 @@ static unsigned matchOption(const OptTable::Info *I, 
> StringRef Str,
>bool Matched = IgnoreCase ? Rest.startswith_insensitive(I->Name)
>  

Re: [clang] 7925e28 - Revert "[AArch64] Add __ARM_FEATURE_BTI and __ARM_FEATURE_PAUTH"

2022-12-07 Thread Roman Lebedev via cfe-commits
Reminder to please always mention the reason for the revert in the
commit message.

On Wed, Dec 7, 2022 at 5:20 PM Daniel Kiss via cfe-commits
 wrote:
>
>
> Author: Daniel Kiss
> Date: 2022-12-07T15:19:31+01:00
> New Revision: 7925e2828e3290f2851f29aec66c882597f8bc61
>
> URL: 
> https://github.com/llvm/llvm-project/commit/7925e2828e3290f2851f29aec66c882597f8bc61
> DIFF: 
> https://github.com/llvm/llvm-project/commit/7925e2828e3290f2851f29aec66c882597f8bc61.diff
>
> LOG: Revert "[AArch64] Add __ARM_FEATURE_BTI and __ARM_FEATURE_PAUTH"
>
> This reverts commit cfd44221e3e1783c0f44d5b1694dfbe84187246a.
>
> Added:
>
>
> Modified:
> clang/lib/Basic/Targets/AArch64.cpp
> clang/test/Preprocessor/aarch64-target-features.c
>
> Removed:
>
>
>
> 
> diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
> b/clang/lib/Basic/Targets/AArch64.cpp
> index 1abe646f88bfd..c5fce62bc501f 100644
> --- a/clang/lib/Basic/Targets/AArch64.cpp
> +++ b/clang/lib/Basic/Targets/AArch64.cpp
> @@ -199,7 +199,6 @@ void AArch64TargetInfo::getTargetDefinesARMV83A(const 
> LangOptions ,
>  MacroBuilder ) const 
> {
>Builder.defineMacro("__ARM_FEATURE_COMPLEX", "1");
>Builder.defineMacro("__ARM_FEATURE_JCVT", "1");
> -  Builder.defineMacro("__ARM_FEATURE_PAUTH", "1");
>// Also include the Armv8.2 defines
>getTargetDefinesARMV82A(Opts, Builder);
>  }
> @@ -213,7 +212,6 @@ void AArch64TargetInfo::getTargetDefinesARMV84A(const 
> LangOptions ,
>  void AArch64TargetInfo::getTargetDefinesARMV85A(const LangOptions ,
>  MacroBuilder ) const 
> {
>Builder.defineMacro("__ARM_FEATURE_FRINT", "1");
> -  Builder.defineMacro("__ARM_FEATURE_BTI", "1");
>// Also include the Armv8.4 defines
>getTargetDefinesARMV84A(Opts, Builder);
>  }
> @@ -387,9 +385,6 @@ void AArch64TargetInfo::getTargetDefines(const 
> LangOptions ,
>  Builder.defineMacro("__ARM_FEATURE_SM4", "1");
>}
>
> -  if (HasPAuth)
> -Builder.defineMacro("__ARM_FEATURE_PAUTH", "1");
> -
>if (HasUnaligned)
>  Builder.defineMacro("__ARM_FEATURE_UNALIGNED", "1");
>
>
> diff  --git a/clang/test/Preprocessor/aarch64-target-features.c 
> b/clang/test/Preprocessor/aarch64-target-features.c
> index 53b6644ef12e6..40ea003a85848 100644
> --- a/clang/test/Preprocessor/aarch64-target-features.c
> +++ b/clang/test/Preprocessor/aarch64-target-features.c
> @@ -461,7 +461,6 @@
>  // == Check Pointer Authentication Extension (PAuth).
>  // RUN: %clang -target arm64-none-linux-gnu -march=armv8-a -x c -E -dM %s -o 
> - | FileCheck -check-prefix=CHECK-PAUTH-OFF %s
>  // RUN: %clang -target arm64-none-linux-gnu -march=armv8.5-a -x c -E -dM %s 
> -o - | FileCheck -check-prefix=CHECK-PAUTH-OFF %s
> -// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a+pauth 
> -mbranch-protection=none -x c -E -dM %s -o - | FileCheck 
> -check-prefix=CHECK-PAUTH-ON %s
>  // RUN: %clang -target arm64-none-linux-gnu -march=armv8-a 
> -mbranch-protection=none -x c -E -dM %s -o - | FileCheck 
> -check-prefix=CHECK-PAUTH-OFF %s
>  // RUN: %clang -target arm64-none-linux-gnu -march=armv8-a 
> -mbranch-protection=bti -x c -E -dM %s -o - | FileCheck 
> -check-prefix=CHECK-PAUTH-OFF %s
>  // RUN: %clang -target arm64-none-linux-gnu -march=armv8-a 
> -mbranch-protection=standard -x c -E -dM %s -o - | FileCheck 
> -check-prefix=CHECK-PAUTH %s
> @@ -474,7 +473,6 @@
>  // CHECK-PAUTH-BKEY: #define __ARM_FEATURE_PAC_DEFAULT 2
>  // CHECK-PAUTH-ALL:  #define __ARM_FEATURE_PAC_DEFAULT 5
>  // CHECK-PAUTH-BKEY-ALL: #define __ARM_FEATURE_PAC_DEFAULT 6
> -// CHECK-PAUTH-ON:   #define __ARM_FEATURE_PAUTH 1
>
>  // == Check Branch Target Identification (BTI).
>  // RUN: %clang -target arm64-none-linux-gnu -march=armv8-a -x c -E -dM %s -o 
> - | FileCheck -check-prefix=CHECK-BTI-OFF %s
> @@ -562,12 +560,10 @@
>  // RUN: %clang -target aarch64-arm-none-eabi -march=armv9.2-a -x c -E -dM %s 
> -o - | FileCheck 
> --check-prefixes=CHECK-V81-OR-LATER,CHECK-V83-OR-LATER,CHECK-V85-OR-LATER %s
>  // RUN: %clang -target aarch64-arm-none-eabi -march=armv9.3-a -x c -E -dM %s 
> -o - | FileCheck 
> --check-prefixes=CHECK-V81-OR-LATER,CHECK-V83-OR-LATER,CHECK-V85-OR-LATER %s
>  // CHECK-V81-OR-LATER: __ARM_FEATURE_ATOMICS 1
> -// CHECK-V85-OR-LATER: __ARM_FEATURE_BTI 1
>  // CHECK-V83-OR-LATER: __ARM_FEATURE_COMPLEX 1
>  // CHECK-V81-OR-LATER: __ARM_FEATURE_CRC32 1
>  // CHECK-V85-OR-LATER: __ARM_FEATURE_FRINT 1
>  // CHECK-V83-OR-LATER: __ARM_FEATURE_JCVT 1
> -// CHECK-V83-OR-LATER: __ARM_FEATURE_PAUTH 1
>  // CHECK-V81-OR-LATER: __ARM_FEATURE_QRDMX 1
>  // CHECK-BEFORE-V83-NOT: __ARM_FEATURE_COMPLEX 1
>  // CHECK-BEFORE-V83-NOT: __ARM_FEATURE_JCVT 1
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> 

[clang] 25f01d5 - Revert "[SROA] `isVectorPromotionViable()`: memory intrinsics operate on vectors of bytes (take 2)"

2022-11-26 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2022-11-27T00:00:06+03:00
New Revision: 25f01d593ce296078f57e872778b77d074ae5888

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

LOG: Revert "[SROA] `isVectorPromotionViable()`: memory intrinsics operate on 
vectors of bytes (take 2)"

TableGen is still getting miscompiled on PPC buildbots.
Sent a mail with request for help.

This reverts commit 3c4d2a03968ccf5889bacffe02d6fa2443b0260f.

Added: 


Modified: 
clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
llvm/lib/Transforms/Scalar/SROA.cpp
llvm/test/CodeGen/AMDGPU/v1024.ll
llvm/test/DebugInfo/X86/sroasplit-1.ll
llvm/test/DebugInfo/X86/sroasplit-4.ll
llvm/test/Transforms/PhaseOrdering/instcombine-sroa-inttoptr.ll
llvm/test/Transforms/SROA/address-spaces.ll
llvm/test/Transforms/SROA/alignment.ll
llvm/test/Transforms/SROA/alloca-address-space.ll
llvm/test/Transforms/SROA/basictest.ll
llvm/test/Transforms/SROA/pointer-offset-size.ll
llvm/test/Transforms/SROA/slice-width.ll
llvm/test/Transforms/SROA/tbaa-struct.ll
llvm/test/Transforms/SROA/tbaa-struct2.ll
llvm/test/Transforms/SROA/vector-promotion.ll

Removed: 




diff  --git a/clang/test/CodeGenOpenCL/amdgpu-nullptr.cl 
b/clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
index 859e81f08d6bd..65f6f2e7d8c24 100644
--- a/clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
+++ b/clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
@@ -515,17 +515,13 @@ typedef struct {
   private char *p;
 } StructTy3;
 
-// CHECK-LABEL: @test_memset_private(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = bitcast [[STRUCT_STRUCTTY3:%.*]] 
addrspace(5)* [[PTR:%.*]] to i8 addrspace(5)*
-// CHECK-NEXT:[[S3_SROA_0_SROA_0_0_S3_SROA_0_0__SROA_CAST2_SROA_CAST:%.*]] 
= bitcast [[STRUCT_STRUCTTY3]] addrspace(5)* [[PTR]] to <32 x i8> addrspace(5)*
-// CHECK-NEXT:store <32 x i8> zeroinitializer, <32 x i8> addrspace(5)* 
[[S3_SROA_0_SROA_0_0_S3_SROA_0_0__SROA_CAST2_SROA_CAST]], align 8, !tbaa.struct 
!9
-// CHECK-NEXT:[[S3_SROA_4_0__SROA_IDX6:%.*]] = getelementptr inbounds 
[[STRUCT_STRUCTTY3]], [[STRUCT_STRUCTTY3]] addrspace(5)* [[PTR]], i32 0, i32 4
-// CHECK-NEXT:store i8 addrspace(5)* addrspacecast (i8* null to i8 
addrspace(5)*), i8 addrspace(5)* addrspace(5)* [[S3_SROA_4_0__SROA_IDX6]], 
align 8, !tbaa.struct !12
-// CHECK-NEXT:[[S3_SROA_5_0__SROA_IDX:%.*]] = getelementptr inbounds i8, 
i8 addrspace(5)* [[TMP0]], i32 36
-// CHECK-NEXT:[[S3_SROA_5_0__SROA_CAST8:%.*]] = bitcast i8 addrspace(5)* 
[[S3_SROA_5_0__SROA_IDX]] to i32 addrspace(5)*
-// CHECK-NEXT:store i32 0, i32 addrspace(5)* [[S3_SROA_5_0__SROA_CAST8]], 
align 4, !tbaa.struct !13
-// CHECK-NEXT:ret void
+// CHECK-LABEL: test_memset_private
+// CHECK: call void @llvm.memset.p5i8.i64(i8 addrspace(5)* noundef align 8 
{{.*}}, i8 0, i64 32, i1 false)
+// CHECK: [[GEP:%.*]] = getelementptr inbounds %struct.StructTy3, 
%struct.StructTy3 addrspace(5)* %ptr, i32 0, i32 4
+// CHECK: store i8 addrspace(5)* addrspacecast (i8* null to i8 addrspace(5)*), 
i8 addrspace(5)* addrspace(5)* [[GEP]]
+// CHECK: [[GEP1:%.*]] = getelementptr inbounds i8, i8 addrspace(5)* {{.*}}, 
i32 36
+// CHECK: [[GEP1_CAST:%.*]] = bitcast i8 addrspace(5)* [[GEP1]] to i32 
addrspace(5)*
+// CHECK: store i32 0, i32 addrspace(5)* [[GEP1_CAST]], align 4
 void test_memset_private(private StructTy3 *ptr) {
   StructTy3 S3 = {0, 0, 0, 0, 0};
   *ptr = S3;

diff  --git a/llvm/lib/Transforms/Scalar/SROA.cpp 
b/llvm/lib/Transforms/Scalar/SROA.cpp
index a2d7dc234333f..6dcdd630b6bae 100644
--- a/llvm/lib/Transforms/Scalar/SROA.cpp
+++ b/llvm/lib/Transforms/Scalar/SROA.cpp
@@ -1806,10 +1806,8 @@ static bool isVectorPromotionViableForSlice(Partition 
, const Slice ,
   ? Ty->getElementType()
   : FixedVectorType::get(Ty->getElementType(), 
NumElements);
 
-  Type *SplitIntTy = nullptr;
-  if (uint64_t Bitwidth = NumElements * ElementSize * 8;
-  Bitwidth <= IntegerType::MAX_INT_BITS)
-SplitIntTy = Type::getIntNTy(Ty->getContext(), Bitwidth);
+  Type *SplitIntTy =
+  Type::getIntNTy(Ty->getContext(), NumElements * ElementSize * 8);
 
   Use *U = S.getUse();
 
@@ -1828,8 +1826,7 @@ static bool isVectorPromotionViableForSlice(Partition , 
const Slice ,
 // Disable vector promotion when there are loads or stores of an FCA.
 if (LTy->isStructTy())
   return false;
-if (SplitIntTy &&
-(P.beginOffset() > S.beginOffset() || P.endOffset() < S.endOffset())) {
+if (P.beginOffset() > S.beginOffset() || P.endOffset() < S.endOffset()) {
   assert(LTy->isIntegerTy());
   LTy = SplitIntTy;
 }
@@ -1842,8 +1839,7 @@ static bool isVectorPromotionViableForSlice(Partition , 
const Slice ,
 // Disable vector promotion when 

[clang] 3c4d2a0 - [SROA] `isVectorPromotionViable()`: memory intrinsics operate on vectors of bytes (take 2)

2022-11-26 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2022-11-26T23:19:15+03:00
New Revision: 3c4d2a03968ccf5889bacffe02d6fa2443b0260f

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

LOG: [SROA] `isVectorPromotionViable()`: memory intrinsics operate on vectors 
of bytes (take 2)

This is a recommit of cf624b23bc5d5a6161706d1663def49380ff816a,
which was reverted in 5cfc22cafe3f2465e0bb324f8daba82ffcabd0df,
because the cut-off on the number of vector elements was not low enough,
and it triggered both SDAG SDNode operand number assertions,
and caused compile time explosions in some cases.

Let's try with something really *REALLY* conservative first,
just to get somewhere, and try to bump it (to 64/128) later.

FIXME: should this respect TTI reg width * num vec regs?

Original commit message:

Now, there's a big caveat here - these bytes
are abstract bytes, not the i8 we have in LLVM,
so strictly speaking this is not exactly legal,
see e.g. https://github.com/AliveToolkit/alive2/issues/860
^ the "bytes" "could" have been a pointer,
and loading it as an integer inserts an implicit ptrtoint.

But at the same time,
InstCombine's `InstCombinerImpl::SimplifyAnyMemTransfer()`
would expand a memtransfer of 1/2/4/8 bytes
into integer-typed load+store,
so this isn't exactly a new problem.

Note that in memory, poison is byte-wise,
so we really can't widen elements,
but SROA seems to be inconsistent here.

Fixes #59116.

Added: 


Modified: 
clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
llvm/lib/Transforms/Scalar/SROA.cpp
llvm/test/CodeGen/AMDGPU/v1024.ll
llvm/test/DebugInfo/X86/sroasplit-1.ll
llvm/test/DebugInfo/X86/sroasplit-4.ll
llvm/test/Transforms/PhaseOrdering/instcombine-sroa-inttoptr.ll
llvm/test/Transforms/SROA/address-spaces.ll
llvm/test/Transforms/SROA/alignment.ll
llvm/test/Transforms/SROA/alloca-address-space.ll
llvm/test/Transforms/SROA/basictest.ll
llvm/test/Transforms/SROA/pointer-offset-size.ll
llvm/test/Transforms/SROA/slice-width.ll
llvm/test/Transforms/SROA/tbaa-struct.ll
llvm/test/Transforms/SROA/tbaa-struct2.ll
llvm/test/Transforms/SROA/vector-promotion.ll

Removed: 




diff  --git a/clang/test/CodeGenOpenCL/amdgpu-nullptr.cl 
b/clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
index 65f6f2e7d8c24..859e81f08d6bd 100644
--- a/clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
+++ b/clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
@@ -515,13 +515,17 @@ typedef struct {
   private char *p;
 } StructTy3;
 
-// CHECK-LABEL: test_memset_private
-// CHECK: call void @llvm.memset.p5i8.i64(i8 addrspace(5)* noundef align 8 
{{.*}}, i8 0, i64 32, i1 false)
-// CHECK: [[GEP:%.*]] = getelementptr inbounds %struct.StructTy3, 
%struct.StructTy3 addrspace(5)* %ptr, i32 0, i32 4
-// CHECK: store i8 addrspace(5)* addrspacecast (i8* null to i8 addrspace(5)*), 
i8 addrspace(5)* addrspace(5)* [[GEP]]
-// CHECK: [[GEP1:%.*]] = getelementptr inbounds i8, i8 addrspace(5)* {{.*}}, 
i32 36
-// CHECK: [[GEP1_CAST:%.*]] = bitcast i8 addrspace(5)* [[GEP1]] to i32 
addrspace(5)*
-// CHECK: store i32 0, i32 addrspace(5)* [[GEP1_CAST]], align 4
+// CHECK-LABEL: @test_memset_private(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = bitcast [[STRUCT_STRUCTTY3:%.*]] 
addrspace(5)* [[PTR:%.*]] to i8 addrspace(5)*
+// CHECK-NEXT:[[S3_SROA_0_SROA_0_0_S3_SROA_0_0__SROA_CAST2_SROA_CAST:%.*]] 
= bitcast [[STRUCT_STRUCTTY3]] addrspace(5)* [[PTR]] to <32 x i8> addrspace(5)*
+// CHECK-NEXT:store <32 x i8> zeroinitializer, <32 x i8> addrspace(5)* 
[[S3_SROA_0_SROA_0_0_S3_SROA_0_0__SROA_CAST2_SROA_CAST]], align 8, !tbaa.struct 
!9
+// CHECK-NEXT:[[S3_SROA_4_0__SROA_IDX6:%.*]] = getelementptr inbounds 
[[STRUCT_STRUCTTY3]], [[STRUCT_STRUCTTY3]] addrspace(5)* [[PTR]], i32 0, i32 4
+// CHECK-NEXT:store i8 addrspace(5)* addrspacecast (i8* null to i8 
addrspace(5)*), i8 addrspace(5)* addrspace(5)* [[S3_SROA_4_0__SROA_IDX6]], 
align 8, !tbaa.struct !12
+// CHECK-NEXT:[[S3_SROA_5_0__SROA_IDX:%.*]] = getelementptr inbounds i8, 
i8 addrspace(5)* [[TMP0]], i32 36
+// CHECK-NEXT:[[S3_SROA_5_0__SROA_CAST8:%.*]] = bitcast i8 addrspace(5)* 
[[S3_SROA_5_0__SROA_IDX]] to i32 addrspace(5)*
+// CHECK-NEXT:store i32 0, i32 addrspace(5)* [[S3_SROA_5_0__SROA_CAST8]], 
align 4, !tbaa.struct !13
+// CHECK-NEXT:ret void
 void test_memset_private(private StructTy3 *ptr) {
   StructTy3 S3 = {0, 0, 0, 0, 0};
   *ptr = S3;

diff  --git a/llvm/lib/Transforms/Scalar/SROA.cpp 
b/llvm/lib/Transforms/Scalar/SROA.cpp
index 6dcdd630b6bae..a2d7dc234333f 100644
--- a/llvm/lib/Transforms/Scalar/SROA.cpp
+++ b/llvm/lib/Transforms/Scalar/SROA.cpp
@@ -1806,8 +1806,10 @@ static bool isVectorPromotionViableForSlice(Partition 
, const Slice ,
   ? Ty->getElementType()
 

Re: [clang] 5cfc22c - Revert "[SROA] `isVectorPromotionViable()`: memory intrinsics operate on vectors of bytes"

2022-11-23 Thread Roman Lebedev via cfe-commits
Thank you!

On Wed, Nov 23, 2022 at 3:11 PM Benjamin Kramer via cfe-commits
 wrote:
>
>
> Author: Benjamin Kramer
> Date: 2022-11-23T13:11:16+01:00
> New Revision: 5cfc22cafe3f2465e0bb324f8daba82ffcabd0df
>
> URL: 
> https://github.com/llvm/llvm-project/commit/5cfc22cafe3f2465e0bb324f8daba82ffcabd0df
> DIFF: 
> https://github.com/llvm/llvm-project/commit/5cfc22cafe3f2465e0bb324f8daba82ffcabd0df.diff
>
> LOG: Revert "[SROA] `isVectorPromotionViable()`: memory intrinsics operate on 
> vectors of bytes"
>
> This reverts commit cf624b23bc5d5a6161706d1663def49380ff816a. It
> triggers crashes in clang, see the comments on github on the original
> change.
>
> Added:
>
>
> Modified:
> clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
> llvm/lib/Transforms/Scalar/SROA.cpp
> llvm/test/CodeGen/AMDGPU/v1024.ll
> llvm/test/DebugInfo/X86/sroasplit-1.ll
> llvm/test/DebugInfo/X86/sroasplit-4.ll
> llvm/test/Transforms/PhaseOrdering/instcombine-sroa-inttoptr.ll
> llvm/test/Transforms/SROA/address-spaces.ll
> llvm/test/Transforms/SROA/alignment.ll
> llvm/test/Transforms/SROA/alloca-address-space.ll
> llvm/test/Transforms/SROA/basictest.ll
> llvm/test/Transforms/SROA/pointer-offset-size.ll
> llvm/test/Transforms/SROA/scalable-vectors.ll
> llvm/test/Transforms/SROA/slice-width.ll
> llvm/test/Transforms/SROA/sroa-common-type-fail-promotion.ll
> llvm/test/Transforms/SROA/tbaa-struct.ll
> llvm/test/Transforms/SROA/tbaa-struct2.ll
> llvm/test/Transforms/SROA/vector-promotion.ll
>
> Removed:
>
>
>
> 
> diff  --git a/clang/test/CodeGenOpenCL/amdgpu-nullptr.cl 
> b/clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
> index 859e81f08d6bd..65f6f2e7d8c24 100644
> --- a/clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
> +++ b/clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
> @@ -515,17 +515,13 @@ typedef struct {
>private char *p;
>  } StructTy3;
>
> -// CHECK-LABEL: @test_memset_private(
> -// CHECK-NEXT:  entry:
> -// CHECK-NEXT:[[TMP0:%.*]] = bitcast [[STRUCT_STRUCTTY3:%.*]] 
> addrspace(5)* [[PTR:%.*]] to i8 addrspace(5)*
> -// CHECK-NEXT:
> [[S3_SROA_0_SROA_0_0_S3_SROA_0_0__SROA_CAST2_SROA_CAST:%.*]] = bitcast 
> [[STRUCT_STRUCTTY3]] addrspace(5)* [[PTR]] to <32 x i8> addrspace(5)*
> -// CHECK-NEXT:store <32 x i8> zeroinitializer, <32 x i8> addrspace(5)* 
> [[S3_SROA_0_SROA_0_0_S3_SROA_0_0__SROA_CAST2_SROA_CAST]], align 8, 
> !tbaa.struct !9
> -// CHECK-NEXT:[[S3_SROA_4_0__SROA_IDX6:%.*]] = getelementptr inbounds 
> [[STRUCT_STRUCTTY3]], [[STRUCT_STRUCTTY3]] addrspace(5)* [[PTR]], i32 0, i32 4
> -// CHECK-NEXT:store i8 addrspace(5)* addrspacecast (i8* null to i8 
> addrspace(5)*), i8 addrspace(5)* addrspace(5)* [[S3_SROA_4_0__SROA_IDX6]], 
> align 8, !tbaa.struct !12
> -// CHECK-NEXT:[[S3_SROA_5_0__SROA_IDX:%.*]] = getelementptr inbounds i8, 
> i8 addrspace(5)* [[TMP0]], i32 36
> -// CHECK-NEXT:[[S3_SROA_5_0__SROA_CAST8:%.*]] = bitcast i8 addrspace(5)* 
> [[S3_SROA_5_0__SROA_IDX]] to i32 addrspace(5)*
> -// CHECK-NEXT:store i32 0, i32 addrspace(5)* 
> [[S3_SROA_5_0__SROA_CAST8]], align 4, !tbaa.struct !13
> -// CHECK-NEXT:ret void
> +// CHECK-LABEL: test_memset_private
> +// CHECK: call void @llvm.memset.p5i8.i64(i8 addrspace(5)* noundef align 8 
> {{.*}}, i8 0, i64 32, i1 false)
> +// CHECK: [[GEP:%.*]] = getelementptr inbounds %struct.StructTy3, 
> %struct.StructTy3 addrspace(5)* %ptr, i32 0, i32 4
> +// CHECK: store i8 addrspace(5)* addrspacecast (i8* null to i8 
> addrspace(5)*), i8 addrspace(5)* addrspace(5)* [[GEP]]
> +// CHECK: [[GEP1:%.*]] = getelementptr inbounds i8, i8 addrspace(5)* {{.*}}, 
> i32 36
> +// CHECK: [[GEP1_CAST:%.*]] = bitcast i8 addrspace(5)* [[GEP1]] to i32 
> addrspace(5)*
> +// CHECK: store i32 0, i32 addrspace(5)* [[GEP1_CAST]], align 4
>  void test_memset_private(private StructTy3 *ptr) {
>StructTy3 S3 = {0, 0, 0, 0, 0};
>*ptr = S3;
>
> diff  --git a/llvm/lib/Transforms/Scalar/SROA.cpp 
> b/llvm/lib/Transforms/Scalar/SROA.cpp
> index 09a445c236fa7..6dcdd630b6bae 100644
> --- a/llvm/lib/Transforms/Scalar/SROA.cpp
> +++ b/llvm/lib/Transforms/Scalar/SROA.cpp
> @@ -1806,10 +1806,8 @@ static bool isVectorPromotionViableForSlice(Partition 
> , const Slice ,
>? Ty->getElementType()
>: FixedVectorType::get(Ty->getElementType(), 
> NumElements);
>
> -  Type *SplitIntTy = nullptr;
> -  if (uint64_t Bitwidth = NumElements * ElementSize * 8;
> -  Bitwidth <= IntegerType::MAX_INT_BITS)
> -SplitIntTy = Type::getIntNTy(Ty->getContext(), Bitwidth);
> +  Type *SplitIntTy =
> +  Type::getIntNTy(Ty->getContext(), NumElements * ElementSize * 8);
>
>Use *U = S.getUse();
>
> @@ -1828,8 +1826,7 @@ static bool isVectorPromotionViableForSlice(Partition 
> , const Slice ,
>  // Disable vector promotion when there are loads or stores of an FCA.
>  if (LTy->isStructTy())
>return 

[clang] cf624b2 - [SROA] `isVectorPromotionViable()`: memory intrinsics operate on vectors of bytes

2022-11-22 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2022-11-23T02:38:25+03:00
New Revision: cf624b23bc5d5a6161706d1663def49380ff816a

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

LOG: [SROA] `isVectorPromotionViable()`: memory intrinsics operate on vectors 
of bytes

Now, there's a big caveat here - these bytes
are abstract bytes, not the i8 we have in LLVM,
so strictly speaking this is not exactly legal,
see e.g. https://github.com/AliveToolkit/alive2/issues/860
^ the "bytes" "could" have been a pointer,
and loading it as an integer inserts an implicit ptrtoint.

But at the same time,
InstCombine's `InstCombinerImpl::SimplifyAnyMemTransfer()`
would expand a memtransfer of 1/2/4/8 bytes
into integer-typed load+store,
so this isn't exactly a new problem.

Note that in memory, poison is byte-wise,
so we really can't widen elements,
but SROA seems to be inconsistent here.

Fixes #59116.

Added: 


Modified: 
clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
llvm/lib/Transforms/Scalar/SROA.cpp
llvm/test/CodeGen/AMDGPU/v1024.ll
llvm/test/DebugInfo/X86/sroasplit-1.ll
llvm/test/DebugInfo/X86/sroasplit-4.ll
llvm/test/Transforms/PhaseOrdering/instcombine-sroa-inttoptr.ll
llvm/test/Transforms/SROA/address-spaces.ll
llvm/test/Transforms/SROA/alignment.ll
llvm/test/Transforms/SROA/alloca-address-space.ll
llvm/test/Transforms/SROA/basictest.ll
llvm/test/Transforms/SROA/pointer-offset-size.ll
llvm/test/Transforms/SROA/scalable-vectors.ll
llvm/test/Transforms/SROA/slice-width.ll
llvm/test/Transforms/SROA/sroa-common-type-fail-promotion.ll
llvm/test/Transforms/SROA/tbaa-struct.ll
llvm/test/Transforms/SROA/tbaa-struct2.ll
llvm/test/Transforms/SROA/vector-promotion.ll

Removed: 




diff  --git a/clang/test/CodeGenOpenCL/amdgpu-nullptr.cl 
b/clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
index 65f6f2e7d8c24..859e81f08d6bd 100644
--- a/clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
+++ b/clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
@@ -515,13 +515,17 @@ typedef struct {
   private char *p;
 } StructTy3;
 
-// CHECK-LABEL: test_memset_private
-// CHECK: call void @llvm.memset.p5i8.i64(i8 addrspace(5)* noundef align 8 
{{.*}}, i8 0, i64 32, i1 false)
-// CHECK: [[GEP:%.*]] = getelementptr inbounds %struct.StructTy3, 
%struct.StructTy3 addrspace(5)* %ptr, i32 0, i32 4
-// CHECK: store i8 addrspace(5)* addrspacecast (i8* null to i8 addrspace(5)*), 
i8 addrspace(5)* addrspace(5)* [[GEP]]
-// CHECK: [[GEP1:%.*]] = getelementptr inbounds i8, i8 addrspace(5)* {{.*}}, 
i32 36
-// CHECK: [[GEP1_CAST:%.*]] = bitcast i8 addrspace(5)* [[GEP1]] to i32 
addrspace(5)*
-// CHECK: store i32 0, i32 addrspace(5)* [[GEP1_CAST]], align 4
+// CHECK-LABEL: @test_memset_private(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = bitcast [[STRUCT_STRUCTTY3:%.*]] 
addrspace(5)* [[PTR:%.*]] to i8 addrspace(5)*
+// CHECK-NEXT:[[S3_SROA_0_SROA_0_0_S3_SROA_0_0__SROA_CAST2_SROA_CAST:%.*]] 
= bitcast [[STRUCT_STRUCTTY3]] addrspace(5)* [[PTR]] to <32 x i8> addrspace(5)*
+// CHECK-NEXT:store <32 x i8> zeroinitializer, <32 x i8> addrspace(5)* 
[[S3_SROA_0_SROA_0_0_S3_SROA_0_0__SROA_CAST2_SROA_CAST]], align 8, !tbaa.struct 
!9
+// CHECK-NEXT:[[S3_SROA_4_0__SROA_IDX6:%.*]] = getelementptr inbounds 
[[STRUCT_STRUCTTY3]], [[STRUCT_STRUCTTY3]] addrspace(5)* [[PTR]], i32 0, i32 4
+// CHECK-NEXT:store i8 addrspace(5)* addrspacecast (i8* null to i8 
addrspace(5)*), i8 addrspace(5)* addrspace(5)* [[S3_SROA_4_0__SROA_IDX6]], 
align 8, !tbaa.struct !12
+// CHECK-NEXT:[[S3_SROA_5_0__SROA_IDX:%.*]] = getelementptr inbounds i8, 
i8 addrspace(5)* [[TMP0]], i32 36
+// CHECK-NEXT:[[S3_SROA_5_0__SROA_CAST8:%.*]] = bitcast i8 addrspace(5)* 
[[S3_SROA_5_0__SROA_IDX]] to i32 addrspace(5)*
+// CHECK-NEXT:store i32 0, i32 addrspace(5)* [[S3_SROA_5_0__SROA_CAST8]], 
align 4, !tbaa.struct !13
+// CHECK-NEXT:ret void
 void test_memset_private(private StructTy3 *ptr) {
   StructTy3 S3 = {0, 0, 0, 0, 0};
   *ptr = S3;

diff  --git a/llvm/lib/Transforms/Scalar/SROA.cpp 
b/llvm/lib/Transforms/Scalar/SROA.cpp
index 0d045656661a1..0fafa3af76367 100644
--- a/llvm/lib/Transforms/Scalar/SROA.cpp
+++ b/llvm/lib/Transforms/Scalar/SROA.cpp
@@ -1806,8 +1806,10 @@ static bool isVectorPromotionViableForSlice(Partition 
, const Slice ,
   ? Ty->getElementType()
   : FixedVectorType::get(Ty->getElementType(), 
NumElements);
 
-  Type *SplitIntTy =
-  Type::getIntNTy(Ty->getContext(), NumElements * ElementSize * 8);
+  Type *SplitIntTy = nullptr;
+  if (uint64_t Bitwidth = NumElements * ElementSize * 8;
+  Bitwidth <= IntegerType::MAX_INT_BITS)
+SplitIntTy = Type::getIntNTy(Ty->getContext(), Bitwidth);
 
   Use *U = S.getUse();
 
@@ -1826,7 +1828,8 @@ static 

[clang] 3410808 - Revert "Reland "[LTO][COFF] Use bitcode file names in lto native object file names.""

2022-11-22 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2022-11-23T00:40:12+03:00
New Revision: 34108082947c964ae9bbfcd9808f2fd31c0d672f

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

LOG: Revert "Reland "[LTO][COFF] Use bitcode file names in lto native object 
file names.""

Breaks build of LLVMgold here:
```
/repositories/llvm-project/llvm/tools/gold/gold-plugin.cpp:1108:19: error: no 
matching function for call to 'localCache'
Cache = check(localCache("ThinLTO", "Thin", options::cache_dir, AddBuffer));
  ^~
/repositories/llvm-project/llvm/include/llvm/Support/Caching.h:72:21: note: 
candidate function not viable: no known conversion from '(lambda at 
/repositories/llvm-project/llvm/tools/gold/gold-plugin.cpp:1102:20)' to 
'llvm::AddBufferFn' (aka 'function)>') for 4th argument
Expected localCache(
^
/repositories/llvm-project/llvm/tools/gold/gold-plugin.cpp:1110:18: error: no 
viable conversion from '(lambda at 
/repositories/llvm-project/llvm/tools/gold/gold-plugin.cpp:1094:20)' to 
'llvm::AddStreamFn' (aka 'function> 
(unsigned int, const llvm::Twine &)>')
  check(Lto->run(AddStream, Cache));
 ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/std_function.h:375:7:
 note: candidate constructor not viable: no known conversion from '(lambda at 
/repositories/llvm-project/llvm/tools/gold/gold-plugin.cpp:1094:20)' to 
'std::nullptr_t' for 1st argument
  function(nullptr_t) noexcept
  ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/std_function.h:386:7:
 note: candidate constructor not viable: no known conversion from '(lambda at 
/repositories/llvm-project/llvm/tools/gold/gold-plugin.cpp:1094:20)' to 'const 
std::function> (unsigned 
int, const llvm::Twine &)> &' for 1st argument
  function(const function& __x)
  ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/std_function.h:404:7:
 note: candidate constructor not viable: no known conversion from '(lambda at 
/repositories/llvm-project/llvm/tools/gold/gold-plugin.cpp:1094:20)' to 
'std::function> 
(unsigned int, const llvm::Twine &)> &&' for 1st argument
  function(function&& __x) noexcept
  ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/std_function.h:435:2:
 note: candidate template ignored: requirement '_Callable<(lambda at 
/repositories/llvm-project/llvm/tools/gold/gold-plugin.cpp:1094:20) &, (lambda 
at /repositories/llvm-project/llvm/tools/gold/gold-plugin.cpp:1094:20), 
std::__invoke_result<(lambda at 
/repositories/llvm-project/llvm/tools/gold/gold-plugin.cpp:1094:20) &, unsigned 
int, const llvm::Twine &>>::value' was not satisfied [with _Functor = (lambda 
at /repositories/llvm-project/llvm/tools/gold/gold-plugin.cpp:1094:20) &]
function(_Functor&& __f)
^
/repositories/llvm-project/llvm/include/llvm/LTO/LTO.h:278:25: note: passing 
argument to parameter 'AddStream' here
  Error run(AddStreamFn AddStream, FileCache Cache = nullptr);
^

```

This reverts commit 387620aa8cea33174b6c1fb80c1af713fee732ac.

Added: 


Modified: 
clang/lib/CodeGen/BackendUtil.cpp
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
lld/COFF/LTO.cpp
lld/COFF/LTO.h
lld/ELF/LTO.cpp
lld/MachO/LTO.cpp
lld/test/COFF/lto-obj-path.ll
lld/test/COFF/pdb-thinlto.ll
lld/test/COFF/thinlto.ll
lld/wasm/LTO.cpp
lldb/source/Core/DataFileCache.cpp
llvm/include/llvm/Support/Caching.h
llvm/lib/Debuginfod/Debuginfod.cpp
llvm/lib/LTO/LTO.cpp
llvm/lib/LTO/LTOBackend.cpp
llvm/lib/LTO/LTOCodeGenerator.cpp
llvm/lib/Support/Caching.cpp
llvm/tools/llvm-lto/llvm-lto.cpp
llvm/tools/llvm-lto2/llvm-lto2.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 77b0c5b15da7d..d0cab0ceb4d3c 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1110,7 +1110,7 @@ static void runThinLTOBackend(
   if (!lto::initImportList(*M, *CombinedIndex, ImportList))
 return;
 
-  auto AddStream = [&](size_t Task, const Twine ) {
+  auto AddStream = [&](size_t Task) {
 return std::make_unique(std::move(OS),
   CGOpts.ObjectFilenameForDebug);
   };

diff  --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 5e0c0f92e6f53..500f5fdcecae2 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -843,9 +843,7 @@ Error linkBitcodeFiles(SmallVectorImpl 
,
   // Run the LTO job to compile the bitcode.
   size_t MaxTasks = 

[clang] 8adfa29 - [Pipelines] Introduce SROA after (final, run-time) loop unrolling

2022-11-17 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2022-11-17T21:31:30+03:00
New Revision: 8adfa29706e5407b62a4726e2172894e0dfdc1e8

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

LOG: [Pipelines] Introduce SROA after (final, run-time) loop unrolling

Now that we are done with loop unrolling, be it either by LoopVectorizer,
or LoopUnroll passes, some variable-offset GEP's into alloca's could have
become constant-offset, thus enabling SROA and alloca promotion,
yet we don't capitalize on that, which is surprizing.

While it would be good to not introduce one more SROA invocation,
but instead move the one from 
`PassBuilder::buildFunctionSimplificationPipeline()`,
the existing test coverage says that is a bad idea,
though it would be fine compile-time wise: 
https://llvm-compile-time-tracker.com/compare.php?from=b150d34c47efbd8fa09604bce805c0920360f8d7=5a9a5c855158b482552be8c7af3e73d67fa44805=instructions

So instead, i add yet another SROA run.
I have checked, and it needs to be at least after said final loop unrolling.
This is still fine compile-time wise: 
https://llvm-compile-time-tracker.com/compare.php?from=70324cd88328c0924e605fa81b696572560aa5c9=fb489bbef687ad821c3173a931709f9cad9aee8a=instructions

I've encountered this in a real code, `SROA-after-final-loop-unrolling.ll` has 
been reduced from https://godbolt.org/z/fsdMhETh3

Reviewed By: spatel

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

Added: 


Modified: 
clang/test/CodeGen/cleanup-destslot-simple.c
llvm/lib/Passes/PassBuilderPipelines.cpp
llvm/test/Other/new-pm-defaults.ll
llvm/test/Other/new-pm-lto-defaults.ll
llvm/test/Other/new-pm-thinlto-defaults.ll
llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
llvm/test/Transforms/Coroutines/coro-retcon-resume-values.ll
llvm/test/Transforms/PhaseOrdering/X86/SROA-after-final-loop-unrolling-2.ll
llvm/test/Transforms/PhaseOrdering/X86/SROA-after-final-loop-unrolling.ll
llvm/test/Transforms/PhaseOrdering/single-iteration-loop-sroa.ll

Removed: 




diff  --git a/clang/test/CodeGen/cleanup-destslot-simple.c 
b/clang/test/CodeGen/cleanup-destslot-simple.c
index 18d4c2138090e..2a0e682b0ab21 100644
--- a/clang/test/CodeGen/cleanup-destslot-simple.c
+++ b/clang/test/CodeGen/cleanup-destslot-simple.c
@@ -17,8 +17,8 @@
 // CHECK-LIFETIME-NEXT:store i32 3, ptr [[X]], align 4, !dbg 
[[DBG10:![0-9]+]], !tbaa [[TBAA11:![0-9]+]]
 // CHECK-LIFETIME-NEXT:call void @llvm.lifetime.start.p0(i64 8, ptr 
nonnull [[P]]), !dbg [[DBG15:![0-9]+]]
 // CHECK-LIFETIME-NEXT:store volatile ptr [[X]], ptr [[P]], align 8, !dbg 
[[DBG16:![0-9]+]], !tbaa [[TBAA17:![0-9]+]]
-// CHECK-LIFETIME-NEXT:[[P_0_P_0_P_0_:%.*]] = load volatile ptr, ptr 
[[P]], align 8, !dbg [[DBG19:![0-9]+]], !tbaa [[TBAA17]]
-// CHECK-LIFETIME-NEXT:[[TMP0:%.*]] = load i32, ptr [[P_0_P_0_P_0_]], 
align 4, !dbg [[DBG20:![0-9]+]], !tbaa [[TBAA11]]
+// CHECK-LIFETIME-NEXT:[[P_0_P_0_P_0_P_0_:%.*]] = load volatile ptr, ptr 
[[P]], align 8, !dbg [[DBG19:![0-9]+]], !tbaa [[TBAA17]]
+// CHECK-LIFETIME-NEXT:[[TMP0:%.*]] = load i32, ptr [[P_0_P_0_P_0_P_0_]], 
align 4, !dbg [[DBG20:![0-9]+]], !tbaa [[TBAA11]]
 // CHECK-LIFETIME-NEXT:call void @llvm.lifetime.end.p0(i64 8, ptr nonnull 
[[P]]), !dbg [[DBG21:![0-9]+]]
 // CHECK-LIFETIME-NEXT:call void @llvm.lifetime.end.p0(i64 4, ptr nonnull 
[[X]]) #[[ATTR2]], !dbg [[DBG21]]
 // CHECK-LIFETIME-NEXT:ret i32 [[TMP0]], !dbg [[DBG22:![0-9]+]]
@@ -49,7 +49,7 @@
 // CHECK-MSAN-NEXT:[[TMP5:%.*]] = inttoptr i64 [[TMP4]] to ptr, !dbg 
[[DBG15]]
 // CHECK-MSAN-NEXT:store i64 0, ptr [[TMP5]], align 8, !dbg 
[[DBG16:![0-9]+]]
 // CHECK-MSAN-NEXT:store volatile ptr [[X]], ptr [[P]], align 8, !dbg 
[[DBG16]], !tbaa [[TBAA17:![0-9]+]]
-// CHECK-MSAN-NEXT:[[P_0_P_0_P_0_:%.*]] = load volatile ptr, ptr [[P]], 
align 8, !dbg [[DBG19:![0-9]+]], !tbaa [[TBAA17]]
+// CHECK-MSAN-NEXT:[[P_0_P_0_P_0_P_0_:%.*]] = load volatile ptr, ptr 
[[P]], align 8, !dbg [[DBG19:![0-9]+]], !tbaa [[TBAA17]]
 // CHECK-MSAN-NEXT:[[_MSLD:%.*]] = load i64, ptr [[TMP5]], align 8, !dbg 
[[DBG19]]
 // CHECK-MSAN-NEXT:[[_MSCMP_NOT:%.*]] = icmp eq i64 [[_MSLD]], 0, !dbg 
[[DBG20:![0-9]+]]
 // CHECK-MSAN-NEXT:br i1 [[_MSCMP_NOT]], label [[TMP7:%.*]], label 
[[TMP6:%.*]], !dbg [[DBG20]], !prof [[PROF21:![0-9]+]]
@@ -57,8 +57,8 @@
 // CHECK-MSAN-NEXT:call void @__msan_warning_noreturn() #[[ATTR3:[0-9]+]], 
!dbg [[DBG20]]
 // CHECK-MSAN-NEXT:unreachable, !dbg [[DBG20]]
 // CHECK-MSAN:   7:
-// CHECK-MSAN-NEXT:[[TMP8:%.*]] = load i32, ptr [[P_0_P_0_P_0_]], align 4, 
!dbg [[DBG20]], !tbaa [[TBAA11]]
-// CHECK-MSAN-NEXT:[[TMP9:%.*]] = ptrtoint ptr [[P_0_P_0_P_0_]] 

[clang] b2fbafc - [NFC][Clang] Autogenerate checklines in a test being affected by a patch

2022-11-14 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2022-11-15T03:51:24+03:00
New Revision: b2fbafc911062ba74761d69d035ee8686125f2fc

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

LOG: [NFC][Clang] Autogenerate checklines in a test being affected by a patch

Added: 


Modified: 
clang/test/CodeGen/cleanup-destslot-simple.c

Removed: 




diff  --git a/clang/test/CodeGen/cleanup-destslot-simple.c 
b/clang/test/CodeGen/cleanup-destslot-simple.c
index 36cea26408eb7..18d4c2138090e 100644
--- a/clang/test/CodeGen/cleanup-destslot-simple.c
+++ b/clang/test/CodeGen/cleanup-destslot-simple.c
@@ -1,22 +1,117 @@
-// RUN: %clang_cc1 -O1 -triple x86_64-none-linux-gnu -emit-llvm 
-debug-info-kind=line-tables-only %s -o - | FileCheck %s --check-prefix=CHECK 
--check-prefix=LIFETIME
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -O1 -triple x86_64-none-linux-gnu -emit-llvm 
-debug-info-kind=line-tables-only %s -o - | FileCheck %s 
--check-prefix=CHECK-LIFETIME
 
 // We shouldn't have markers at -O0 or with msan.
-// RUN: %clang_cc1 -O0 -triple x86_64-none-linux-gnu -emit-llvm 
-debug-info-kind=line-tables-only %s -o - | FileCheck %s
-// RUN: %clang_cc1 -O1 -triple x86_64-none-linux-gnu -emit-llvm 
-debug-info-kind=line-tables-only %s -o - -fsanitize=memory | FileCheck %s
-// RUN: %clang_cc1 -O1 -triple x86_64-none-linux-gnu -emit-llvm 
-debug-info-kind=line-tables-only %s -o - -fsanitize=kernel-memory | FileCheck 
%s
+// RUN: %clang_cc1 -O0 -triple x86_64-none-linux-gnu -emit-llvm 
-debug-info-kind=line-tables-only %s -o - | FileCheck %s 
--check-prefix=CHECK-OPTNONE
+// RUN: %clang_cc1 -O1 -triple x86_64-none-linux-gnu -emit-llvm 
-debug-info-kind=line-tables-only %s -o - -fsanitize=memory | FileCheck %s 
--check-prefix=CHECK-MSAN
+// RUN: %clang_cc1 -O1 -triple x86_64-none-linux-gnu -emit-llvm 
-debug-info-kind=line-tables-only %s -o - -fsanitize=kernel-memory | FileCheck 
%s --check-prefix=CHECK-KMSAN
 
 // There is no exception to handle here, lifetime.end is not a destructor,
 // so there is no need have cleanup dest slot related code
-// CHECK-LABEL: define{{.*}} i32 @test
+
+// CHECK-LIFETIME-LABEL: @test(
+// CHECK-LIFETIME-NEXT:  entry:
+// CHECK-LIFETIME-NEXT:[[X:%.*]] = alloca i32, align 4
+// CHECK-LIFETIME-NEXT:[[P:%.*]] = alloca ptr, align 8
+// CHECK-LIFETIME-NEXT:call void @llvm.lifetime.start.p0(i64 4, ptr 
nonnull [[X]]) #[[ATTR2:[0-9]+]], !dbg [[DBG9:![0-9]+]]
+// CHECK-LIFETIME-NEXT:store i32 3, ptr [[X]], align 4, !dbg 
[[DBG10:![0-9]+]], !tbaa [[TBAA11:![0-9]+]]
+// CHECK-LIFETIME-NEXT:call void @llvm.lifetime.start.p0(i64 8, ptr 
nonnull [[P]]), !dbg [[DBG15:![0-9]+]]
+// CHECK-LIFETIME-NEXT:store volatile ptr [[X]], ptr [[P]], align 8, !dbg 
[[DBG16:![0-9]+]], !tbaa [[TBAA17:![0-9]+]]
+// CHECK-LIFETIME-NEXT:[[P_0_P_0_P_0_:%.*]] = load volatile ptr, ptr 
[[P]], align 8, !dbg [[DBG19:![0-9]+]], !tbaa [[TBAA17]]
+// CHECK-LIFETIME-NEXT:[[TMP0:%.*]] = load i32, ptr [[P_0_P_0_P_0_]], 
align 4, !dbg [[DBG20:![0-9]+]], !tbaa [[TBAA11]]
+// CHECK-LIFETIME-NEXT:call void @llvm.lifetime.end.p0(i64 8, ptr nonnull 
[[P]]), !dbg [[DBG21:![0-9]+]]
+// CHECK-LIFETIME-NEXT:call void @llvm.lifetime.end.p0(i64 4, ptr nonnull 
[[X]]) #[[ATTR2]], !dbg [[DBG21]]
+// CHECK-LIFETIME-NEXT:ret i32 [[TMP0]], !dbg [[DBG22:![0-9]+]]
+//
+// CHECK-OPTNONE-LABEL: @test(
+// CHECK-OPTNONE-NEXT:  entry:
+// CHECK-OPTNONE-NEXT:[[X:%.*]] = alloca i32, align 4
+// CHECK-OPTNONE-NEXT:[[P:%.*]] = alloca ptr, align 8
+// CHECK-OPTNONE-NEXT:store i32 3, ptr [[X]], align 4, !dbg 
[[DBG9:![0-9]+]]
+// CHECK-OPTNONE-NEXT:store volatile ptr [[X]], ptr [[P]], align 8, !dbg 
[[DBG10:![0-9]+]]
+// CHECK-OPTNONE-NEXT:[[TMP0:%.*]] = load volatile ptr, ptr [[P]], align 
8, !dbg [[DBG11:![0-9]+]]
+// CHECK-OPTNONE-NEXT:[[TMP1:%.*]] = load i32, ptr [[TMP0]], align 4, !dbg 
[[DBG12:![0-9]+]]
+// CHECK-OPTNONE-NEXT:ret i32 [[TMP1]], !dbg [[DBG13:![0-9]+]]
+//
+// CHECK-MSAN-LABEL: @test(
+// CHECK-MSAN-NEXT:  entry:
+// CHECK-MSAN-NEXT:[[X:%.*]] = alloca i32, align 4
+// CHECK-MSAN-NEXT:[[P:%.*]] = alloca ptr, align 8
+// CHECK-MSAN-NEXT:call void @llvm.lifetime.start.p0(i64 4, ptr nonnull 
[[X]]) #[[ATTR2:[0-9]+]], !dbg [[DBG9:![0-9]+]]
+// CHECK-MSAN-NEXT:[[TMP0:%.*]] = ptrtoint ptr [[X]] to i64, !dbg [[DBG9]]
+// CHECK-MSAN-NEXT:[[TMP1:%.*]] = xor i64 [[TMP0]], 87960930222080, !dbg 
[[DBG9]]
+// CHECK-MSAN-NEXT:[[TMP2:%.*]] = inttoptr i64 [[TMP1]] to ptr, !dbg 
[[DBG9]]
+// CHECK-MSAN-NEXT:store i32 0, ptr [[TMP2]], align 4, !dbg 
[[DBG10:![0-9]+]]
+// CHECK-MSAN-NEXT:store i32 3, ptr [[X]], align 4, !dbg [[DBG10]], !tbaa 
[[TBAA11:![0-9]+]]
+// CHECK-MSAN-NEXT:call void 

[clang] 6daa005 - [NFC][Clang] Add some codegen tests for https://github.com/llvm/llvm-project/issues/58798

2022-11-12 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2022-11-13T02:39:52+03:00
New Revision: 6daa005b90c8122751d04c6eba0fa1259e912cfe

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

LOG: [NFC][Clang] Add some codegen tests for 
https://github.com/llvm/llvm-project/issues/58798

Added: 
clang/test/CodeGenCXX/pr58798.cpp

Modified: 


Removed: 




diff  --git a/clang/test/CodeGenCXX/pr58798.cpp 
b/clang/test/CodeGenCXX/pr58798.cpp
new file mode 100644
index 0..607b36aa7f69a
--- /dev/null
+++ b/clang/test/CodeGenCXX/pr58798.cpp
@@ -0,0 +1,186 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --function-signature --check-attributes
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple x86_64-linux-gnu -fexceptions 
-fcxx-exceptions | FileCheck %s
+
+// CHECK: Function Attrs: mustprogress noinline nounwind optnone willreturn 
memory(read)
+// CHECK-LABEL: define 
{{[^@]+}}@_Z54early_caller_of_callee_with_clang_attr_with_clang_attri
+// CHECK-SAME: (i32 noundef [[A:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:store i32 [[A]], ptr [[A_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load i32, ptr [[A_ADDR]], align 4
+// CHECK-NEXT:[[CALL:%.*]] = call noundef i32 
@_Z22callee_with_clang_attri(i32 noundef [[TMP0]]) #[[ATTR3:[0-9]+]]
+// CHECK-NEXT:ret i32 [[CALL]]
+//
+
+// CHECK: Function Attrs: mustprogress noinline nounwind optnone willreturn 
memory(read)
+// CHECK-LABEL: define {{[^@]+}}@_Z22callee_with_clang_attri
+// CHECK-SAME: (i32 noundef [[A:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:store i32 [[A]], ptr [[A_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load i32, ptr [[A_ADDR]], align 4
+// CHECK-NEXT:[[TOBOOL:%.*]] = icmp ne i32 [[TMP0]], 0
+// CHECK-NEXT:br i1 [[TOBOOL]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
+// CHECK:   if.then:
+// CHECK-NEXT:[[EXCEPTION:%.*]] = call ptr @__cxa_allocate_exception(i64 
4) #[[ATTR4:[0-9]+]]
+// CHECK-NEXT:store i32 42, ptr [[EXCEPTION]], align 16
+// CHECK-NEXT:call void @__cxa_throw(ptr [[EXCEPTION]], ptr @_ZTIi, ptr 
null) #[[ATTR5:[0-9]+]]
+// CHECK-NEXT:unreachable
+// CHECK:   if.end:
+// CHECK-NEXT:ret i32 24
+//
+
+// CHECK: Function Attrs: mustprogress noinline nounwind optnone
+// CHECK-LABEL: define 
{{[^@]+}}@_Z52early_caller_of_callee_with_clang_attr_with_cxx_attri
+// CHECK-SAME: (i32 noundef [[A:%.*]]) #[[ATTR1:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:store i32 [[A]], ptr [[A_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load i32, ptr [[A_ADDR]], align 4
+// CHECK-NEXT:[[CALL:%.*]] = call noundef i32 
@_Z22callee_with_clang_attri(i32 noundef [[TMP0]]) #[[ATTR3]]
+// CHECK-NEXT:ret i32 [[CALL]]
+//
+
+// CHECK: Function Attrs: mustprogress noinline nounwind optnone willreturn 
memory(read)
+// CHECK-LABEL: define 
{{[^@]+}}@_Z52early_caller_of_callee_with_cxx_attr_with_clang_attri
+// CHECK-SAME: (i32 noundef [[A:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:store i32 [[A]], ptr [[A_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load i32, ptr [[A_ADDR]], align 4
+// CHECK-NEXT:[[CALL:%.*]] = call noundef i32 
@_Z20callee_with_cxx_attri(i32 noundef [[TMP0]]) #[[ATTR4]]
+// CHECK-NEXT:ret i32 [[CALL]]
+//
+
+// CHECK: Function Attrs: mustprogress noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@_Z20callee_with_cxx_attri
+// CHECK-SAME: (i32 noundef [[A:%.*]]) #[[ATTR1]] personality ptr 
@__gxx_personality_v0 {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:store i32 [[A]], ptr [[A_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load i32, ptr [[A_ADDR]], align 4
+// CHECK-NEXT:[[TOBOOL:%.*]] = icmp ne i32 [[TMP0]], 0
+// CHECK-NEXT:br i1 [[TOBOOL]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
+// CHECK:   if.then:
+// CHECK-NEXT:[[EXCEPTION:%.*]] = call ptr @__cxa_allocate_exception(i64 
4) #[[ATTR4]]
+// CHECK-NEXT:store i32 42, ptr [[EXCEPTION]], align 16
+// CHECK-NEXT:invoke void @__cxa_throw(ptr [[EXCEPTION]], ptr @_ZTIi, ptr 
null) #[[ATTR5]]
+// CHECK-NEXT:to label [[UNREACHABLE:%.*]] unwind label 
[[TERMINATE_LPAD:%.*]]
+// CHECK:   if.end:
+// CHECK-NEXT:ret i32 24
+// CHECK:   terminate.lpad:
+// CHECK-NEXT:[[TMP1:%.*]] = landingpad { ptr, i32 }
+// CHECK-NEXT:catch ptr null
+// CHECK-NEXT:[[TMP2:%.*]] = extractvalue { ptr, i32 } [[TMP1]], 0
+// CHECK-NEXT:call void @__clang_call_terminate(ptr [[TMP2]]) 

Re: [clang] 4bafe65 - Add support for floating-point option `ffp-eval-method` and for

2022-02-15 Thread Roman Lebedev via cfe-commits
Where was this reviewed?

On Wed, Feb 16, 2022 at 12:59 AM Zahira Ammarguellat via cfe-commits
 wrote:
>
>
> Author: Zahira Ammarguellat
> Date: 2022-02-15T13:59:27-08:00
> New Revision: 4bafe65c2b2f1ce745894a509a6d80c87fb1c335
>
> URL: 
> https://github.com/llvm/llvm-project/commit/4bafe65c2b2f1ce745894a509a6d80c87fb1c335
> DIFF: 
> https://github.com/llvm/llvm-project/commit/4bafe65c2b2f1ce745894a509a6d80c87fb1c335.diff
>
> LOG: Add support for floating-point option `ffp-eval-method` and for
> `pragma clang fp eval_method`.
>
> Added:
> clang/test/CodeGen/X86/32bit-behavior-no-eval.c
> clang/test/CodeGen/X86/32bit-behavior.c
> clang/test/CodeGen/X86/fp-eval-method.c
> clang/test/CodeGen/flt_eval_macro.cpp
> clang/test/Preprocessor/flt_eval_macro.cpp
> clang/test/Sema/fp-eval-pragma.cpp
> clang/test/Sema/x86-eval-method.c
> clang/test/Sema/x86_64-eval-method.c
>
> Modified:
> clang/docs/LanguageExtensions.rst
> clang/docs/UsersManual.rst
> clang/include/clang/Basic/DiagnosticCommonKinds.td
> clang/include/clang/Basic/DiagnosticLexKinds.td
> clang/include/clang/Basic/FPOptions.def
> clang/include/clang/Basic/LangOptions.def
> clang/include/clang/Basic/LangOptions.h
> clang/include/clang/Basic/TargetInfo.h
> clang/include/clang/Driver/Options.td
> clang/include/clang/Lex/Preprocessor.h
> clang/include/clang/Parse/Parser.h
> clang/include/clang/Sema/Sema.h
> clang/lib/Basic/Targets/OSTargets.h
> clang/lib/Basic/Targets/X86.h
> clang/lib/Driver/ToolChains/Clang.cpp
> clang/lib/Frontend/InitPreprocessor.cpp
> clang/lib/Lex/PPMacroExpansion.cpp
> clang/lib/Parse/ParsePragma.cpp
> clang/lib/Parse/ParseStmt.cpp
> clang/lib/Sema/Sema.cpp
> clang/lib/Sema/SemaAttr.cpp
> clang/lib/Sema/SemaExpr.cpp
> clang/test/CodeGen/fp-floatcontrol-pragma.cpp
> clang/test/Preprocessor/init-aarch64.c
> clang/test/Preprocessor/init-arm.c
> clang/test/Preprocessor/init-mips.c
> clang/test/Preprocessor/init-ppc.c
> clang/test/Preprocessor/init-ppc64.c
> clang/test/Preprocessor/init-s390x.c
> clang/test/Preprocessor/init-v7k-compat.c
> clang/test/Preprocessor/init-x86.c
> clang/test/Preprocessor/init.c
>
> Removed:
>
>
>
> 
> diff  --git a/clang/docs/LanguageExtensions.rst 
> b/clang/docs/LanguageExtensions.rst
> index f45d88092eb4a..5249d3f3f7930 100644
> --- a/clang/docs/LanguageExtensions.rst
> +++ b/clang/docs/LanguageExtensions.rst
> @@ -3907,6 +3907,38 @@ A ``#pragma clang fp`` pragma may contain any number 
> of options:
>  ...
>}
>
> +``#pragma clang fp eval_method`` allows floating-point behavior to be 
> specified
> +for a section of the source code. This pragma can appear at file or namespace
> +scope, or at the start of a compound statement (excluding comments).
> +The pragma is active within the scope of the compound statement.
> +
> +When ``pragma clang fp eval_method(source)`` is enabled, the section of code
> +governed by the pragma behaves as though the command-line option
> +``-ffp-eval-method=source`` is enabled. Rounds intermediate results to
> +source-defined precision.
> +
> +When ``pragma clang fp eval_method(double)`` is enabled, the section of code
> +governed by the pragma behaves as though the command-line option
> +``-ffp-eval-method=double`` is enabled. Rounds intermediate results to
> +``double`` precision.
> +
> +When ``pragma clang fp eval_method(extended)`` is enabled, the section of 
> code
> +governed by the pragma behaves as though the command-line option
> +``-ffp-eval-method=extended`` is enabled. Rounds intermediate results to
> +target-dependent ``long double`` precision. In Win32 programming, for 
> instance,
> +the long double data type maps to the double, 64-bit precision data type.
> +
> +The full syntax this pragma supports is
> +``#pragma clang fp eval_method(source|double|extended)``.
> +
> +.. code-block:: c++
> +
> +  for(...) {
> +// The compiler will use long double as the floating-point evaluation
> +// method.
> +#pragma clang fp eval_method(extended)
> +a = b[i] * c[i] + e;
> +  }
>
>  The ``#pragma float_control`` pragma allows precise floating-point
>  semantics and floating-point exception behavior to be specified
>
> diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
> index 1df96296cb8ac..70fee29ab2a84 100644
> --- a/clang/docs/UsersManual.rst
> +++ b/clang/docs/UsersManual.rst
> @@ -1566,6 +1566,22 @@ Note that floating-point operations performed as part 
> of constant initialization
> * ``maytrap`` The compiler avoids transformations that may raise 
> exceptions that would not have been raised by the original code. Constant 
> folding performed by the compiler is exempt from this option.
> * ``strict`` The compiler ensures that all transformations strictly 
> preserve the floating point 

[clang] eaac0e8 - [NFC][clang] Autogenerate checklines in CodeGenCXX/nrvo.cpp

2022-02-08 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2022-02-08T18:27:54+03:00
New Revision: eaac0e87fb0249f9b87b9929b1afa24504db9792

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

LOG: [NFC][clang] Autogenerate checklines in CodeGenCXX/nrvo.cpp

It checks IR after optimizations, which is inherently fragile,
and the results are now different after the recent patch.

Added: 


Modified: 
clang/test/CodeGenCXX/nrvo.cpp

Removed: 




diff  --git a/clang/test/CodeGenCXX/nrvo.cpp b/clang/test/CodeGenCXX/nrvo.cpp
index 11b1d5e13572a..c9428fd8887db 100644
--- a/clang/test/CodeGenCXX/nrvo.cpp
+++ b/clang/test/CodeGenCXX/nrvo.cpp
@@ -1,3 +1,4 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
 // RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm -O1 -o - %s | 
FileCheck %s
 // RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm -O1 
-fcxx-exceptions -fexceptions -std=c++03 -o - %s | FileCheck 
--check-prefixes=CHECK-EH,CHECK-EH-03 %s
 // RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm -O1 
-fcxx-exceptions -fexceptions -std=c++11 -o - %s | FileCheck 
--check-prefixes=CHECK-EH,CHECK-EH-11 %s
@@ -18,34 +19,141 @@ template struct Y {
   }
 };
 
-// CHECK-LABEL: define{{.*}} void @_Z5test0v
-// CHECK-EH-LABEL: define{{.*}} void @_Z5test0v
+// CHECK-LABEL: @_Z5test0v(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:call void @_ZN1XC1Ev(%class.X* noundef nonnull align 1 
dereferenceable(1) [[AGG_RESULT:%.*]]) #[[ATTR5:[0-9]+]]
+// CHECK-NEXT:ret void
+//
+// CHECK-EH-LABEL: @_Z5test0v(
+// CHECK-EH-NEXT:  entry:
+// CHECK-EH-NEXT:call void @_ZN1XC1Ev(%class.X* noundef nonnull align 1 
dereferenceable(1) [[AGG_RESULT:%.*]])
+// CHECK-EH-NEXT:ret void
+//
 X test0() {
   X x;
-  // CHECK:  call {{.*}} @_ZN1XC1Ev
-  // CHECK-NEXT: ret void
 
-  // CHECK-EH:   call {{.*}} @_ZN1XC1Ev
-  // CHECK-EH-NEXT:  ret void
   return x;
 }
 
-// CHECK-LABEL: define{{.*}} void @_Z5test1b(
-// CHECK-EH-LABEL: define{{.*}} void @_Z5test1b(
+// CHECK-LABEL: @_Z5test1b(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:call void @_ZN1XC1Ev(%class.X* noundef nonnull align 1 
dereferenceable(1) [[AGG_RESULT:%.*]]) #[[ATTR5]]
+// CHECK-NEXT:ret void
+//
+// CHECK-EH-LABEL: @_Z5test1b(
+// CHECK-EH-NEXT:  entry:
+// CHECK-EH-NEXT:call void @_ZN1XC1Ev(%class.X* noundef nonnull align 1 
dereferenceable(1) [[AGG_RESULT:%.*]])
+// CHECK-EH-NEXT:ret void
+//
 X test1(bool B) {
-  // CHECK:  call {{.*}} @_ZN1XC1Ev
-  // CHECK-NEXT: ret void
   X x;
   if (B)
 return (x);
   return x;
-  // CHECK-EH:  call {{.*}} @_ZN1XC1Ev
-  // CHECK-EH-NEXT: ret void
 }
 
-// CHECK-LABEL: define{{.*}} void @_Z5test2b
-// CHECK-EH-LABEL: define{{.*}} void @_Z5test2b
-// CHECK-EH-SAME:  personality i8* bitcast (i32 (...)* @__gxx_personality_v0 
to i8*)
+// CHECK-LABEL: @_Z5test2b(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[X:%.*]] = alloca [[CLASS_X:%.*]], align 1
+// CHECK-NEXT:[[Y:%.*]] = alloca [[CLASS_X]], align 1
+// CHECK-NEXT:[[TMP0:%.*]] = getelementptr inbounds [[CLASS_X]], %class.X* 
[[X]], i32 0, i32 0
+// CHECK-NEXT:call void @llvm.lifetime.start.p0i8(i64 1, i8* nonnull 
[[TMP0]]) #[[ATTR5]]
+// CHECK-NEXT:call void @_ZN1XC1Ev(%class.X* noundef nonnull align 1 
dereferenceable(1) [[X]]) #[[ATTR5]]
+// CHECK-NEXT:[[TMP1:%.*]] = getelementptr inbounds [[CLASS_X]], %class.X* 
[[Y]], i32 0, i32 0
+// CHECK-NEXT:call void @llvm.lifetime.start.p0i8(i64 1, i8* nonnull 
[[TMP1]]) #[[ATTR5]]
+// CHECK-NEXT:call void @_ZN1XC1Ev(%class.X* noundef nonnull align 1 
dereferenceable(1) [[Y]]) #[[ATTR5]]
+// CHECK-NEXT:[[Y_X:%.*]] = select i1 [[B:%.*]], %class.X* [[Y]], 
%class.X* [[X]]
+// CHECK-NEXT:call void @_ZN1XC1ERKS_(%class.X* noundef nonnull align 1 
dereferenceable(1) [[AGG_RESULT:%.*]], %class.X* noundef nonnull align 1 
dereferenceable(1) [[Y_X]]) #[[ATTR5]]
+// CHECK-NEXT:call void @_ZN1XD1Ev(%class.X* noundef nonnull align 1 
dereferenceable(1) [[Y]]) #[[ATTR5]]
+// CHECK-NEXT:call void @llvm.lifetime.end.p0i8(i64 1, i8* nonnull 
[[TMP1]]) #[[ATTR5]]
+// CHECK-NEXT:call void @_ZN1XD1Ev(%class.X* noundef nonnull align 1 
dereferenceable(1) [[X]]) #[[ATTR5]]
+// CHECK-NEXT:call void @llvm.lifetime.end.p0i8(i64 1, i8* nonnull 
[[TMP0]]) #[[ATTR5]]
+// CHECK-NEXT:ret void
+//
+// CHECK-EH-03-LABEL: @_Z5test2b(
+// CHECK-EH-03-NEXT:  entry:
+// CHECK-EH-03-NEXT:[[X:%.*]] = alloca [[CLASS_X:%.*]], align 1
+// CHECK-EH-03-NEXT:[[Y:%.*]] = alloca [[CLASS_X]], align 1
+// CHECK-EH-03-NEXT:[[TMP0:%.*]] = getelementptr inbounds [[CLASS_X]], 
%class.X* [[X]], i32 0, i32 0
+// CHECK-EH-03-NEXT:call void @llvm.lifetime.start.p0i8(i64 1, i8* nonnull 
[[TMP0]]) #[[ATTR7:[0-9]+]]
+// CHECK-EH-03-NEXT:

Re: [clang] 17d9560 - Making the code compliant to the documentation about Floating Point

2021-11-08 Thread Roman Lebedev via cfe-commits
Was the link to the review omitted in the commit message?

On Mon, Nov 8, 2021 at 3:51 PM Zahira Ammarguellat via cfe-commits
 wrote:
>
>
> Author: Zahira Ammarguellat
> Date: 2021-11-08T07:51:29-05:00
> New Revision: 17d9560294eee1eae5e2d3ac1ab84f514318409e
>
> URL: 
> https://github.com/llvm/llvm-project/commit/17d9560294eee1eae5e2d3ac1ab84f514318409e
> DIFF: 
> https://github.com/llvm/llvm-project/commit/17d9560294eee1eae5e2d3ac1ab84f514318409e.diff
>
> LOG: Making the code compliant to the documentation about Floating Point
> support default values for C/C++. FPP-MODEL=PRECISE enables FFP-CONTRACT
> FMA is enabled.
>
> Fix for https://bugs.llvm.org/show_bug.cgi?id=50222
>
> Added:
> clang/test/CodeGen/ffp-model.c
> clang/test/Misc/ffp-contract.c
>
> Modified:
> clang/docs/ReleaseNotes.rst
> clang/docs/UsersManual.rst
> clang/lib/Driver/ToolChains/Clang.cpp
> clang/test/CodeGen/ffp-contract-option.c
> clang/test/CodeGen/ppc-emmintrin.c
> clang/test/CodeGen/ppc-xmmintrin.c
> clang/test/Driver/fp-model.c
>
> Removed:
>
>
>
> 
> diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
> index ba15803e6f48..fe4b563a6d2c 100644
> --- a/clang/docs/ReleaseNotes.rst
> +++ b/clang/docs/ReleaseNotes.rst
> @@ -202,6 +202,16 @@ Arm and AArch64 Support in Clang
>architecture features, but will enable certain optimizations specific to
>Cortex-A57 CPUs and enable the use of a more accurate scheduling model.
>
> +
> +Floating Point Support in Clang
> +---
> +- The -ffp-model=precise now implies -ffp-contract=on rather than
> +  -ffp-contract=fast, and the documentation of these features has been
> +  clarified. Previously, the documentation claimed that -ffp-model=precise 
> was
> +  the default, but this was incorrect because the precise model implied
> +  -ffp-contract=fast, whereas the default behavior is -ffp-contract=on.
> +  -ffp-model=precise is now exactly the default mode of the compiler.
> +
>  Internal API Changes
>  
>
>
> diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
> index 8c6922db6b37..406efb093d55 100644
> --- a/clang/docs/UsersManual.rst
> +++ b/clang/docs/UsersManual.rst
> @@ -1260,8 +1260,49 @@ installed.
>  Controlling Floating Point Behavior
>  ---
>
> -Clang provides a number of ways to control floating point behavior. The 
> options
> -are listed below.
> +Clang provides a number of ways to control floating point behavior, including
> +with command line options and source pragmas. This section
> +describes the various floating point semantic modes and the corresponding 
> options.
> +
> +.. csv-table:: Floating Point Semantic Modes
> +  :header: "Mode", "Values"
> +  :widths: 15, 30, 30
> +
> +  "ffp-exception-behavior", "{ignore, strict, may_trap}",
> +  "fenv_access", "{off, on}", "(none)"
> +  "frounding-math", "{dynamic, tonearest, downward, upward, towardzero}"
> +  "ffp-contract", "{on, off, fast, fast-honor-pragmas}"
> +  "fdenormal-fp-math", "{IEEE, PreserveSign, PositiveZero}"
> +  "fdenormal-fp-math-fp32", "{IEEE, PreserveSign, PositiveZero}"
> +  "fmath-errno", "{on, off}"
> +  "fhonor-nans", "{on, off}"
> +  "fhonor-infinities", "{on, off}"
> +  "fsigned-zeros", "{on, off}"
> +  "freciprocal-math", "{on, off}"
> +  "allow_approximate_fns", "{on, off}"
> +  "fassociative-math", "{on, off}"
> +
> +This table describes the option settings that correspond to the three
> +floating point semantic models: precise (the default), strict, and fast.
> +
> +
> +.. csv-table:: Floating Point Models
> +  :header: "Mode", "Precise", "Strict", "Fast"
> +  :widths: 25, 15, 15, 15
> +
> +  "except_behavior", "ignore", "strict", "ignore"
> +  "fenv_access", "off", "on", "off"
> +  "rounding_mode", "tonearest", "dynamic", "tonearest"
> +  "contract", "on", "off", "fast"
> +  "denormal_fp_math", "IEEE", "IEEE", "PreserveSign"
> +  "denormal_fp32_math", "IEEE","IEEE", "PreserveSign"
> +  "support_math_errno", "on", "on", "off"
> +  "no_honor_nans", "off", "off", "on"
> +  "no_honor_infinities", "off", "off", "on"
> +  "no_signed_zeros", "off", "off", "on"
> +  "allow_reciprocal", "off", "off", "on"
> +  "allow_approximate_fns", "off", "off", "on"
> +  "allow_reassociation", "off", "off", "on"
>
>  .. option:: -ffast-math
>
> @@ -1467,7 +1508,7 @@ Note that floating-point operations performed as part 
> of constant initialization
> and ``fast``.
> Details:
>
> -   * ``precise`` Disables optimizations that are not value-safe on 
> floating-point data, although FP contraction (FMA) is enabled 
> (``-ffp-contract=fast``).  This is the default behavior.
> +   * ``precise`` Disables optimizations that are not value-safe on 
> floating-point data, although FP contraction (FMA) is enabled 
> (``-ffp-contract=on``).  This is the default behavior.
> * ``strict`` 

[clang] 101aaf6 - Revert "[NFC] `IRBuilderBase::CreateAdd()`: place constant onto RHS"

2021-10-27 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-10-27T22:21:37+03:00
New Revision: 101aaf62efef1ee55e0bc9fa78a83d8a4c6fcee6

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

LOG: Revert "[NFC] `IRBuilderBase::CreateAdd()`: place constant onto RHS"

Clang OpenMP codegen tests are failing,
will recommit afterwards.

This reverts commit 4723c9b3c6c46632a5d66e65d198899894b1e2c5.

Added: 


Modified: 
clang/test/CodeGen/builtins-overflow.c
clang/test/CodeGen/builtins-ppc-p10vector.c
clang/test/CodeGen/catch-nullptr-and-nonzero-offset.c
clang/test/CodeGen/complex-convert.c
clang/test/CodeGen/extern-inline.c
clang/test/CodeGen/matrix-type-operators.c
clang/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp
clang/test/CodeGenCXX/virtual-base-cast.cpp
llvm/include/llvm/IR/IRBuilder.h
llvm/test/Instrumentation/InstrProfiling/runtime-counter-relocation.ll
llvm/test/Instrumentation/MemorySanitizer/AArch64/vararg.ll
llvm/test/Instrumentation/MemorySanitizer/Mips/vararg-mips64.ll
llvm/test/Instrumentation/MemorySanitizer/Mips/vararg-mips64el.ll
llvm/test/Instrumentation/MemorySanitizer/PowerPC/vararg-ppc64.ll
llvm/test/Instrumentation/MemorySanitizer/PowerPC/vararg-ppc64le.ll
llvm/test/Instrumentation/MemorySanitizer/SystemZ/vararg.ll
llvm/test/Instrumentation/MemorySanitizer/msan_kernel_basic.ll
llvm/test/Transforms/LoopDistribute/scev-inserted-runtime-check.ll
llvm/test/Transforms/LoopVectorize/AArch64/scalable-strict-fadd.ll
llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-gep.ll
llvm/test/Transforms/LoopVectorize/ARM/mve-gather-scatter-tailpred.ll
llvm/test/Transforms/LoopVectorize/X86/conversion-cost.ll
llvm/test/Transforms/LoopVectorize/X86/load-deref-pred.ll
llvm/test/Transforms/LoopVectorize/X86/pr36524.ll
llvm/test/Transforms/LoopVectorize/first-order-recurrence-complex.ll
llvm/test/Transforms/LoopVectorize/float-minmax-instruction-flag.ll
llvm/test/Transforms/LoopVectorize/if-pred-stores.ll
llvm/test/Transforms/LoopVectorize/induction-step.ll
llvm/test/Transforms/LoopVectorize/induction.ll
llvm/test/Transforms/LoopVectorize/pr30654-phiscev-sext-trunc.ll
llvm/test/Transforms/LoopVectorize/pr44488-predication.ll
llvm/test/Transforms/LoopVectorize/pr45259.ll
llvm/test/Transforms/LoopVectorize/runtime-check-small-clamped-bounds.ll
llvm/test/Transforms/LoopVectorize/scalar_after_vectorization.ll
llvm/test/Transforms/LoopVersioning/wrapping-pointer-versioning.ll

Removed: 




diff  --git a/clang/test/CodeGen/builtins-overflow.c 
b/clang/test/CodeGen/builtins-overflow.c
index f7f5a577e1dc3..636a571d13640 100644
--- a/clang/test/CodeGen/builtins-overflow.c
+++ b/clang/test/CodeGen/builtins-overflow.c
@@ -484,7 +484,7 @@ int test_mixed_sign_mull_overflow(int x, unsigned y) {
 // CHECK-NEXT:  [[UnsignedOFlow:%.*]] = extractvalue { i32, i1 } %{{.*}}, 1
 // CHECK-NEXT:  [[UnsignedResult:%.*]] = extractvalue { i32, i1 } %{{.*}}, 0
 // CHECK-NEXT:  [[IsNegZext:%.*]] = zext i1 [[IsNeg]] to i32
-// CHECK-NEXT:  [[MaxResult:%.*]] = add i32 [[IsNegZext]], 2147483647
+// CHECK-NEXT:  [[MaxResult:%.*]] = add i32 2147483647, [[IsNegZext]]
 // CHECK-NEXT:  [[SignedOFlow:%.*]] = icmp ugt i32 [[UnsignedResult]], 
[[MaxResult]]
 // CHECK-NEXT:  [[OFlow:%.*]] = or i1 [[UnsignedOFlow]], [[SignedOFlow]]
 // CHECK-NEXT:  [[NegativeResult:%.*]] = sub i32 0, [[UnsignedResult]]
@@ -523,7 +523,7 @@ int test_mixed_sign_mull_overflow_unsigned(int x, unsigned 
y) {
 int test_mixed_sign_mull_overflow_swapped(int x, unsigned y) {
 // CHECK: @test_mixed_sign_mull_overflow_swapped
 // CHECK:  call { i32, i1 } @llvm.umul.with.overflow.i32
-// CHECK:  add i32 [[Op0:%.*]], 2147483647
+// CHECK:  add i32 2147483647
   int result;
   if (__builtin_mul_overflow(y, x, ))
 return LongErrorCode;
@@ -533,7 +533,7 @@ int test_mixed_sign_mull_overflow_swapped(int x, unsigned 
y) {
 long long test_mixed_sign_mulll_overflow(long long x, unsigned long long y) {
 // CHECK: @test_mixed_sign_mulll_overflow
 // CHECK:  call { i64, i1 } @llvm.umul.with.overflow.i64
-// CHECK:  add i64 [[Op0:%.*]], 92233720368547
+// CHECK:  add i64 92233720368547
   long long result;
   if (__builtin_mul_overflow(x, y, ))
 return LongLongErrorCode;
@@ -543,7 +543,7 @@ long long test_mixed_sign_mulll_overflow(long long x, 
unsigned long long y) {
 long long test_mixed_sign_mulll_overflow_swapped(long long x, unsigned long 
long y) {
 // CHECK: @test_mixed_sign_mulll_overflow_swapped
 // CHECK:  call { i64, i1 } @llvm.umul.with.overflow.i64
-// CHECK:  add i64 [[Op0:%.*]], 92233720368547
+// CHECK:  add i64 92233720368547
   long long result;
   if (__builtin_mul_overflow(y, x, ))
 return LongLongErrorCode;
@@ -553,7 

[clang] 4723c9b - [NFC] `IRBuilderBase::CreateAdd()`: place constant onto RHS

2021-10-27 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-10-27T21:34:38+03:00
New Revision: 4723c9b3c6c46632a5d66e65d198899894b1e2c5

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

LOG: [NFC] `IRBuilderBase::CreateAdd()`: place constant onto RHS

Added: 


Modified: 
clang/test/CodeGen/builtins-overflow.c
clang/test/CodeGen/builtins-ppc-p10vector.c
clang/test/CodeGen/catch-nullptr-and-nonzero-offset.c
clang/test/CodeGen/complex-convert.c
clang/test/CodeGen/extern-inline.c
clang/test/CodeGen/matrix-type-operators.c
clang/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp
clang/test/CodeGenCXX/virtual-base-cast.cpp
llvm/include/llvm/IR/IRBuilder.h
llvm/test/Instrumentation/InstrProfiling/runtime-counter-relocation.ll
llvm/test/Instrumentation/MemorySanitizer/AArch64/vararg.ll
llvm/test/Instrumentation/MemorySanitizer/Mips/vararg-mips64.ll
llvm/test/Instrumentation/MemorySanitizer/Mips/vararg-mips64el.ll
llvm/test/Instrumentation/MemorySanitizer/PowerPC/vararg-ppc64.ll
llvm/test/Instrumentation/MemorySanitizer/PowerPC/vararg-ppc64le.ll
llvm/test/Instrumentation/MemorySanitizer/SystemZ/vararg.ll
llvm/test/Instrumentation/MemorySanitizer/msan_kernel_basic.ll
llvm/test/Transforms/LoopDistribute/scev-inserted-runtime-check.ll
llvm/test/Transforms/LoopVectorize/AArch64/scalable-strict-fadd.ll
llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-gep.ll
llvm/test/Transforms/LoopVectorize/ARM/mve-gather-scatter-tailpred.ll
llvm/test/Transforms/LoopVectorize/X86/conversion-cost.ll
llvm/test/Transforms/LoopVectorize/X86/load-deref-pred.ll
llvm/test/Transforms/LoopVectorize/X86/pr36524.ll
llvm/test/Transforms/LoopVectorize/first-order-recurrence-complex.ll
llvm/test/Transforms/LoopVectorize/float-minmax-instruction-flag.ll
llvm/test/Transforms/LoopVectorize/if-pred-stores.ll
llvm/test/Transforms/LoopVectorize/induction-step.ll
llvm/test/Transforms/LoopVectorize/induction.ll
llvm/test/Transforms/LoopVectorize/pr30654-phiscev-sext-trunc.ll
llvm/test/Transforms/LoopVectorize/pr44488-predication.ll
llvm/test/Transforms/LoopVectorize/pr45259.ll
llvm/test/Transforms/LoopVectorize/runtime-check-small-clamped-bounds.ll
llvm/test/Transforms/LoopVectorize/scalar_after_vectorization.ll
llvm/test/Transforms/LoopVersioning/wrapping-pointer-versioning.ll

Removed: 




diff  --git a/clang/test/CodeGen/builtins-overflow.c 
b/clang/test/CodeGen/builtins-overflow.c
index 636a571d13640..f7f5a577e1dc3 100644
--- a/clang/test/CodeGen/builtins-overflow.c
+++ b/clang/test/CodeGen/builtins-overflow.c
@@ -484,7 +484,7 @@ int test_mixed_sign_mull_overflow(int x, unsigned y) {
 // CHECK-NEXT:  [[UnsignedOFlow:%.*]] = extractvalue { i32, i1 } %{{.*}}, 1
 // CHECK-NEXT:  [[UnsignedResult:%.*]] = extractvalue { i32, i1 } %{{.*}}, 0
 // CHECK-NEXT:  [[IsNegZext:%.*]] = zext i1 [[IsNeg]] to i32
-// CHECK-NEXT:  [[MaxResult:%.*]] = add i32 2147483647, [[IsNegZext]]
+// CHECK-NEXT:  [[MaxResult:%.*]] = add i32 [[IsNegZext]], 2147483647
 // CHECK-NEXT:  [[SignedOFlow:%.*]] = icmp ugt i32 [[UnsignedResult]], 
[[MaxResult]]
 // CHECK-NEXT:  [[OFlow:%.*]] = or i1 [[UnsignedOFlow]], [[SignedOFlow]]
 // CHECK-NEXT:  [[NegativeResult:%.*]] = sub i32 0, [[UnsignedResult]]
@@ -523,7 +523,7 @@ int test_mixed_sign_mull_overflow_unsigned(int x, unsigned 
y) {
 int test_mixed_sign_mull_overflow_swapped(int x, unsigned y) {
 // CHECK: @test_mixed_sign_mull_overflow_swapped
 // CHECK:  call { i32, i1 } @llvm.umul.with.overflow.i32
-// CHECK:  add i32 2147483647
+// CHECK:  add i32 [[Op0:%.*]], 2147483647
   int result;
   if (__builtin_mul_overflow(y, x, ))
 return LongErrorCode;
@@ -533,7 +533,7 @@ int test_mixed_sign_mull_overflow_swapped(int x, unsigned 
y) {
 long long test_mixed_sign_mulll_overflow(long long x, unsigned long long y) {
 // CHECK: @test_mixed_sign_mulll_overflow
 // CHECK:  call { i64, i1 } @llvm.umul.with.overflow.i64
-// CHECK:  add i64 92233720368547
+// CHECK:  add i64 [[Op0:%.*]], 92233720368547
   long long result;
   if (__builtin_mul_overflow(x, y, ))
 return LongLongErrorCode;
@@ -543,7 +543,7 @@ long long test_mixed_sign_mulll_overflow(long long x, 
unsigned long long y) {
 long long test_mixed_sign_mulll_overflow_swapped(long long x, unsigned long 
long y) {
 // CHECK: @test_mixed_sign_mulll_overflow_swapped
 // CHECK:  call { i64, i1 } @llvm.umul.with.overflow.i64
-// CHECK:  add i64 92233720368547
+// CHECK:  add i64 [[Op0:%.*]], 92233720368547
   long long result;
   if (__builtin_mul_overflow(y, x, ))
 return LongLongErrorCode;
@@ -553,7 +553,7 @@ long long test_mixed_sign_mulll_overflow_swapped(long long 
x, unsigned long long
 long long 

[clang] f3190de - [IR] `IRBuilderBase::CreateAnd()`: short-circuit `x & 0` --> `0`

2021-10-27 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-10-27T18:01:06+03:00
New Revision: f3190dedeef9da2109ea57e4cb372f295ff53b88

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

LOG: [IR] `IRBuilderBase::CreateAnd()`: short-circuit `x & 0` --> `0`

https://alive2.llvm.org/ce/z/YzPhSb

Refs. https://reviews.llvm.org/D109368#3089809

Added: 


Modified: 
clang/test/CodeGen/catch-nullptr-and-nonzero-offset.c
llvm/include/llvm/IR/IRBuilder.h
llvm/test/Transforms/LoopPredication/basic.ll
llvm/test/Transforms/LoopPredication/reverse.ll

Removed: 




diff  --git a/clang/test/CodeGen/catch-nullptr-and-nonzero-offset.c 
b/clang/test/CodeGen/catch-nullptr-and-nonzero-offset.c
index 12c4893ae1d1..191a6dac0a6b 100644
--- a/clang/test/CodeGen/catch-nullptr-and-nonzero-offset.c
+++ b/clang/test/CodeGen/catch-nullptr-and-nonzero-offset.c
@@ -172,13 +172,13 @@ char *nullptr_var(unsigned long offset) {
   // CHECK-SANITIZE-NEXT:   %[[COMPUTED_OFFSET:.*]] = extractvalue 
{ i64, i1 } %[[COMPUTED_OFFSET_AGGREGATE]], 0, !nosanitize
   // CHECK-SANITIZE-NEXT:   %[[COMPUTED_GEP:.*]] = add i64 0, 
%[[COMPUTED_OFFSET]], !nosanitize
   // CHECK-SANITIZE-NEXT:   %[[COMPUTED_GEP_IS_NOT_NULL:.*]] = 
icmp ne i64 %[[COMPUTED_GEP]], 0, !nosanitize
-  // CHECK-SANITIZE-C-NEXT: 
%[[BOTH_POINTERS_ARE_NULL_OR_BOTH_ARE_NONNULL:.*]] = and i1 
%[[COMPUTED_GEP_IS_NOT_NULL]], false, !nosanitize
   // CHECK-SANITIZE-CPP-NEXT:   
%[[BOTH_POINTERS_ARE_NULL_OR_BOTH_ARE_NONNULL:.*]] = icmp eq i1 false, 
%[[COMPUTED_GEP_IS_NOT_NULL]], !nosanitize
   // CHECK-SANITIZE-NEXT:   
%[[COMPUTED_OFFSET_DID_NOT_OVERFLOW:.*]] = xor i1 
%[[COMPUTED_OFFSET_OVERFLOWED]], true, !nosanitize
   // CHECK-SANITIZE-NEXT:   %[[COMPUTED_GEP_IS_UGE_BASE:.*]] = 
icmp uge i64 %[[COMPUTED_GEP]], 0, !nosanitize
   // CHECK-SANITIZE-NEXT:   %[[GEP_DID_NOT_OVERFLOW:.*]] = and i1 
%[[COMPUTED_GEP_IS_UGE_BASE]], %[[COMPUTED_OFFSET_DID_NOT_OVERFLOW]], 
!nosanitize
-  // CHECK-SANITIZE-NEXT:   %[[GEP_IS_OKAY:.*]] = and i1 
%[[BOTH_POINTERS_ARE_NULL_OR_BOTH_ARE_NONNULL]], %[[GEP_DID_NOT_OVERFLOW]], 
!nosanitize
-  // CHECK-SANITIZE-NEXT:   br i1 %[[GEP_IS_OKAY]], label 
%[[CONT:.*]], label %[[HANDLER_POINTER_OVERFLOW:[^,]+]],{{.*}} !nosanitize
+  // CHECK-SANITIZE-CPP-NEXT:   %[[GEP_IS_OKAY:.*]] = and i1 
%[[BOTH_POINTERS_ARE_NULL_OR_BOTH_ARE_NONNULL]], %[[GEP_DID_NOT_OVERFLOW]], 
!nosanitize
+  // CHECK-SANITIZE-C-NEXT: br i1 false, label %[[CONT:.*]], label 
%[[HANDLER_POINTER_OVERFLOW:[^,]+]],{{.*}} !nosanitize
+  // CHECK-SANITIZE-CPP-NEXT:   br i1 %[[GEP_IS_OKAY]], label 
%[[CONT:.*]], label %[[HANDLER_POINTER_OVERFLOW:[^,]+]],{{.*}} !nosanitize
   // CHECK-SANITIZE:  [[HANDLER_POINTER_OVERFLOW]]:
   // CHECK-SANITIZE-NORECOVER-NEXT: call void 
@__ubsan_handle_pointer_overflow_abort(i8* bitcast ({ {{{.*}}} }* @[[LINE_500]] 
to i8*), i64 0, i64 %[[COMPUTED_GEP]])
   // CHECK-SANITIZE-RECOVER-NEXT:   call void 
@__ubsan_handle_pointer_overflow(i8* bitcast ({ {{{.*}}} }* @[[LINE_500]] to 
i8*), i64 0, i64 %[[COMPUTED_GEP]])

diff  --git a/llvm/include/llvm/IR/IRBuilder.h 
b/llvm/include/llvm/IR/IRBuilder.h
index 7b3a4c6d714a..c7899681835e 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -1362,9 +1362,13 @@ class IRBuilderBase {
   Value *CreateAnd(Value *LHS, Value *RHS, const Twine  = "") {
 if (!isa(RHS) && isa(LHS))
   std::swap(LHS, RHS);
-if (auto *RC = dyn_cast(RHS)) {
-  if (isa(RC) && cast(RC)->isMinusOne())
+if (auto RCI = dyn_cast(RHS)) {
+  if (RCI->isZero())
+return RHS; // LHS & 0 -> 0
+  if (RCI->isMinusOne())
 return LHS;  // LHS & -1 -> LHS
+}
+if (auto *RC = dyn_cast(RHS)) {
   if (auto *LC = dyn_cast(LHS))
 return Insert(Folder.CreateAnd(LC, RC), Name);
 }

diff  --git a/llvm/test/Transforms/LoopPredication/basic.ll 
b/llvm/test/Transforms/LoopPredication/basic.ll
index 9972caae5713..1f64e4383c51 100644
--- a/llvm/test/Transforms/LoopPredication/basic.ll
+++ b/llvm/test/Transforms/LoopPredication/basic.ll
@@ -1554,12 +1554,11 @@ define i32 @provably_taken(i32* %array, i32* 
%length.ptr) {
 ; CHECK-NEXT:  loop.preheader:
 ; CHECK-NEXT:[[LENGTH:%.*]] = load i32, i32* [[LENGTH_PTR:%.*]], align 4, 
!range [[RNG1:![0-9]+]]
 ; CHECK-NEXT:[[TMP0:%.*]] = icmp ult i32 0, [[LENGTH]]
-; CHECK-NEXT:[[TMP1:%.*]] = and i1 [[TMP0]], false
 ; CHECK-NEXT:br label [[LOOP:%.*]]
 ; CHECK:   loop:
 ; CHECK-NEXT:[[LOOP_ACC:%.*]] = phi i32 [ [[LOOP_ACC_NEXT:%.*]], [[LOOP]] 
], [ 0, [[LOOP_PREHEADER:%.*]] ]
 ; CHECK-NEXT:[[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[LOOP]] 

[clang] 749581d - [IR] `IRBuilderBase::CreateAnd()`: fix short-circuiting for constant on LHS

2021-10-27 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-10-27T18:01:06+03:00
New Revision: 749581d21f2b3f53e4fca4eb8728c942d646893b

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

LOG: [IR] `IRBuilderBase::CreateAnd()`: fix short-circuiting for constant on LHS

Refs. https://reviews.llvm.org/D109368#3089809

Added: 


Modified: 
clang/test/CodeGen/arm-mve-intrinsics/vadc.c
clang/test/CodeGen/catch-nullptr-and-nonzero-offset.c
clang/test/CodeGenCXX/ext-vector-type-conditional.cpp
clang/test/CodeGenObjC/ubsan-nullability.m
llvm/include/llvm/IR/IRBuilder.h
llvm/test/Transforms/LoopIdiom/X86/left-shift-until-bittest.ll
llvm/test/Transforms/LoopPredication/basic.ll
llvm/test/Transforms/LoopPredication/basic_widenable_branch_guards.ll
llvm/test/Transforms/LoopPredication/invariant_load.ll
llvm/test/Transforms/LowerTypeTests/import.ll

Removed: 




diff  --git a/clang/test/CodeGen/arm-mve-intrinsics/vadc.c 
b/clang/test/CodeGen/arm-mve-intrinsics/vadc.c
index 5e428efd1b29c..29d17e73eb341 100644
--- a/clang/test/CodeGen/arm-mve-intrinsics/vadc.c
+++ b/clang/test/CodeGen/arm-mve-intrinsics/vadc.c
@@ -9,7 +9,7 @@
 // CHECK-NEXT:[[TMP0:%.*]] = call { <4 x i32>, i32 } 
@llvm.arm.mve.vadc.v4i32(<4 x i32> [[A:%.*]], <4 x i32> [[B:%.*]], i32 0)
 // CHECK-NEXT:[[TMP1:%.*]] = extractvalue { <4 x i32>, i32 } [[TMP0]], 1
 // CHECK-NEXT:[[TMP2:%.*]] = lshr i32 [[TMP1]], 29
-// CHECK-NEXT:[[TMP3:%.*]] = and i32 1, [[TMP2]]
+// CHECK-NEXT:[[TMP3:%.*]] = and i32 [[TMP2]], 1
 // CHECK-NEXT:store i32 [[TMP3]], i32* [[CARRY_OUT:%.*]], align 4
 // CHECK-NEXT:[[TMP4:%.*]] = extractvalue { <4 x i32>, i32 } [[TMP0]], 0
 // CHECK-NEXT:ret <4 x i32> [[TMP4]]
@@ -30,7 +30,7 @@ int32x4_t test_vadciq_s32(int32x4_t a, int32x4_t b, unsigned 
*carry_out)
 // CHECK-NEXT:[[TMP2:%.*]] = call { <4 x i32>, i32 } 
@llvm.arm.mve.vadc.v4i32(<4 x i32> [[A:%.*]], <4 x i32> [[B:%.*]], i32 [[TMP1]])
 // CHECK-NEXT:[[TMP3:%.*]] = extractvalue { <4 x i32>, i32 } [[TMP2]], 1
 // CHECK-NEXT:[[TMP4:%.*]] = lshr i32 [[TMP3]], 29
-// CHECK-NEXT:[[TMP5:%.*]] = and i32 1, [[TMP4]]
+// CHECK-NEXT:[[TMP5:%.*]] = and i32 [[TMP4]], 1
 // CHECK-NEXT:store i32 [[TMP5]], i32* [[CARRY]], align 4
 // CHECK-NEXT:[[TMP6:%.*]] = extractvalue { <4 x i32>, i32 } [[TMP2]], 0
 // CHECK-NEXT:ret <4 x i32> [[TMP6]]
@@ -51,7 +51,7 @@ uint32x4_t test_vadcq_u32(uint32x4_t a, uint32x4_t b, 
unsigned *carry)
 // CHECK-NEXT:[[TMP2:%.*]] = call { <4 x i32>, i32 } 
@llvm.arm.mve.vadc.predicated.v4i32.v4i1(<4 x i32> [[INACTIVE:%.*]], <4 x i32> 
[[A:%.*]], <4 x i32> [[B:%.*]], i32 0, <4 x i1> [[TMP1]])
 // CHECK-NEXT:[[TMP3:%.*]] = extractvalue { <4 x i32>, i32 } [[TMP2]], 1
 // CHECK-NEXT:[[TMP4:%.*]] = lshr i32 [[TMP3]], 29
-// CHECK-NEXT:[[TMP5:%.*]] = and i32 1, [[TMP4]]
+// CHECK-NEXT:[[TMP5:%.*]] = and i32 [[TMP4]], 1
 // CHECK-NEXT:store i32 [[TMP5]], i32* [[CARRY_OUT:%.*]], align 4
 // CHECK-NEXT:[[TMP6:%.*]] = extractvalue { <4 x i32>, i32 } [[TMP2]], 0
 // CHECK-NEXT:ret <4 x i32> [[TMP6]]
@@ -74,7 +74,7 @@ uint32x4_t test_vadciq_m_u32(uint32x4_t inactive, uint32x4_t 
a, uint32x4_t b, un
 // CHECK-NEXT:[[TMP4:%.*]] = call { <4 x i32>, i32 } 
@llvm.arm.mve.vadc.predicated.v4i32.v4i1(<4 x i32> [[INACTIVE:%.*]], <4 x i32> 
[[A:%.*]], <4 x i32> [[B:%.*]], i32 [[TMP1]], <4 x i1> [[TMP3]])
 // CHECK-NEXT:[[TMP5:%.*]] = extractvalue { <4 x i32>, i32 } [[TMP4]], 1
 // CHECK-NEXT:[[TMP6:%.*]] = lshr i32 [[TMP5]], 29
-// CHECK-NEXT:[[TMP7:%.*]] = and i32 1, [[TMP6]]
+// CHECK-NEXT:[[TMP7:%.*]] = and i32 [[TMP6]], 1
 // CHECK-NEXT:store i32 [[TMP7]], i32* [[CARRY]], align 4
 // CHECK-NEXT:[[TMP8:%.*]] = extractvalue { <4 x i32>, i32 } [[TMP4]], 0
 // CHECK-NEXT:ret <4 x i32> [[TMP8]]
@@ -93,7 +93,7 @@ int32x4_t test_vadcq_m_s32(int32x4_t inactive, int32x4_t a, 
int32x4_t b, unsigne
 // CHECK-NEXT:[[TMP0:%.*]] = call { <4 x i32>, i32 } 
@llvm.arm.mve.vsbc.v4i32(<4 x i32> [[A:%.*]], <4 x i32> [[B:%.*]], i32 0)
 // CHECK-NEXT:[[TMP1:%.*]] = extractvalue { <4 x i32>, i32 } [[TMP0]], 1
 // CHECK-NEXT:[[TMP2:%.*]] = lshr i32 [[TMP1]], 29
-// CHECK-NEXT:[[TMP3:%.*]] = and i32 1, [[TMP2]]
+// CHECK-NEXT:[[TMP3:%.*]] = and i32 [[TMP2]], 1
 // CHECK-NEXT:store i32 [[TMP3]], i32* [[CARRY_OUT:%.*]], align 4
 // CHECK-NEXT:[[TMP4:%.*]] = extractvalue { <4 x i32>, i32 } [[TMP0]], 0
 // CHECK-NEXT:ret <4 x i32> [[TMP4]]
@@ -111,7 +111,7 @@ int32x4_t test_vsbciq_s32(int32x4_t a, int32x4_t b, 
unsigned *carry_out) {
 // CHECK-NEXT:[[TMP0:%.*]] = call { <4 x i32>, i32 } 
@llvm.arm.mve.vsbc.v4i32(<4 x i32> [[A:%.*]], <4 x i32> [[B:%.*]], i32 0)
 // CHECK-NEXT:[[TMP1:%.*]] = extractvalue { <4 x i32>, 

[clang] f3c2094 - [clang] `aligned_alloc` allocation function specifies alignment in first arg, manifest that knowledge

2021-09-10 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-09-10T20:49:29+03:00
New Revision: f3c2094d8c112f40923ef45953f66c4b2ecb6d01

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

LOG: [clang] `aligned_alloc` allocation function specifies alignment in first 
arg, manifest that knowledge

Mainly, if a constant value was passed as an alignment,
then we correctly annotate the alignment of the returned value
of @aligned_alloc. And if it wasn't constant,
then we also don't loose that, but emit an assumption.

Added: 


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

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 59726ad67fbb..cc3417d4ccba 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -15150,6 +15150,10 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl 
*FD) {
 // Add known guaranteed alignment for allocation functions.
 switch (BuiltinID) {
 case Builtin::BIaligned_alloc:
+  if (!FD->hasAttr())
+FD->addAttr(AllocAlignAttr::CreateImplicit(Context, ParamIdx(1, FD),
+   FD->getLocation()));
+  LLVM_FALLTHROUGH;
 case Builtin::BIcalloc:
 case Builtin::BImalloc:
 case Builtin::BImemalign:

diff  --git a/clang/test/CodeGen/alloc-fns-alignment.c 
b/clang/test/CodeGen/alloc-fns-alignment.c
index 1ce0cfbad97b..b19cf867f74c 100644
--- a/clang/test/CodeGen/alloc-fns-alignment.c
+++ b/clang/test/CodeGen/alloc-fns-alignment.c
@@ -48,13 +48,14 @@ void *aligned_alloc_large_constant_test(size_t n) {
 // ALIGN16: align 16 i8* @realloc
 
 // CHECK-LABEL: @aligned_alloc_variable_test
-// ALIGN16: align 16 i8* @aligned_alloc
+// ALIGN16:  %[[ALLOCATED:.*]] = call align 16 i8* 
@aligned_alloc({{i32|i64}} %[[ALIGN:.*]], {{i32|i64}} %[[NBYTES:.*]])
+// ALIGN16-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* %[[ALLOCATED]], 
{{i32|i64}} %[[ALIGN]]) ]
 
 // CHECK-LABEL: @aligned_alloc_constant_test
 // ALIGN16: align 16 i8* @aligned_alloc
 
 // CHECK-LABEL: @aligned_alloc_large_constant_test
-// ALIGN16: align 16 i8* @aligned_alloc
+// ALIGN16: align 4096 i8* @aligned_alloc
 
 // CHECK-LABEL: @malloc_test
 // ALIGN8: align 8 i8* @malloc
@@ -72,7 +73,7 @@ void *aligned_alloc_large_constant_test(size_t n) {
 // ALIGN8: align 8 i8* @aligned_alloc
 
 // CHECK-LABEL: @aligned_alloc_large_constant_test
-// ALIGN8: align 8 i8* @aligned_alloc
+// ALIGN8: align 4096 i8* @aligned_alloc
 
 // NOBUILTIN-MALLOC: declare i8* @malloc
 // NOBUILTIN-CALLOC: declare i8* @calloc



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


[clang] 85ba583 - [NFCI][clang] Move allocation alignment manifestation for malloc-like into Sema from Codegen

2021-09-10 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-09-10T20:49:28+03:00
New Revision: 85ba583eba1902c386a55f5565f3c721bd6bcb23

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

LOG: [NFCI][clang] Move allocation alignment manifestation for malloc-like into 
Sema from Codegen

... so that it happens right next to 
`AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction()`,
which is good for consistency.

Added: 


Modified: 
clang/lib/CodeGen/CGCall.cpp
clang/lib/Sema/SemaDecl.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 1ddd4d160b4bd..deb688513fd18 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -2066,24 +2066,6 @@ void CodeGenModule::ConstructAttributeList(StringRef 
Name,
   // allows it to work on indirect virtual function calls.
   if (AttrOnCallSite && TargetDecl->hasAttr())
 FuncAttrs.addAttribute(llvm::Attribute::NoMerge);
-
-  // Add known guaranteed alignment for allocation functions.
-  if (unsigned BuiltinID = Fn->getBuiltinID()) {
-switch (BuiltinID) {
-case Builtin::BIaligned_alloc:
-case Builtin::BIcalloc:
-case Builtin::BImalloc:
-case Builtin::BImemalign:
-case Builtin::BIrealloc:
-case Builtin::BIstrdup:
-case Builtin::BIstrndup:
-  RetAttrs.addAlignmentAttr(Context.getTargetInfo().getNewAlign() /
-Context.getTargetInfo().getCharWidth());
-  break;
-default:
-  break;
-}
-  }
 }
 
 // 'const', 'pure' and 'noalias' attributed functions are also nounwind.

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 92c1a37fdab96..59726ad67fbb6 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -15146,6 +15146,30 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl 
*FD) {
   else
 FD->addAttr(CUDAHostAttr::CreateImplicit(Context, FD->getLocation()));
 }
+
+// Add known guaranteed alignment for allocation functions.
+switch (BuiltinID) {
+case Builtin::BIaligned_alloc:
+case Builtin::BIcalloc:
+case Builtin::BImalloc:
+case Builtin::BImemalign:
+case Builtin::BIrealloc:
+case Builtin::BIstrdup:
+case Builtin::BIstrndup: {
+  if (!FD->hasAttr()) {
+unsigned NewAlign = Context.getTargetInfo().getNewAlign() /
+Context.getTargetInfo().getCharWidth();
+IntegerLiteral *Alignment = IntegerLiteral::Create(
+Context, Context.MakeIntValue(NewAlign, Context.UnsignedIntTy),
+Context.UnsignedIntTy, FD->getLocation());
+FD->addAttr(AssumeAlignedAttr::CreateImplicit(
+Context, Alignment, /*Offset=*/nullptr, FD->getLocation()));
+  }
+  break;
+}
+default:
+  break;
+}
   }
 
   AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction(FD);



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


[clang] 50d7ecc - [NFC][clang] Improve test coverage for alignment manifestation on aligned allocation functions

2021-09-10 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-09-10T20:49:28+03:00
New Revision: 50d7ecc560b27d258c921abe39211926d46fbcff

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

LOG: [NFC][clang] Improve test coverage for alignment manifestation on aligned 
allocation functions

Added: 


Modified: 
clang/test/CodeGen/alloc-fns-alignment.c

Removed: 




diff  --git a/clang/test/CodeGen/alloc-fns-alignment.c 
b/clang/test/CodeGen/alloc-fns-alignment.c
index d2f9b467196a7..1ce0cfbad97b0 100644
--- a/clang/test/CodeGen/alloc-fns-alignment.c
+++ b/clang/test/CodeGen/alloc-fns-alignment.c
@@ -5,12 +5,14 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-malloc  
-emit-llvm < %s  | FileCheck %s --check-prefix=NOBUILTIN-MALLOC
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-calloc  
-emit-llvm < %s  | FileCheck %s --check-prefix=NOBUILTIN-CALLOC
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-realloc 
-emit-llvm < %s  | FileCheck %s --check-prefix=NOBUILTIN-REALLOC
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-aligned_alloc 
-emit-llvm < %s  | FileCheck %s --check-prefix=NOBUILTIN-ALIGNED_ALLOC
 
 typedef __SIZE_TYPE__ size_t;
 
 void *malloc(size_t);
 void *calloc(size_t, size_t);
 void *realloc(void *, size_t);
+void *aligned_alloc(size_t, size_t);
 
 void *malloc_test(size_t n) {
   return malloc(n);
@@ -20,16 +22,59 @@ void *calloc_test(size_t n) {
   return calloc(1, n);
 }
 
-void *raalloc_test(void *p, size_t n) {
+void *realloc_test(void *p, size_t n) {
   return realloc(p, n);
 }
 
+void *aligned_alloc_variable_test(size_t n, size_t a) {
+  return aligned_alloc(a, n);
+}
+
+void *aligned_alloc_constant_test(size_t n) {
+  return aligned_alloc(8, n);
+}
+
+void *aligned_alloc_large_constant_test(size_t n) {
+  return aligned_alloc(4096, n);
+}
+
+// CHECK-LABEL: @malloc_test
 // ALIGN16: align 16 i8* @malloc
+
+// CHECK-LABEL: @calloc_test
 // ALIGN16: align 16 i8* @calloc
+
+// CHECK-LABEL: @realloc_test
 // ALIGN16: align 16 i8* @realloc
+
+// CHECK-LABEL: @aligned_alloc_variable_test
+// ALIGN16: align 16 i8* @aligned_alloc
+
+// CHECK-LABEL: @aligned_alloc_constant_test
+// ALIGN16: align 16 i8* @aligned_alloc
+
+// CHECK-LABEL: @aligned_alloc_large_constant_test
+// ALIGN16: align 16 i8* @aligned_alloc
+
+// CHECK-LABEL: @malloc_test
 // ALIGN8: align 8 i8* @malloc
+
+// CHECK-LABEL: @calloc_test
 // ALIGN8: align 8 i8* @calloc
+
+// CHECK-LABEL: @realloc_test
 // ALIGN8: align 8 i8* @realloc
+
+// CHECK-LABEL: @aligned_alloc_variable_test
+// ALIGN8: align 8 i8* @aligned_alloc
+
+// CHECK-LABEL: @aligned_alloc_constant_test
+// ALIGN8: align 8 i8* @aligned_alloc
+
+// CHECK-LABEL: @aligned_alloc_large_constant_test
+// ALIGN8: align 8 i8* @aligned_alloc
+
 // NOBUILTIN-MALLOC: declare i8* @malloc
 // NOBUILTIN-CALLOC: declare i8* @calloc
 // NOBUILTIN-REALLOC: declare i8* @realloc
+// NOBUILTIN-ALIGNED_ALLOC: declare i8* @aligned_alloc



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


[clang] 564d85e - The maximal representable alignment in LLVM IR is 1GiB, not 512MiB

2021-08-26 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-08-26T12:53:39+03:00
New Revision: 564d85e090afdaac6475d43708d77a7fa0cf5301

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

LOG: The maximal representable alignment in LLVM IR is 1GiB, not 512MiB

In LLVM IR, `AlignmentBitfieldElementT` is 5-bit wide
But that means that the maximal alignment exponent is `(1<<5)-2`,
which is `30`, not `29`. And indeed, alignment of `1073741824`
roundtrips IR serialization-deserialization.

While this doesn't seem all that important, this doubles
the maximal supported alignment from 512MiB to 1GiB,
and there's actually one noticeable use-case for that;
On X86, the huge pages can have sizes of 2MiB and 1GiB (!).

So while this doesn't add support for truly huge alignments,
which i think we can easily-ish do if wanted, i think this adds
zero-cost support for a not-trivially-dismissable case.

I don't believe we need any upgrade infrastructure,
and since we don't explicitly record the IR version,
we don't need to bump one either.

As @craig.topper speculates in D108661#2963519,
this might be an artificial limit imposed by the original implementation
of the `getAlignment()` functions.

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

Added: 
llvm/test/CodeGen/MIR/X86/load-with-1gb-alignment.mir

Modified: 
clang/include/clang/Sema/Sema.h
clang/test/CXX/drs/dr6xx.cpp
clang/test/CodeGen/builtin-assume-aligned.c

clang/test/CodeGen/catch-alignment-assumption-attribute-align_value-on-paramvar.cpp

clang/test/CodeGen/catch-alignment-assumption-builtin_assume_aligned-three-params-variable.cpp

clang/test/CodeGen/catch-alignment-assumption-builtin_assume_aligned-three-params.cpp

clang/test/CodeGen/catch-alignment-assumption-builtin_assume_aligned-two-params.cpp
clang/test/CodeGen/catch-alignment-assumption-openmp.cpp
clang/test/Sema/alloc-align-attr.c
clang/test/Sema/attr-aligned.c
clang/test/Sema/builtin-assume-aligned.c
clang/test/SemaCXX/alloc-align-attr.cpp
llvm/include/llvm/IR/Instruction.h
llvm/include/llvm/IR/Value.h
llvm/test/Assembler/align-inst-alloca.ll
llvm/test/Assembler/align-inst-load.ll
llvm/test/Assembler/align-inst-store.ll
llvm/test/Assembler/align-inst.ll
llvm/test/Bitcode/inalloca.ll
llvm/test/Transforms/Attributor/ArgumentPromotion/live_called_from_dead.ll
llvm/test/Transforms/Attributor/ArgumentPromotion/live_called_from_dead_2.ll
llvm/test/Transforms/Attributor/IPConstantProp/PR26044.ll
llvm/test/Transforms/Attributor/IPConstantProp/pthreads.ll
llvm/test/Transforms/Attributor/callbacks.ll
llvm/test/Transforms/Attributor/liveness.ll
llvm/test/Transforms/Attributor/memory_locations.ll
llvm/test/Transforms/Attributor/noalias.ll
llvm/test/Transforms/Attributor/nocapture-1.ll
llvm/test/Transforms/Attributor/noundef.ll
llvm/test/Transforms/Attributor/undefined_behavior.ll
llvm/test/Transforms/Attributor/value-simplify.ll
llvm/test/Transforms/GVN/PRE/2017-06-28-pre-load-dbgloc.ll
llvm/test/Transforms/InstCombine/atomic.ll
llvm/test/Transforms/InstCombine/getelementptr.ll
llvm/test/Transforms/InstCombine/load.ll
llvm/test/Transforms/InstCombine/mempcpy.ll
llvm/test/Transforms/InstCombine/pr44245.ll
llvm/test/Transforms/InstCombine/store.ll
llvm/test/Transforms/OpenMP/parallel_level_fold.ll
llvm/test/Verifier/align-md.ll
llvm/unittests/IR/ValueTest.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 188e94a9645be..d5c685ee9791f 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -396,7 +396,7 @@ class Sema final {
   ///
   /// This is the greatest alignment value supported by load, store, and alloca
   /// instructions, and global values.
-  static const unsigned MaxAlignmentExponent = 29;
+  static const unsigned MaxAlignmentExponent = 30;
   static const unsigned MaximumAlignment = 1u << MaxAlignmentExponent;
 
   typedef OpaquePtr DeclGroupPtrTy;

diff  --git a/clang/test/CXX/drs/dr6xx.cpp b/clang/test/CXX/drs/dr6xx.cpp
index e9e08fd2e2c00..efca2b4292748 100644
--- a/clang/test/CXX/drs/dr6xx.cpp
+++ b/clang/test/CXX/drs/dr6xx.cpp
@@ -551,9 +551,11 @@ namespace dr648 { // dr648: yes
 
 #if __cplusplus >= 201103L
 namespace dr649 { // dr649: yes
-  alignas(0x4000) int n; // expected-error {{requested alignment}}1
-  struct alignas(0x4000) X {}; // expected-error {{requested alignment}}
-  struct Y { int n alignas(0x4000); }; // expected-error {{requested 
alignment}}
+alignas(0x8000) int n;   // expected-error {{requested alignment}}1
+struct alignas(0x8000) X {}; // expected-error {{requested alignment}}
+struct Y {
+  int n 

Re: [clang] 4389a41 - Revert "[clang][fpenv][patch] Change clang option -ffp-model=precise to select ffp-contract=on"

2021-08-06 Thread Roman Lebedev via cfe-commits
Reminder to actually explain in the commit message why the particular
change is being reverted.

On Fri, Aug 6, 2021 at 10:02 PM Zahira Ammarguellat via cfe-commits
 wrote:
>
>
> Author: Zahira Ammarguellat
> Date: 2021-08-06T12:01:47-07:00
> New Revision: 4389a413e2129d7d55ee779638b649aa852b6f8a
>
> URL: 
> https://github.com/llvm/llvm-project/commit/4389a413e2129d7d55ee779638b649aa852b6f8a
> DIFF: 
> https://github.com/llvm/llvm-project/commit/4389a413e2129d7d55ee779638b649aa852b6f8a.diff
>
> LOG: Revert "[clang][fpenv][patch] Change clang option -ffp-model=precise to 
> select ffp-contract=on"
>
> This reverts commit 48ad446a0fb2c9b98cb7047e4daf8a84c29cef8f.
>
> Added:
>
>
> Modified:
> clang/docs/UsersManual.rst
> clang/lib/Driver/ToolChains/Clang.cpp
> clang/test/CodeGen/ffp-contract-option.c
> clang/test/CodeGen/ppc-emmintrin.c
> clang/test/CodeGen/ppc-xmmintrin.c
> clang/test/Driver/fp-model.c
>
> Removed:
>
>
>
> 
> diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
> index 838669794ea8..980d0ab45975 100644
> --- a/clang/docs/UsersManual.rst
> +++ b/clang/docs/UsersManual.rst
> @@ -1260,50 +1260,8 @@ installed.
>  Controlling Floating Point Behavior
>  ---
>
> -Clang provides a number of ways to control floating point behavior, including
> -with command line options and source pragmas. This section
> -describes the various floating point semantic modes and the corresponding 
> options.
> -
> -.. csv-table:: Floating Point Semantic Modes
> -  :header: "Mode", "Values"
> -  :widths: 15, 30, 30
> -
> -  "except_behavior", "{ignore, strict, may_trap}", "ffp-exception-behavior"
> -  "fenv_access", "{off, on}", "(none)"
> -  "rounding_mode", "{dynamic, tonearest, downward, upward, towardzero}", 
> "frounding-math"
> -  "contract", "{on, off, fast}", "ffp-contract"
> -  "denormal_fp_math", "{IEEE, PreserveSign, PositiveZero}", 
> "fdenormal-fp-math"
> -  "denormal_fp32_math", "{IEEE, PreserveSign, PositiveZero}", 
> "fdenormal-fp-math-fp32"
> -  "support_math_errno", "{on, off}", "fmath-errno"
> -  "no_honor_nans", "{on, off}", "fhonor-nans"
> -  "no_honor_infinities", "{on, off}", "fhonor-infinities"
> -  "no_signed_zeros", "{on, off}", "fsigned-zeros"
> -  "allow_reciprocal", "{on, off}", "freciprocal-math"
> -  "allow_approximate_fns", "{on, off}", "(none)"
> -  "allow_reassociation", "{on, off}", "fassociative-math"
> -
> -
> -This table describes the option settings that correspond to the three
> -floating point semantic models: precise (the default), strict, and fast.
> -
> -
> -.. csv-table:: Floating Point Models
> -  :header: "Mode", "Precise", "Strict", "Fast"
> -  :widths: 25, 15, 15, 15
> -
> -  "except_behavior", "ignore", "strict", "ignore"
> -  "fenv_access", "off", "on", "off"
> -  "rounding_mode", "tonearest", "dynamic", "tonearest"
> -  "contract", "on", "off", "fast"
> -  "denormal_fp_math", "IEEE", "IEEE", "PreserveSign"
> -  "denormal_fp32_math", "IEEE","IEEE", "PreserveSign"
> -  "support_math_errno", "on", "on", "off"
> -  "no_honor_nans", "off", "off", "on"
> -  "no_honor_infinities", "off", "off", "on"
> -  "no_signed_zeros", "off", "off", "on"
> -  "allow_reciprocal", "off", "off", "on"
> -  "allow_approximate_fns", "off", "off", "on"
> -  "allow_reassociation", "off", "off", "on"
> +Clang provides a number of ways to control floating point behavior. The 
> options
> +are listed below.
>
>  .. option:: -ffast-math
>
> @@ -1498,7 +1456,7 @@ Note that floating-point operations performed as part 
> of constant initialization
> and ``fast``.
> Details:
>
> -   * ``precise`` Disables optimizations that are not value-safe on 
> floating-point data, although FP contraction (FMA) is enabled 
> (``-ffp-contract=on``).  This is the default behavior.
> +   * ``precise`` Disables optimizations that are not value-safe on 
> floating-point data, although FP contraction (FMA) is enabled 
> (``-ffp-contract=fast``).  This is the default behavior.
> * ``strict`` Enables ``-frounding-math`` and 
> ``-ffp-exception-behavior=strict``, and disables contractions (FMA).  All of 
> the ``-ffast-math`` enablements are disabled. Enables ``STDC FENV_ACCESS``: 
> by default ``FENV_ACCESS`` is disabled. This option setting behaves as though 
> ``#pragma STDC FENV_ACESS ON`` appeared at the top of the source file.
> * ``fast`` Behaves identically to specifying both ``-ffast-math`` and 
> ``ffp-contract=fast``
>
>
> diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
> b/clang/lib/Driver/ToolChains/Clang.cpp
> index 1c79640be80f..96bbc0250126 100644
> --- a/clang/lib/Driver/ToolChains/Clang.cpp
> +++ b/clang/lib/Driver/ToolChains/Clang.cpp
> @@ -2641,7 +2641,7 @@ static void RenderFloatingPointOptions(const ToolChain 
> , const Driver ,
>
>llvm::DenormalMode DenormalFPMath = DefaultDenormalFPMath;
>llvm::DenormalMode 

[clang] 329f819 - [NFC][Clang][CodegenOpenCL] Fix test not to rely on volatile store not being removed

2021-07-09 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-07-09T14:16:54+03:00
New Revision: 329f8197ef59f9bd23328b52d623ba768b51dbb2

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

LOG: [NFC][Clang][CodegenOpenCL] Fix test not to rely on volatile store not 
being removed

Added: 


Modified: 
clang/test/CodeGenOpenCL/convergent.cl

Removed: 




diff  --git a/clang/test/CodeGenOpenCL/convergent.cl 
b/clang/test/CodeGenOpenCL/convergent.cl
index 1905d7dd81aa..a69b3d784e8c 100644
--- a/clang/test/CodeGenOpenCL/convergent.cl
+++ b/clang/test/CodeGenOpenCL/convergent.cl
@@ -3,11 +3,10 @@
 
 // This is initially assumed convergent, but can be deduced to not require it.
 
-// CHECK-LABEL: define{{.*}} spir_func void @non_convfun() local_unnamed_addr 
#0
+// CHECK-LABEL: define{{.*}} spir_func void @non_convfun(i32* %p) 
local_unnamed_addr #0
 // CHECK: ret void
 __attribute__((noinline))
-void non_convfun(void) {
-  volatile int* p;
+void non_convfun(volatile int* p) {
   *p = 0;
 }
 
@@ -28,29 +27,29 @@ void g(void);
 //  non_convfun();
 //}
 //
-// CHECK-LABEL: define{{.*}} spir_func void @test_merge_if(i32 %a) 
local_unnamed_addr #1 {
+// CHECK-LABEL: define{{.*}} spir_func void @test_merge_if(i32 %a, i32* %p) 
local_unnamed_addr #1 {
 // CHECK: %[[tobool:.+]] = icmp eq i32 %a, 0
 // CHECK: br i1 %[[tobool]], label %[[if_end3_critedge:.+]], label 
%[[if_then:.+]]
 
 // CHECK: [[if_then]]:
 // CHECK: tail call spir_func void @f()
-// CHECK: tail call spir_func void @non_convfun()
+// CHECK: tail call spir_func void @non_convfun(i32* %p)
 // CHECK: tail call spir_func void @g()
 
 // CHECK: br label %[[if_end3:.+]]
 
 // CHECK: [[if_end3_critedge]]:
-// CHECK: tail call spir_func void @non_convfun()
+// CHECK: tail call spir_func void @non_convfun(i32* %p)
 // CHECK: br label %[[if_end3]]
 
 // CHECK: [[if_end3]]:
 // CHECK: ret void
 
-void test_merge_if(int a) {
+void test_merge_if(int a, volatile int* p) {
   if (a) {
 f();
   }
-  non_convfun();
+  non_convfun(p);
   if (a) {
 g();
   }



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


[clang] f4877c7 - [clang] Improve `-Wnull-dereference` diag to be more in-line with reality

2021-07-09 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-07-09T12:51:12+03:00
New Revision: f4877c78c0fc98be47b926439bbfe33d5e1d1b6d

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

LOG: [clang] Improve `-Wnull-dereference` diag to be more in-line with reality

* Drop any mention of `volatile`.
  Please refer to https://reviews.llvm.org/D105338
* Drop address space check - it really doesn't affect the behavior,
  the store will still be dropped: https://godbolt.org/z/dP8fevxG4

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaExpr.cpp
clang/test/Analysis/NewDelete-checker-test.cpp
clang/test/Analysis/conditional-path-notes.c
clang/test/Analysis/cxx-for-range.cpp
clang/test/Analysis/diagnostics/no-prune-paths.c
clang/test/Analysis/inlining/path-notes.cpp
clang/test/Analysis/objc-arc.m
clang/test/Analysis/objc-for.m
clang/test/Analysis/taint-generic.c
clang/test/Analysis/valist-uninitialized.c
clang/test/Parser/expressions.c
clang/test/Sema/exprs.c
clang/test/Sema/offsetof.c
clang/test/SemaCXX/member-pointer.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index a9d738895033..d33d48846b18 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6744,13 +6744,13 @@ def ext_typecheck_indirection_through_void_pointer : 
ExtWarn<
   "ISO C++ does not allow indirection on operand of type %0">,
   InGroup>;
 def warn_indirection_through_null : Warning<
-  "indirection of non-volatile null pointer will be deleted, not trap">,
+  "indirection of null pointer will be deleted, not trap">,
   InGroup;
 def warn_binding_null_to_reference : Warning<
   "binding dereferenced null pointer to reference has undefined behavior">,
   InGroup;
 def note_indirection_through_null : Note<
-  "consider using __builtin_trap() or qualifying pointer with 'volatile'">;
+  "consider using __builtin_trap()">;
 def warn_pointer_indirection_from_incompatible_type : Warning<
   "dereference of type %1 that was reinterpret_cast from type %0 has undefined 
"
   "behavior">,

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index a3a26d21422f..d0efe4c02a1e 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -533,21 +533,16 @@ ExprResult Sema::DefaultFunctionArrayConversion(Expr *E, 
bool Diagnose) {
 }
 
 static void CheckForNullPointerDereference(Sema , Expr *E) {
-  // Check to see if we are dereferencing a null pointer.  If so,
-  // and if not volatile-qualified, this is undefined behavior that the
-  // optimizer will delete, so warn about it.  People sometimes try to use this
-  // to get a deterministic trap and are surprised by clang's behavior.  This
-  // only handles the pattern "*null", which is a very syntactic check.
+  // Check to see if we are dereferencing a null pointer.
+  // If so, this is undefined behavior that the optimizer will delete,
+  // so warn about it. People sometimes try to use this to get a deterministic
+  // trap and are surprised by clang's behavior. This only handles the pattern
+  // "*null", which is a very syntactic check.
   const auto *UO = dyn_cast(E->IgnoreParenCasts());
   if (UO && UO->getOpcode() == UO_Deref &&
   UO->getSubExpr()->getType()->isPointerType()) {
-const LangAS AS =
-UO->getSubExpr()->getType()->getPointeeType().getAddressSpace();
-if ((!isTargetAddressSpace(AS) ||
- (isTargetAddressSpace(AS) && toTargetAddressSpace(AS) == 0)) &&
-UO->getSubExpr()->IgnoreParenCasts()->isNullPointerConstant(
-S.Context, Expr::NPC_ValueDependentIsNotNull) &&
-!UO->getType().isVolatileQualified()) {
+if (UO->getSubExpr()->IgnoreParenCasts()->isNullPointerConstant(
+S.Context, Expr::NPC_ValueDependentIsNotNull)) {
   S.DiagRuntimeBehavior(UO->getOperatorLoc(), UO,
 S.PDiag(diag::warn_indirection_through_null)
 << UO->getSubExpr()->getSourceRange());

diff  --git a/clang/test/Analysis/NewDelete-checker-test.cpp 
b/clang/test/Analysis/NewDelete-checker-test.cpp
index 86df9d01dfb0..44a176a6eef8 100644
--- a/clang/test/Analysis/NewDelete-checker-test.cpp
+++ b/clang/test/Analysis/NewDelete-checker-test.cpp
@@ -83,7 +83,7 @@ void testGlobalPointerPlacementNew() {
 //- Other cases
 void testNewMemoryIsInHeap() {
   int *p = new int;
-  if (global != p) // condition is always true as 'p' wraps a heap region that 
+  if (global != p) // condition is always true as 'p' wraps a heap region that
// is 
diff erent from a region wrapped by 'global'
 global = 

[clang] c2c0d3e - Revert "[WebAssembly] Implementation of global.get/set for reftypes in LLVM IR"

2021-07-02 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-07-02T11:49:51+03:00
New Revision: c2c0d3ea894328667583155334f0607db0c0a73a

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

LOG: Revert "[WebAssembly] Implementation of global.get/set for reftypes in 
LLVM IR"

This reverts commit 4facbf213c51e4add2e8c19b08d5e58ad71c72de.

```

FAIL: LLVM :: CodeGen/WebAssembly/funcref-call.ll (44466 of 44468)
 TEST 'LLVM :: CodeGen/WebAssembly/funcref-call.ll' FAILED 

Script:
--
: 'RUN: at line 1';   /builddirs/llvm-project/build-Clang12/bin/llc < 
/repositories/llvm-project/llvm/test/CodeGen/WebAssembly/funcref-call.ll 
--mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | 
/builddirs/llvm-project/build-Clang12/bin/FileCheck 
/repositories/llvm-project/llvm/test/CodeGen/WebAssembly/funcref-call.ll
--
Exit Code: 2

Command Output (stderr):
--
llc: 
/repositories/llvm-project/llvm/include/llvm/Support/LowLevelTypeImpl.h:44: 
static llvm::LLT llvm::LLT::scalar(unsigned int): Assertion `SizeInBits > 0 && 
"invalid scalar size"' failed.

```

Added: 


Modified: 
clang/lib/Basic/Targets/WebAssembly.h
clang/test/CodeGen/target-data.c
llvm/include/llvm/CodeGen/TargetLowering.h
llvm/include/llvm/CodeGen/ValueTypes.h
llvm/lib/CodeGen/CodeGenPrepare.cpp
llvm/lib/CodeGen/MachineOperand.cpp
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/lib/CodeGen/TargetLoweringBase.cpp
llvm/lib/CodeGen/ValueTypes.cpp
llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp
llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.h
llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
llvm/lib/Target/WebAssembly/WebAssemblyISD.def
llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.h
llvm/lib/Target/WebAssembly/WebAssemblyInstrTable.td
llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp

Removed: 
llvm/test/CodeGen/WebAssembly/externref-globalget.ll
llvm/test/CodeGen/WebAssembly/externref-globalset.ll
llvm/test/CodeGen/WebAssembly/externref-inttoptr.ll
llvm/test/CodeGen/WebAssembly/externref-ptrtoint.ll
llvm/test/CodeGen/WebAssembly/externref-undef.ll
llvm/test/CodeGen/WebAssembly/externref-unsized-load.ll
llvm/test/CodeGen/WebAssembly/externref-unsized-store.ll
llvm/test/CodeGen/WebAssembly/funcref-call.ll
llvm/test/CodeGen/WebAssembly/funcref-globalget.ll
llvm/test/CodeGen/WebAssembly/funcref-globalset.ll



diff  --git a/clang/lib/Basic/Targets/WebAssembly.h 
b/clang/lib/Basic/Targets/WebAssembly.h
index ed590fe7e3338..b29730c5d706b 100644
--- a/clang/lib/Basic/Targets/WebAssembly.h
+++ b/clang/lib/Basic/Targets/WebAssembly.h
@@ -147,7 +147,7 @@ class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo
   explicit WebAssembly32TargetInfo(const llvm::Triple ,
const TargetOptions )
   : WebAssemblyTargetInfo(T, Opts) {
-resetDataLayout("e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20");
+resetDataLayout("e-m:e-p:32:32-i64:64-n32:64-S128-ni:1");
   }
 
 protected:
@@ -166,7 +166,7 @@ class LLVM_LIBRARY_VISIBILITY WebAssembly64TargetInfo
 SizeType = UnsignedLong;
 PtrDiffType = SignedLong;
 IntPtrType = SignedLong;
-resetDataLayout("e-m:e-p:64:64-i64:64-n32:64-S128-ni:1:10:20");
+resetDataLayout("e-m:e-p:64:64-i64:64-n32:64-S128-ni:1");
   }
 
 protected:

diff  --git a/clang/test/CodeGen/target-data.c 
b/clang/test/CodeGen/target-data.c
index 1be01efd16515..1d88984530e5b 100644
--- a/clang/test/CodeGen/target-data.c
+++ b/clang/test/CodeGen/target-data.c
@@ -108,11 +108,11 @@
 
 // RUN: %clang_cc1 -triple wasm32-unknown-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=WEBASSEMBLY32
-// WEBASSEMBLY32: target datalayout = 
"e-m:e-p:32:32-i64:64-n32:64-S128-ni:1:10:20"
+// WEBASSEMBLY32: target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1"
 
 // RUN: %clang_cc1 -triple wasm64-unknown-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=WEBASSEMBLY64
-// WEBASSEMBLY64: target datalayout = 
"e-m:e-p:64:64-i64:64-n32:64-S128-ni:1:10:20"
+// WEBASSEMBLY64: target datalayout = "e-m:e-p:64:64-i64:64-n32:64-S128-ni:1"
 
 // RUN: %clang_cc1 -triple lanai-unknown-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=LANAI

diff  --git a/llvm/include/llvm/CodeGen/TargetLowering.h 
b/llvm/include/llvm/CodeGen/TargetLowering.h
index 75894d15a9693..47d6ca43a5ac3 100644
--- a/llvm/include/llvm/CodeGen/TargetLowering.h
+++ b/llvm/include/llvm/CodeGen/TargetLowering.h
@@ -350,7 

[clang] e523645 - [NewPM] Remove SpeculateAroundPHIs pass

2021-06-15 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-06-15T20:35:55+03:00
New Revision: e52364532afb2748c324f360bc1cc12605d314f3

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

LOG: [NewPM] Remove SpeculateAroundPHIs pass

Addition of this pass has been botched.
There is no particular reason why it had to be sold as an inseparable part
of new-pm transition. It was added when old-pm was still the default,
and very *very* few users were actually tracking new-pm,
so it's effects weren't measured.

Which means, some of the turnoil of the new-pm transition
are actually likely regressions due to this pass.

Likewise, there has been a number of post-commit feedback
(post new-pm switch), namely
* https://reviews.llvm.org/D37467#2787157 (regresses HW-loops)
* https://reviews.llvm.org/D37467#2787259 (should not be in middle-end, should 
run after LSR, not before)
* https://reviews.llvm.org/D95789 (an attempt to fix bad loop backedge metadata)
and in the half year past, the pass authors (google) still haven't found time 
to respond to any of that.

Hereby it is proposed to backout the pass from the pipeline,
until someone who cares about it can address the issues reported,
and properly start the process of adding a new pass into the pipeline,
with proper performance evaluation.

Furthermore, neither google nor facebook reports any perf changes
from this change, so i'm dropping the pass completely.
It can always be re-reverted should/if anyone want to pick it up again.

Reviewed By: aeubanks

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

Added: 


Modified: 
clang/test/CodeGen/thinlto-distributed-newpm.ll
llvm/lib/Passes/PassBuilder.cpp
llvm/lib/Passes/PassRegistry.def
llvm/lib/Transforms/Scalar/CMakeLists.txt
llvm/test/Other/new-pm-defaults.ll
llvm/test/Other/new-pm-thinlto-defaults.ll
llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
llvm/test/Transforms/LoopUnroll/AArch64/runtime-unroll-generic.ll

llvm/test/Transforms/PhaseOrdering/AArch64/hoisting-sinking-required-for-vectorization.ll
llvm/test/Transforms/PhaseOrdering/loop-rotation-vs-common-code-hoisting.ll
llvm/utils/gn/secondary/llvm/lib/Transforms/Scalar/BUILD.gn

Removed: 
llvm/include/llvm/Transforms/Scalar/SpeculateAroundPHIs.h
llvm/lib/Transforms/Scalar/SpeculateAroundPHIs.cpp
llvm/test/Transforms/SpeculateAroundPHIs/basic-x86.ll
llvm/test/Transforms/SpeculateAroundPHIs/convergent.ll
llvm/test/Transforms/SpeculateAroundPHIs/pr42991.ll



diff  --git a/clang/test/CodeGen/thinlto-distributed-newpm.ll 
b/clang/test/CodeGen/thinlto-distributed-newpm.ll
index e20f781915726..c61a6ff7fbeb5 100644
--- a/clang/test/CodeGen/thinlto-distributed-newpm.ll
+++ b/clang/test/CodeGen/thinlto-distributed-newpm.ll
@@ -165,7 +165,6 @@
 ; CHECK-O: Running pass: InstSimplifyPass on main
 ; CHECK-O: Running pass: DivRemPairsPass on main
 ; CHECK-O: Running pass: SimplifyCFGPass on main
-; CHECK-O: Running pass: SpeculateAroundPHIsPass on main
 ; CHECK-O: Running pass: CGProfilePass
 ; CHECK-O: Running pass: GlobalDCEPass
 ; CHECK-O: Running pass: ConstantMergePass

diff  --git a/llvm/include/llvm/Transforms/Scalar/SpeculateAroundPHIs.h 
b/llvm/include/llvm/Transforms/Scalar/SpeculateAroundPHIs.h
deleted file mode 100644
index 2104daff44abe..0
--- a/llvm/include/llvm/Transforms/Scalar/SpeculateAroundPHIs.h
+++ /dev/null
@@ -1,109 +0,0 @@
-//===- SpeculateAroundPHIs.h - Speculate around PHIs *- 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
-//
-//===--===//
-
-#ifndef LLVM_TRANSFORMS_SCALAR_SPECULATEAROUNDPHIS_H
-#define LLVM_TRANSFORMS_SCALAR_SPECULATEAROUNDPHIS_H
-
-#include "llvm/ADT/SetVector.h"
-#include "llvm/Analysis/AssumptionCache.h"
-#include "llvm/IR/Dominators.h"
-#include "llvm/IR/Function.h"
-#include "llvm/IR/PassManager.h"
-#include "llvm/Support/Compiler.h"
-
-namespace llvm {
-
-/// This pass handles simple speculating of  instructions around PHIs when
-/// doing so is profitable for a particular target despite duplicated
-/// instructions.
-///
-/// The motivating example are PHIs of constants which will require
-/// materializing the constants along each edge. If the PHI is used by an
-/// instruction where the target can materialize the constant as part of the
-/// instruction, it is profitable to speculate those instructions around the
-/// PHI node. This can reduce dynamic instruction count as well as decrease
-/// register pressure.
-///
-/// 

[clang-tools-extra] be6b9e8 - Revert "[clang-tidy] Simplify static assert check"

2021-05-30 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-05-30T16:44:31+03:00
New Revision: be6b9e8ae71768d2e09ec14619ca4ecfdef553fa

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

LOG: Revert "[clang-tidy] Simplify static assert check"

This patch starts to produce a very obvious false-positives,
despite the fact the preexisting tests already cover the pattern.
they clearly don't actually cover it.

https://godbolt.org/z/3zdqvbfxj

This reverts commit 1709bb8c7395418236ec94fe3b9d91fed746452b.

Added: 


Modified: 
clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
clang-tools-extra/clang-tidy/misc/StaticAssertCheck.h

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
index e9ea69aaeb323..224936887e033 100644
--- a/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
@@ -27,37 +27,48 @@ StaticAssertCheck::StaticAssertCheck(StringRef Name, 
ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context) {}
 
 void StaticAssertCheck::registerMatchers(MatchFinder *Finder) {
-  auto NegatedString =
-  unaryOperator(hasOperatorName("!"), hasUnaryOperand(stringLiteral()));
+  auto NegatedString = unaryOperator(
+  hasOperatorName("!"), 
hasUnaryOperand(ignoringImpCasts(stringLiteral(;
   auto IsAlwaysFalse =
   expr(anyOf(cxxBoolLiteral(equals(false)), integerLiteral(equals(0)),
  cxxNullPtrLiteralExpr(), gnuNullExpr(), NegatedString))
   .bind("isAlwaysFalse");
-  auto IsAlwaysFalseWithCast =
-  anyOf(IsAlwaysFalse, 
cStyleCastExpr(has(IsAlwaysFalse)).bind("castExpr"));
-  auto AssertExprRoot =
-  anyOf(binaryOperator(
-hasAnyOperatorName("&&", "=="),
-hasEitherOperand(stringLiteral().bind("assertMSG")),
-anyOf(binaryOperator(hasEitherOperand(IsAlwaysFalseWithCast)),
-  anything()))
-.bind("assertExprRoot"),
-IsAlwaysFalse);
+  auto IsAlwaysFalseWithCast = ignoringParenImpCasts(anyOf(
+  IsAlwaysFalse, cStyleCastExpr(has(ignoringParenImpCasts(IsAlwaysFalse)))
+ .bind("castExpr")));
+  auto AssertExprRoot = anyOf(
+  binaryOperator(
+  hasAnyOperatorName("&&", "=="),
+  
hasEitherOperand(ignoringImpCasts(stringLiteral().bind("assertMSG"))),
+  anyOf(binaryOperator(hasEitherOperand(IsAlwaysFalseWithCast)),
+anything()))
+  .bind("assertExprRoot"),
+  IsAlwaysFalse);
   auto NonConstexprFunctionCall =
   callExpr(hasDeclaration(functionDecl(unless(isConstexpr();
   auto AssertCondition =
-  expr(optionally(expr(anyOf(AssertExprRoot,
-unaryOperator(hasUnaryOperand(AssertExprRoot),
-   unless(findAll(NonConstexprFunctionCall)))
+  expr(
+  anyOf(expr(ignoringParenCasts(anyOf(
+AssertExprRoot, unaryOperator(hasUnaryOperand(
+
ignoringParenCasts(AssertExprRoot)),
+anything()),
+  unless(findAll(NonConstexprFunctionCall)))
   .bind("condition");
   auto Condition =
-  anyOf(callExpr(traverse(TK_AsIs, callExpr(hasDeclaration(functionDecl(
-   hasName("__builtin_expect"),
- hasArgument(0, AssertCondition)),
+  anyOf(ignoringParenImpCasts(callExpr(
+hasDeclaration(functionDecl(hasName("__builtin_expect"))),
+hasArgument(0, AssertCondition))),
 AssertCondition);
 
+  Finder->addMatcher(conditionalOperator(hasCondition(Condition),
+ unless(isInTemplateInstantiation()))
+ .bind("condStmt"),
+ this);
+
   Finder->addMatcher(
-  mapAnyOf(ifStmt, 
conditionalOperator).with(hasCondition(Condition)).bind("condStmt"), this);
+  ifStmt(hasCondition(Condition), unless(isInTemplateInstantiation()))
+  .bind("condStmt"),
+  this);
 }
 
 void StaticAssertCheck::check(const MatchFinder::MatchResult ) {

diff  --git a/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.h 
b/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.h
index 796fc4827db42..0168d1fcd107f 100644
--- a/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.h
+++ b/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.h
@@ -30,9 +30,6 @@ class StaticAssertCheck : public ClangTidyCheck {
   }
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
-  llvm::Optional getCheckTraversalKind() const override {
-return 

[clang] 0d8f91d - [NFC] Delete two newly-added test cases

2021-05-13 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-05-13T21:23:01+03:00
New Revision: 0d8f91d2a9994619bb62c548a81eb605f0e768f7

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

LOG: [NFC] Delete two newly-added test cases

Failing on bots in unobvious ways.

Added: 


Modified: 


Removed: 
clang/test/CodeGenCXX/thunk-wrong-return-type.cpp
clang/test/CodeGenCXX/thunk-wrong-this.cpp



diff  --git a/clang/test/CodeGenCXX/thunk-wrong-return-type.cpp 
b/clang/test/CodeGenCXX/thunk-wrong-return-type.cpp
deleted file mode 100644
index e12e313b7dbd..
--- a/clang/test/CodeGenCXX/thunk-wrong-return-type.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-// RUN: %clang_cc1 -emit-llvm-only -triple %itanium_abi_triple %s -emit-llvm 
-o - %s | FileCheck %s
-
-struct A {};
-struct alignas(32) B : virtual A {
-  char c[32];
-};
-struct Pad {
-  char c[7];
-};
-struct C : B, Pad, virtual A {};
-
-struct X {
-  virtual A ();
-};
-struct U {
-  virtual ~U();
-};
-C c;
-struct Y : U, X {
-  virtual B () override { return c; }
-};
-
-Y y;
-
-// FIXME: The return type should be  align 1 dereferenceable(1) %{{[^*]+}}*
-// CHECK: define linkonce_odr %{{[^*]+}}* @_ZTchn8_v0_n24_N1Y1fEv(%{{[^*]+}}* 
%this) unnamed_addr #1 comdat align 2 {

diff  --git a/clang/test/CodeGenCXX/thunk-wrong-this.cpp 
b/clang/test/CodeGenCXX/thunk-wrong-this.cpp
deleted file mode 100644
index 337559a52b6c..
--- a/clang/test/CodeGenCXX/thunk-wrong-this.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-// RUN: %clang_cc1 -emit-llvm-only -triple %itanium_abi_triple %s -emit-llvm 
-o - %s | FileCheck %s
-
-class Base1 {
-  virtual void Foo1();
-};
-
-class Base2 {
-  virtual void Foo2();
-};
-
-class alignas(16) Obj : public Base1, public Base2 {
-  void Foo1() override;
-  void Foo2() override;
-  ~Obj();
-};
-
-void Obj::Foo1() {}
-void Obj::Foo2() {}
-
-// CHECK: define {{.*}}void @_ZN3Obj4Foo2Ev(%{{[^*]+}}* nonnull align 16 
dereferenceable(16) %this) unnamed_addr #0 align 2 {
-
-// FIXME: the argument should be  %class.Base2.2* nonnull dereferenceable(8) 
%this
-// CHECK: define dso_local void @_ZThn8_N3Obj4Foo2Ev(%{{[^*]+}}* %this) 
unnamed_addr #1 align 2 {
-
-// CHECK: tail call void @_ZN3Obj4Foo2Ev(%{{[^*]+}}* nonnull align 16 
dereferenceable(16) %2)



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


[clang] ecc4e9e - [NFC] Try to fix CodeGenCXX/thunk-wrong-return-type.cpp test

2021-05-13 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-05-13T21:17:31+03:00
New Revision: ecc4e9e8f4cb7581cbc447bc838943176715695c

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

LOG: [NFC] Try to fix CodeGenCXX/thunk-wrong-return-type.cpp test

Added: 


Modified: 
clang/test/CodeGenCXX/thunk-wrong-return-type.cpp
clang/test/CodeGenCXX/thunk-wrong-this.cpp

Removed: 




diff  --git a/clang/test/CodeGenCXX/thunk-wrong-return-type.cpp 
b/clang/test/CodeGenCXX/thunk-wrong-return-type.cpp
index 53c35a44b8fe..e12e313b7dbd 100644
--- a/clang/test/CodeGenCXX/thunk-wrong-return-type.cpp
+++ b/clang/test/CodeGenCXX/thunk-wrong-return-type.cpp
@@ -22,5 +22,5 @@ struct Y : U, X {
 
 Y y;
 
-// FIXME: The return type should be  align 1 dereferenceable(1) %struct.A.8*
-// CHECK: define linkonce_odr %struct.B.1* 
@_ZTchn8_v0_n24_N1Y1fEv(%struct.Y.5* %this) unnamed_addr #1 comdat align 2 {
+// FIXME: The return type should be  align 1 dereferenceable(1) %{{[^*]+}}*
+// CHECK: define linkonce_odr %{{[^*]+}}* @_ZTchn8_v0_n24_N1Y1fEv(%{{[^*]+}}* 
%this) unnamed_addr #1 comdat align 2 {

diff  --git a/clang/test/CodeGenCXX/thunk-wrong-this.cpp 
b/clang/test/CodeGenCXX/thunk-wrong-this.cpp
index 824efe08b263..337559a52b6c 100644
--- a/clang/test/CodeGenCXX/thunk-wrong-this.cpp
+++ b/clang/test/CodeGenCXX/thunk-wrong-this.cpp
@@ -17,9 +17,9 @@ class alignas(16) Obj : public Base1, public Base2 {
 void Obj::Foo1() {}
 void Obj::Foo2() {}
 
-// CHECK: define {{.*}}void @_ZN3Obj4Foo2Ev(%{{.*}}* nonnull align 16 
dereferenceable(16) %this) unnamed_addr #0 align 2 {
+// CHECK: define {{.*}}void @_ZN3Obj4Foo2Ev(%{{[^*]+}}* nonnull align 16 
dereferenceable(16) %this) unnamed_addr #0 align 2 {
 
 // FIXME: the argument should be  %class.Base2.2* nonnull dereferenceable(8) 
%this
-// CHECK: define dso_local void @_ZThn8_N3Obj4Foo2Ev(%{{.*}}* %this) 
unnamed_addr #1 align 2 {
+// CHECK: define dso_local void @_ZThn8_N3Obj4Foo2Ev(%{{[^*]+}}* %this) 
unnamed_addr #1 align 2 {
 
-// CHECK: tail call void @_ZN3Obj4Foo2Ev(%{{.*}}* nonnull align 16 
dereferenceable(16) %2)
+// CHECK: tail call void @_ZN3Obj4Foo2Ev(%{{[^*]+}}* nonnull align 16 
dereferenceable(16) %2)



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


[clang] 9d3eb78 - [NFC] Try to fix CodeGenCXX/thunk-wrong-this.cpp test

2021-05-13 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-05-13T21:10:14+03:00
New Revision: 9d3eb7885d916b22bc673334f71a10e3b2835174

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

LOG: [NFC] Try to fix CodeGenCXX/thunk-wrong-this.cpp test

Added: 


Modified: 
clang/test/CodeGenCXX/thunk-wrong-this.cpp

Removed: 




diff  --git a/clang/test/CodeGenCXX/thunk-wrong-this.cpp 
b/clang/test/CodeGenCXX/thunk-wrong-this.cpp
index f70197b4ede1..824efe08b263 100644
--- a/clang/test/CodeGenCXX/thunk-wrong-this.cpp
+++ b/clang/test/CodeGenCXX/thunk-wrong-this.cpp
@@ -17,9 +17,9 @@ class alignas(16) Obj : public Base1, public Base2 {
 void Obj::Foo1() {}
 void Obj::Foo2() {}
 
-// CHECK: define dso_local void @_ZN3Obj4Foo2Ev(%class.Obj.0* nonnull align 16 
dereferenceable(16) %this) unnamed_addr #0 align 2 {
+// CHECK: define {{.*}}void @_ZN3Obj4Foo2Ev(%{{.*}}* nonnull align 16 
dereferenceable(16) %this) unnamed_addr #0 align 2 {
 
 // FIXME: the argument should be  %class.Base2.2* nonnull dereferenceable(8) 
%this
-// CHECK: define dso_local void @_ZThn8_N3Obj4Foo2Ev(%class.Obj.0* %this) 
unnamed_addr #1 align 2 {
+// CHECK: define dso_local void @_ZThn8_N3Obj4Foo2Ev(%{{.*}}* %this) 
unnamed_addr #1 align 2 {
 
-// CHECK: tail call void @_ZN3Obj4Foo2Ev(%class.Obj.0* nonnull align 16 
dereferenceable(16) %2)
+// CHECK: tail call void @_ZN3Obj4Foo2Ev(%{{.*}}* nonnull align 16 
dereferenceable(16) %2)



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


[clang] a624cec - [Clang][Codegen] Do not annotate thunk's this/return types with align/deref/nonnull attrs

2021-05-13 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-05-13T20:33:08+03:00
New Revision: a624cec56d4bf61c1f3cb7daf2d27dac59c56fa4

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

LOG: [Clang][Codegen] Do not annotate thunk's this/return types with 
align/deref/nonnull attrs

As it was discovered in post-commit feedback
for 0aa0458f1429372038ca6a4edc7e94c96cd9a753,
we handle thunks incorrectly, and end up annotating
their this/return with attributes that are valid
for their callees, not for thunks themselves.

While it would be good to fix this properly,
and keep annotating them on thunks,
i've tried doing that in https://reviews.llvm.org/D100388
with little success, and the patch is stuck for a month now.

So for now, as a stopgap measure, subj.

Added: 


Modified: 
clang/lib/CodeGen/CGBlocks.cpp
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGNonTrivialStruct.cpp
clang/lib/CodeGen/CGObjC.cpp
clang/lib/CodeGen/CGVTables.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenModule.h
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/lib/CodeGen/MicrosoftCXXABI.cpp
clang/test/CodeGenCXX/constructor-destructor-return-this.cpp
clang/test/CodeGenCXX/microsoft-abi-byval-thunks.cpp
clang/test/CodeGenCXX/microsoft-abi-structors.cpp
clang/test/CodeGenCXX/microsoft-abi-thunks.cpp
clang/test/CodeGenCXX/thunk-returning-memptr.cpp
clang/test/CodeGenCXX/thunk-wrong-return-type.cpp
clang/test/CodeGenCXX/thunk-wrong-this.cpp
clang/test/CodeGenCXX/thunks-ehspec.cpp
clang/test/CodeGenCXX/thunks.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index 5ecd88e7a14c9..cc9be87961e7d 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -1902,7 +1902,7 @@ static void setBlockHelperAttributesVisibility(bool 
CapturesNonExternalType,
   } else {
 Fn->setVisibility(llvm::GlobalValue::HiddenVisibility);
 Fn->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
-CGM.SetLLVMFunctionAttributes(GlobalDecl(), FI, Fn);
+CGM.SetLLVMFunctionAttributes(GlobalDecl(), FI, Fn, /*IsThunk=*/false);
 CGM.SetLLVMFunctionAttributesForDefinition(nullptr, Fn);
   }
 }

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 1c56089974d35..147b4c90d8d32 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -1692,7 +1692,7 @@ llvm::Function 
*CodeGenFunction::generateBuiltinOSLogHelperFunction(
   llvm::Function *Fn = llvm::Function::Create(
   FuncTy, llvm::GlobalValue::LinkOnceODRLinkage, Name, ());
   Fn->setVisibility(llvm::GlobalValue::HiddenVisibility);
-  CGM.SetLLVMFunctionAttributes(GlobalDecl(), FI, Fn);
+  CGM.SetLLVMFunctionAttributes(GlobalDecl(), FI, Fn, /*IsThunk=*/false);
   CGM.SetLLVMFunctionAttributesForDefinition(nullptr, Fn);
   Fn->setDoesNotThrow();
 

diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 6c77f1889fb52..946772fc9c1e4 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1982,9 +1982,12 @@ static bool DetermineNoUndef(QualType QTy, CodeGenTypes 
,
 /// attributes that restrict how the frontend generates code must be
 /// added here rather than getDefaultFunctionAttributes.
 ///
-void CodeGenModule::ConstructAttributeList(
-StringRef Name, const CGFunctionInfo , CGCalleeInfo CalleeInfo,
-llvm::AttributeList , unsigned , bool AttrOnCallSite) 
{
+void CodeGenModule::ConstructAttributeList(StringRef Name,
+   const CGFunctionInfo ,
+   CGCalleeInfo CalleeInfo,
+   llvm::AttributeList ,
+   unsigned ,
+   bool AttrOnCallSite, bool IsThunk) {
   llvm::AttrBuilder FuncAttrs;
   llvm::AttrBuilder RetAttrs;
 
@@ -2275,18 +2278,21 @@ void CodeGenModule::ConstructAttributeList(
 llvm_unreachable("Invalid ABI kind for return argument");
   }
 
-  if (const auto *RefTy = RetTy->getAs()) {
-QualType PTy = RefTy->getPointeeType();
-if (!PTy->isIncompleteType() && PTy->isConstantSizeType())
-  RetAttrs.addDereferenceableAttr(
-  getMinimumObjectSize(PTy).getQuantity());
-if (getContext().getTargetAddressSpace(PTy) == 0 &&
-!CodeGenOpts.NullPointerIsValid)
-  RetAttrs.addAttribute(llvm::Attribute::NonNull);
-if (PTy->isObjectType()) {
-  llvm::Align Alignment =
-  getNaturalPointeeTypeAlignment(RetTy).getAsAlign();
-  RetAttrs.addAlignmentAttr(Alignment);
+  if (!IsThunk) {
+// FIXME: fix this 

[clang] 70aa462 - [NFC][Clang][Codegen] Add tests with wrong attributes on this/return of thunks

2021-05-13 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-05-13T20:32:40+03:00
New Revision: 70aa4623de9fe2f609eab8969d7ef76b4c80084b

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

LOG: [NFC][Clang][Codegen] Add tests with wrong attributes on this/return of 
thunks

>From https://reviews.llvm.org/D100388

Added: 
clang/test/CodeGenCXX/thunk-wrong-return-type.cpp
clang/test/CodeGenCXX/thunk-wrong-this.cpp

Modified: 


Removed: 




diff  --git a/clang/test/CodeGenCXX/thunk-wrong-return-type.cpp 
b/clang/test/CodeGenCXX/thunk-wrong-return-type.cpp
new file mode 100644
index 0..f6d662c8cb7a9
--- /dev/null
+++ b/clang/test/CodeGenCXX/thunk-wrong-return-type.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -emit-llvm-only -triple %itanium_abi_triple %s -emit-llvm 
-o - %s | FileCheck %s
+
+struct A {};
+struct alignas(32) B : virtual A {
+  char c[32];
+};
+struct Pad {
+  char c[7];
+};
+struct C : B, Pad, virtual A {};
+
+struct X {
+  virtual A ();
+};
+struct U {
+  virtual ~U();
+};
+C c;
+struct Y : U, X {
+  virtual B () override { return c; }
+};
+
+Y y;
+
+// FIXME: The return type should be  align 1 dereferenceable(1) %struct.A.8*
+// CHECK: define linkonce_odr nonnull align 32 dereferenceable(40) 
%struct.B.1* @_ZTchn8_v0_n24_N1Y1fEv(%struct.Y.5* nonnull dereferenceable(16) 
%this) unnamed_addr #1 comdat align 2 {

diff  --git a/clang/test/CodeGenCXX/thunk-wrong-this.cpp 
b/clang/test/CodeGenCXX/thunk-wrong-this.cpp
new file mode 100644
index 0..664163a3b9da5
--- /dev/null
+++ b/clang/test/CodeGenCXX/thunk-wrong-this.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -emit-llvm-only -triple %itanium_abi_triple %s -emit-llvm 
-o - %s | FileCheck %s
+
+class Base1 {
+  virtual void Foo1();
+};
+
+class Base2 {
+  virtual void Foo2();
+};
+
+class alignas(16) Obj : public Base1, public Base2 {
+  void Foo1() override;
+  void Foo2() override;
+  ~Obj();
+};
+
+void Obj::Foo1() {}
+void Obj::Foo2() {}
+
+// CHECK: define dso_local void @_ZN3Obj4Foo2Ev(%class.Obj.0* nonnull 
dereferenceable(16) %this) unnamed_addr #0 align 2 {
+
+// FIXME: the argument should be  %class.Base2.2* nonnull dereferenceable(8) 
%this
+// CHECK: define dso_local void @_ZThn8_N3Obj4Foo2Ev(%class.Obj.0* nonnull 
dereferenceable(16) %this) unnamed_addr #1 align 2 {
+
+// CHECK: tail call void @_ZN3Obj4Foo2Ev(%class.Obj.0* nonnull 
dereferenceable(16) %2)



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


Re: [clang] 1470b85 - Remove AST inclusion from Basic include

2021-05-12 Thread Roman Lebedev via cfe-commits
Thanks!

On Wed, May 12, 2021 at 8:56 PM Benjamin Kramer via cfe-commits
 wrote:
>
>
> Author: Benjamin Kramer
> Date: 2021-05-12T19:51:21+02:00
> New Revision: 1470b8587f6fdc357163c2258747b77ae9ad6d7a
>
> URL: 
> https://github.com/llvm/llvm-project/commit/1470b8587f6fdc357163c2258747b77ae9ad6d7a
> DIFF: 
> https://github.com/llvm/llvm-project/commit/1470b8587f6fdc357163c2258747b77ae9ad6d7a.diff
>
> LOG: Remove AST inclusion from Basic include
>
> That's a cyclic dependency. NFC.
>
> Added:
>
>
> Modified:
> clang/include/clang/Basic/Thunk.h
>
> Removed:
>
>
>
> 
> diff  --git a/clang/include/clang/Basic/Thunk.h 
> b/clang/include/clang/Basic/Thunk.h
> index 7f3c4b24ec6d..91088be6ae73 100644
> --- a/clang/include/clang/Basic/Thunk.h
> +++ b/clang/include/clang/Basic/Thunk.h
> @@ -15,10 +15,13 @@
>  #ifndef LLVM_CLANG_BASIC_THUNK_H
>  #define LLVM_CLANG_BASIC_THUNK_H
>
> -#include "clang/AST/GlobalDecl.h"
> +#include 
> +#include 
>
>  namespace clang {
>
> +class CXXMethodDecl;
> +
>  /// A return adjustment.
>  struct ReturnAdjustment {
>/// The non-virtual adjustment from the derived object to its
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 2d84195 - [NFCI][clang][Codegen] CodeGenVTables::addVTableComponent(): use getGlobalDecl

2021-05-12 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-05-12T20:39:54+03:00
New Revision: 2d84195d60b0cb5ea43b18ab8f6770a84bf32da4

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

LOG: [NFCI][clang][Codegen] CodeGenVTables::addVTableComponent(): use 
getGlobalDecl

It does the same thing.
Split off from https://reviews.llvm.org/D100388

Added: 


Modified: 
clang/lib/CodeGen/CGVTables.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGVTables.cpp b/clang/lib/CodeGen/CGVTables.cpp
index bef9a293b7ed5..a8e3a669353c3 100644
--- a/clang/lib/CodeGen/CGVTables.cpp
+++ b/clang/lib/CodeGen/CGVTables.cpp
@@ -727,22 +727,7 @@ void 
CodeGenVTables::addVTableComponent(ConstantArrayBuilder ,
   case VTableComponent::CK_FunctionPointer:
   case VTableComponent::CK_CompleteDtorPointer:
   case VTableComponent::CK_DeletingDtorPointer: {
-GlobalDecl GD;
-
-// Get the right global decl.
-switch (component.getKind()) {
-default:
-  llvm_unreachable("Unexpected vtable component kind");
-case VTableComponent::CK_FunctionPointer:
-  GD = component.getFunctionDecl();
-  break;
-case VTableComponent::CK_CompleteDtorPointer:
-  GD = GlobalDecl(component.getDestructorDecl(), Dtor_Complete);
-  break;
-case VTableComponent::CK_DeletingDtorPointer:
-  GD = GlobalDecl(component.getDestructorDecl(), Dtor_Deleting);
-  break;
-}
+GlobalDecl GD = component.getGlobalDecl();
 
 if (CGM.getLangOpts().CUDA) {
   // Emit NULL for methods we can't codegen on this



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


[clang] 81f56a2 - [NFC][clang][Codegen] Split ThunkInfo into it's own header

2021-05-12 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-05-12T20:39:54+03:00
New Revision: 81f56a2eb3797eb5be61d65a8f7d7e19456e67d1

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

LOG: [NFC][clang][Codegen] Split ThunkInfo into it's own header

Otherwise we'll have issues with forward definition of GlobalDecl.

Split off from https://reviews.llvm.org/D100388

Added: 
clang/include/clang/Basic/Thunk.h

Modified: 
clang/include/clang/AST/VTableBuilder.h
clang/include/clang/Basic/ABI.h
clang/lib/AST/ItaniumMangle.cpp

Removed: 




diff  --git a/clang/include/clang/AST/VTableBuilder.h 
b/clang/include/clang/AST/VTableBuilder.h
index 241dd13f903e5..e451f3f861b79 100644
--- a/clang/include/clang/AST/VTableBuilder.h
+++ b/clang/include/clang/AST/VTableBuilder.h
@@ -18,6 +18,7 @@
 #include "clang/AST/GlobalDecl.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/Basic/ABI.h"
+#include "clang/Basic/Thunk.h"
 #include "llvm/ADT/DenseMap.h"
 #include 
 #include 

diff  --git a/clang/include/clang/Basic/ABI.h b/clang/include/clang/Basic/ABI.h
index 2401ffa20494e..231bad799a42c 100644
--- a/clang/include/clang/Basic/ABI.h
+++ b/clang/include/clang/Basic/ABI.h
@@ -37,174 +37,6 @@ enum CXXDtorType {
 Dtor_Comdat///< The COMDAT used for dtors
 };
 
-/// A return adjustment.
-struct ReturnAdjustment {
-  /// The non-virtual adjustment from the derived object to its
-  /// nearest virtual base.
-  int64_t NonVirtual;
-
-  /// Holds the ABI-specific information about the virtual return
-  /// adjustment, if needed.
-  union VirtualAdjustment {
-// Itanium ABI
-struct {
-  /// The offset (in bytes), relative to the address point
-  /// of the virtual base class offset.
-  int64_t VBaseOffsetOffset;
-} Itanium;
-
-// Microsoft ABI
-struct {
-  /// The offset (in bytes) of the vbptr, relative to the beginning
-  /// of the derived class.
-  uint32_t VBPtrOffset;
-
-  /// Index of the virtual base in the vbtable.
-  uint32_t VBIndex;
-} Microsoft;
-
-VirtualAdjustment() {
-  memset(this, 0, sizeof(*this));
-}
-
-bool Equals(const VirtualAdjustment ) const {
-  return memcmp(this, , sizeof(Other)) == 0;
-}
-
-bool isEmpty() const {
-  VirtualAdjustment Zero;
-  return Equals(Zero);
-}
-
-bool Less(const VirtualAdjustment ) const {
-  return memcmp(this, , sizeof(RHS)) < 0;
-}
-  } Virtual;
-
-  ReturnAdjustment() : NonVirtual(0) {}
-
-  bool isEmpty() const { return !NonVirtual && Virtual.isEmpty(); }
-
-  friend bool operator==(const ReturnAdjustment ,
- const ReturnAdjustment ) {
-return LHS.NonVirtual == RHS.NonVirtual && LHS.Virtual.Equals(RHS.Virtual);
-  }
-
-  friend bool operator!=(const ReturnAdjustment , const ReturnAdjustment 
) {
-return !(LHS == RHS);
-  }
-
-  friend bool operator<(const ReturnAdjustment ,
-const ReturnAdjustment ) {
-if (LHS.NonVirtual < RHS.NonVirtual)
-  return true;
-
-return LHS.NonVirtual == RHS.NonVirtual && LHS.Virtual.Less(RHS.Virtual);
-  }
-};
-
-/// A \c this pointer adjustment.
-struct ThisAdjustment {
-  /// The non-virtual adjustment from the derived object to its
-  /// nearest virtual base.
-  int64_t NonVirtual;
-
-  /// Holds the ABI-specific information about the virtual this
-  /// adjustment, if needed.
-  union VirtualAdjustment {
-// Itanium ABI
-struct {
-  /// The offset (in bytes), relative to the address point,
-  /// of the virtual call offset.
-  int64_t VCallOffsetOffset;
-} Itanium;
-
-struct {
-  /// The offset of the vtordisp (in bytes), relative to the ECX.
-  int32_t VtordispOffset;
-
-  /// The offset of the vbptr of the derived class (in bytes),
-  /// relative to the ECX after vtordisp adjustment.
-  int32_t VBPtrOffset;
-
-  /// The offset (in bytes) of the vbase offset in the vbtable.
-  int32_t VBOffsetOffset;
-} Microsoft;
-
-VirtualAdjustment() {
-  memset(this, 0, sizeof(*this));
-}
-
-bool Equals(const VirtualAdjustment ) const {
-  return memcmp(this, , sizeof(Other)) == 0;
-}
-
-bool isEmpty() const {
-  VirtualAdjustment Zero;
-  return Equals(Zero);
-}
-
-bool Less(const VirtualAdjustment ) const {
-  return memcmp(this, , sizeof(RHS)) < 0;
-}
-  } Virtual;
-
-  ThisAdjustment() : NonVirtual(0) { }
-
-  bool isEmpty() const { return !NonVirtual && Virtual.isEmpty(); }
-
-  friend bool operator==(const ThisAdjustment ,
- const ThisAdjustment ) {
-return LHS.NonVirtual == RHS.NonVirtual && LHS.Virtual.Equals(RHS.Virtual);
-  }
-
-  friend bool operator!=(const ThisAdjustment , const ThisAdjustment ) 
{
-

Re: [clang] 4a47da2 - [Sema] turns -Wfree-nonheap-object on by default

2021-04-30 Thread Roman Lebedev via cfe-commits
Should the diagnostic be backed out until then?

Roman

On Fri, Apr 30, 2021 at 7:52 PM Christopher Di Bella via cfe-commits
 wrote:
>
> Sorry, not yet. I'll talk with my TL to see if I can get some time allotted 
> for this in the next few weeks.
>
> On Thu, 29 Apr 2021 at 16:13, David Blaikie  wrote:
>>
>> Ping on this - have you had a chance to look at this false positive?
>>
>> On Sat, Apr 3, 2021 at 4:29 PM David Blaikie  wrote:
>> >
>> > Looks like this has a false positive (that's firing on some mlir code,
>> > committed a workaround in  499571ea835daf786626a0db1e12f890b6cd8f8d )
>> > like this:
>> >
>> > $ cat test.cpp
>> > #include 
>> > void f1(int & x) { free(); }
>> > int main() { f1(*(int*)malloc(sizeof(int))); }
>> >
>> > Could you fix that? (& then revert the workaround)
>> >
>> > On Fri, Jan 15, 2021 at 1:44 PM Christopher Di Bella via cfe-commits
>> >  wrote:
>> > >
>> > >
>> > > Author: Christopher Di Bella
>> > > Date: 2021-01-15T21:38:47Z
>> > > New Revision: 4a47da2cf440c2f2006d9b04acfef4292de1e263
>> > >
>> > > URL: 
>> > > https://github.com/llvm/llvm-project/commit/4a47da2cf440c2f2006d9b04acfef4292de1e263
>> > > DIFF: 
>> > > https://github.com/llvm/llvm-project/commit/4a47da2cf440c2f2006d9b04acfef4292de1e263.diff
>> > >
>> > > LOG: [Sema] turns -Wfree-nonheap-object on by default
>> > >
>> > > We'd discussed adding the warning to -Wall in D89988. This patch honours 
>> > > that.
>> > >
>> > > Added:
>> > >
>> > >
>> > > Modified:
>> > > clang/include/clang/Basic/DiagnosticGroups.td
>> > > clang/include/clang/Basic/DiagnosticSemaKinds.td
>> > > clang/test/Analysis/NewDelete-intersections.mm
>> > > clang/test/Analysis/free.c
>> > >
>> > > Removed:
>> > >
>> > >
>> > >
>> > > 
>> > > diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
>> > > b/clang/include/clang/Basic/DiagnosticGroups.td
>> > > index d500ab321058..04ba89aa457e 100644
>> > > --- a/clang/include/clang/Basic/DiagnosticGroups.td
>> > > +++ b/clang/include/clang/Basic/DiagnosticGroups.td
>> > > @@ -110,6 +110,7 @@ def FloatConversion :
>> > >   FloatZeroConversion]>;
>> > >
>> > >  def FrameAddress : DiagGroup<"frame-address">;
>> > > +def FreeNonHeapObject : DiagGroup<"free-nonheap-object">;
>> > >  def DoublePromotion : DiagGroup<"double-promotion">;
>> > >  def EnumTooLarge : DiagGroup<"enum-too-large">;
>> > >  def UnsupportedNan : DiagGroup<"unsupported-nan">;
>> > >
>> > > diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
>> > > b/clang/include/clang/Basic/DiagnosticSemaKinds.td
>> > > index 7d36397a7993..e93657898f58 100644
>> > > --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
>> > > +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
>> > > @@ -7609,7 +7609,7 @@ def err_no_typeid_with_fno_rtti : Error<
>> > >  def err_no_dynamic_cast_with_fno_rtti : Error<
>> > >"use of dynamic_cast requires -frtti">;
>> > >  def warn_no_dynamic_cast_with_rtti_disabled: Warning<
>> > > -  "dynamic_cast will not work since RTTI data is disabled by "
>> > > +  "dynamic_cast will not work since RTTI data is disabled by "
>> > >"%select{-fno-rtti-data|/GR-}0">, InGroup;
>> > >  def warn_no_typeid_with_rtti_disabled: Warning<
>> > >"typeid will not work since RTTI data is disabled by "
>> > > @@ -7625,8 +7625,7 @@ def warn_condition_is_assignment : Warning<"using 
>> > > the result of an "
>> > >InGroup;
>> > >  def warn_free_nonheap_object
>> > >: Warning<"attempt to call %0 on non-heap object %1">,
>> > > -InGroup>,
>> > > -DefaultIgnore; // FIXME: add to -Wall after sufficient testing
>> > > +InGroup;
>> > >
>> > >  // Completely identical except off by default.
>> > >  def warn_condition_is_idiomatic_assignment : Warning<"using the result "
>> > >
>> > > diff  --git a/clang/test/Analysis/NewDelete-intersections.mm 
>> > > b/clang/test/Analysis/NewDelete-intersections.mm
>> > > index f01d62f8d365..6f81034ee349 100644
>> > > --- a/clang/test/Analysis/NewDelete-intersections.mm
>> > > +++ b/clang/test/Analysis/NewDelete-intersections.mm
>> > > @@ -24,9 +24,6 @@
>> > >  extern "C" void free(void *);
>> > >
>> > >  void testMallocFreeNoWarn() {
>> > > -  int i;
>> > > -  free(); // no warn
>> > > -
>> > >int *p1 = (int *)malloc(sizeof(int));
>> > >free(++p1); // no warn
>> > >
>> > > @@ -51,7 +48,7 @@ void testDeleteMalloced() {
>> > >
>> > >int *p2 = (int *)__builtin_alloca(sizeof(int));
>> > >delete p2; // no warn
>> > > -}
>> > > +}
>> > >
>> > >  void testUseZeroAllocatedMalloced() {
>> > >int *p1 = (int *)malloc(0);
>> > > @@ -79,13 +76,13 @@ void testObjcFreeNewed() {
>> > >  }
>> > >
>> > >  void testFreeAfterDelete() {
>> > > -  int *p = new int;
>> > > +  int *p = new int;
>> > >delete p;
>> > >free(p); // newdelete-warning{{Use of memory after it is freed}}
>> > >  }
>> > >
>> > >  void 

Re: [clang] 1c4108a - [i386] Modify the alignment of __m128/__m256/__m512 vector type according i386 abi.

2021-04-14 Thread Roman Lebedev via cfe-commits
Reminder to please ensure that all reviews are subscribed to the
appropriate mailing lists.
This one omitted cfe-dev.

On Wed, Apr 14, 2021 at 11:47 AM via cfe-commits
 wrote:
>
>
> Author: Liu, Chen3
> Date: 2021-04-14T16:44:54+08:00
> New Revision: 1c4108ab661d43e21b1d1c804d8a403e5b0cf7d6
>
> URL: 
> https://github.com/llvm/llvm-project/commit/1c4108ab661d43e21b1d1c804d8a403e5b0cf7d6
> DIFF: 
> https://github.com/llvm/llvm-project/commit/1c4108ab661d43e21b1d1c804d8a403e5b0cf7d6.diff
>
> LOG: [i386] Modify the alignment of __m128/__m256/__m512 vector type 
> according i386 abi.
>
> According to i386 System V ABI:
>
> 1. when __m256 are required to be passed on the stack, the stack pointer must 
> be aligned on a 0 mod 32 byte boundary at the time of the call.
> 2. when __m512 are required to be passed on the stack, the stack pointer must 
> be aligned on a 0 mod 64 byte boundary at the time of the call.
>
> The current method of clang passing __m512 parameter are as follow:
>
> 1. when target supports avx512, passing it with 64 byte alignment;
> 2. when target supports avx, passing it with 32 byte alignment;
> 3. Otherwise, passing it with 16 byte alignment.
>
> Passing __m256 parameter are as follow:
>
> 1. when target supports avx or avx512, passing it with 32 byte alignment;
> 2. Otherwise, passing it with 16 byte alignment.
>
> This pach will passing __m128/__m256/__m512 following i386 System V ABI and
> apply it to Linux only since other System V OS (e.g Darwin, PS4 and FreeBSD) 
> don't
> want to spend any effort dealing with the ramifications of ABI breaks at 
> present.
>
> Differential Revision: https://reviews.llvm.org/D78564
>
> Added:
> clang/test/CodeGen/x86_32-align-linux.c
>
> Modified:
> clang/lib/CodeGen/TargetInfo.cpp
>
> Removed:
>
>
>
> 
> diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
> b/clang/lib/CodeGen/TargetInfo.cpp
> index 7f4deb21d6ed..55e38741e287 100644
> --- a/clang/lib/CodeGen/TargetInfo.cpp
> +++ b/clang/lib/CodeGen/TargetInfo.cpp
> @@ -1105,6 +1105,7 @@ class X86_32ABIInfo : public SwiftABIInfo {
>bool IsWin32StructABI;
>bool IsSoftFloatABI;
>bool IsMCUABI;
> +  bool IsLinuxABI;
>unsigned DefaultNumRegisterParameters;
>
>static bool isRegisterSize(unsigned Size) {
> @@ -1167,9 +1168,9 @@ class X86_32ABIInfo : public SwiftABIInfo {
>  unsigned NumRegisterParameters, bool SoftFloatABI)
>  : SwiftABIInfo(CGT), IsDarwinVectorABI(DarwinVectorABI),
>IsRetSmallStructInRegABI(RetSmallStructInRegABI),
> -  IsWin32StructABI(Win32StructABI),
> -  IsSoftFloatABI(SoftFloatABI),
> +  IsWin32StructABI(Win32StructABI), IsSoftFloatABI(SoftFloatABI),
>IsMCUABI(CGT.getTarget().getTriple().isOSIAMCU()),
> +  IsLinuxABI(CGT.getTarget().getTriple().isOSLinux()),
>DefaultNumRegisterParameters(NumRegisterParameters) {}
>
>bool shouldPassIndirectlyForSwift(ArrayRef scalars,
> @@ -1594,6 +1595,14 @@ unsigned 
> X86_32ABIInfo::getTypeStackAlignInBytes(QualType Ty,
>if (Align <= MinABIStackAlignInBytes)
>  return 0; // Use default alignment.
>
> +  if (IsLinuxABI) {
> +// Exclude other System V OS (e.g Darwin, PS4 and FreeBSD) since we don't
> +// want to spend any effort dealing with the ramifications of ABI breaks.
> +//
> +// If the vector type is __m128/__m256/__m512, return the default 
> alignment.
> +if (Ty->isVectorType() && (Align == 16 || Align == 32 || Align == 64))
> +  return Align;
> +  }
>// On non-Darwin, the stack type alignment is always 4.
>if (!IsDarwinVectorABI) {
>  // Set explicit alignment, since we may need to realign the top.
>
> diff  --git a/clang/test/CodeGen/x86_32-align-linux.c 
> b/clang/test/CodeGen/x86_32-align-linux.c
> new file mode 100644
> index ..6e6ddd757b6f
> --- /dev/null
> +++ b/clang/test/CodeGen/x86_32-align-linux.c
> @@ -0,0 +1,60 @@
> +// RUN: %clang_cc1 -w -fblocks -ffreestanding -triple i386-pc-linux-gnu 
> -emit-llvm -o - %s | FileCheck %s
> +// RUN: %clang_cc1 -w -fblocks -ffreestanding -triple i386-pc-linux-gnu 
> -target-feature +avx -emit-llvm -o - %s | FileCheck %s
> +// RUN: %clang_cc1 -w -fblocks -ffreestanding -triple i386-pc-linux-gnu 
> -target-feature +avx512f -emit-llvm -o - %s | FileCheck %s
> +
> +#include 
> +
> +// CHECK-LABEL: define dso_local void @testm128
> +// CHECK-LABEL: %argp.cur = load i8*, i8** %args, align 4
> +// CHECK-NEXT:  %0 = ptrtoint i8* %argp.cur to i32
> +// CHECK-NEXT:  %1 = add i32 %0, 15
> +// CHECK-NEXT:  %2 = and i32 %1, -16
> +// CHECK-NEXT:  %argp.cur.aligned = inttoptr i32 %2 to i8*
> +void testm128(int argCount, ...) {
> +  __m128 res;
> +  __builtin_va_list args;
> +  __builtin_va_start(args, argCount);
> +  res = __builtin_va_arg(args, __m128);
> +  __builtin_va_end(args);
> +}
> +
> +// CHECK-LABEL: define dso_local void @testm256
> +// CHECK-LABEL: %argp.cur = load i8*, i8** 

[clang-tools-extra] 46b8ea2 - [clang-tidy] Add check for implicit widening of multiplication result

2021-04-13 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-04-13T21:41:22+03:00
New Revision: 46b8ea2fff90b44b7ae558999721cf30f9b83aa9

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

LOG: [clang-tidy] Add check for implicit widening of multiplication result

Overflows are never fun.
In most cases (in most of the code), they are rare,
because usually you e.g. don't have as many elements.

However, it's exceptionally easy to fall into this pitfail
in code that deals with images, because, assuming 4-channel 32-bit FP data,
you need *just* ~269 megapixel image to case an overflow
when computing at least the total byte count.

In [[ https://github.com/darktable-org/darktable | darktable ]], there is a 
*long*, painful history of dealing with such bugs:
* https://github.com/darktable-org/darktable/pull/7740
* https://github.com/darktable-org/darktable/pull/7419
* 
https://github.com/darktable-org/darktable/commit/eea1989f2c9fa76710db07baaec4c19c1e40e81c
* 
https://github.com/darktable-org/darktable/commit/70626dd95bf0fab36f2d011dab075e3ebbf7aa28
* https://github.com/darktable-org/darktable/pull/670
* 
https://github.com/darktable-org/darktable/commit/38c69fb1b2bc90057c569242cb9945a10be0b583

and yet they clearly keep resurfacing still.

It would be immensely helpful to have a diagnostic for those patterns,
which is what this change proposes.

Currently, i only diagnose the most obvious case, where multiplication
is directly widened with no other expressions inbetween,
(i.e. `long r = (int)a * (int)b` but not even e.g. `long r = ((int)a * (int)b)`)
however that might be worth relaxing later.

Reviewed By: aaron.ballman

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

Added: 

clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp

clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.h

clang-tools-extra/docs/clang-tidy/checks/bugprone-implicit-widening-of-multiplication-result.rst

clang-tools-extra/test/clang-tidy/checkers/bugprone-implicit-widening-of-multiplication-result-array-subscript-expression.cpp

clang-tools-extra/test/clang-tidy/checkers/bugprone-implicit-widening-of-multiplication-result-char.cpp

clang-tools-extra/test/clang-tidy/checkers/bugprone-implicit-widening-of-multiplication-result-extint.cpp

clang-tools-extra/test/clang-tidy/checkers/bugprone-implicit-widening-of-multiplication-result-int.cpp

clang-tools-extra/test/clang-tidy/checkers/bugprone-implicit-widening-of-multiplication-result-pointer-offset.cpp

clang-tools-extra/test/clang-tidy/checkers/bugprone-implicit-widening-of-multiplication-result-short.cpp

Modified: 
clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst
clang/include/clang/AST/ASTContext.h
clang/lib/AST/ASTContext.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 7f4d40f970117..9cdadf7bf92ba 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -22,6 +22,7 @@
 #include "FoldInitTypeCheck.h"
 #include "ForwardDeclarationNamespaceCheck.h"
 #include "ForwardingReferenceOverloadCheck.h"
+#include "ImplicitWideningOfMultiplicationResultCheck.h"
 #include "InaccurateEraseCheck.h"
 #include "IncorrectRoundingsCheck.h"
 #include "InfiniteLoopCheck.h"
@@ -97,6 +98,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-forward-declaration-namespace");
 CheckFactories.registerCheck(
 "bugprone-forwarding-reference-overload");
+CheckFactories.registerCheck(
+"bugprone-implicit-widening-of-multiplication-result");
 CheckFactories.registerCheck(
 "bugprone-inaccurate-erase");
 CheckFactories.registerCheck(

diff  --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index b3684a5c101b5..b16dbf576c374 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -17,6 +17,7 @@ add_clang_library(clangTidyBugproneModule
   FoldInitTypeCheck.cpp
   ForwardDeclarationNamespaceCheck.cpp
   ForwardingReferenceOverloadCheck.cpp
+  ImplicitWideningOfMultiplicationResultCheck.cpp
   InaccurateEraseCheck.cpp
   IncorrectRoundingsCheck.cpp
   InfiniteLoopCheck.cpp

diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp
 

[clang] 6270b3a - Temporairly revert "[CGCall] Annotate `this` argument with alignment"

2021-04-10 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-04-10T10:43:16+03:00
New Revision: 6270b3a1eafaba4279e021418c5a2c5a35abc002

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

LOG: Temporairly revert "[CGCall] Annotate `this` argument with alignment"

As per @jyknight, "It seems like there's a bug with vtable thunks getting the 
wrong information."
See https://reviews.llvm.org/D99790#2680857, https://godbolt.org/z/MxhYMe1q7

This reverts commit 0aa0458f1429372038ca6a4edc7e94c96cd9a753.

Added: 


Modified: 
clang/lib/CodeGen/CGCall.cpp
clang/test/CodeGen/attr-nomerge.cpp
clang/test/CodeGenCXX/this-nonnull.cpp
clang/test/CodeGenCoroutines/coro-symmetric-transfer-01.cpp
clang/test/CodeGenObjCXX/objc-struct-cxx-abi.mm
clang/test/OpenMP/irbuilder_for_iterator.cpp
clang/test/OpenMP/irbuilder_for_rangefor.cpp
clang/test/utils/update_cc_test_checks/Inputs/basic-cplusplus.cpp.expected

Removed: 




diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 06f9253e6bfb1..1d71148d67e67 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -2295,7 +2295,7 @@ void CodeGenModule::ConstructAttributeList(
 llvm::AttributeSet::get(getLLVMContext(), Attrs);
   }
 
-  // Apply `nonnull`, `dereferencable(N)` and `align N` to the `this` argument.
+  // Apply `nonnull` and `dereferencable(N)` to the `this` argument.
   if (FI.isInstanceMethod() && !IRFunctionArgs.hasInallocaArg() &&
   !FI.arg_begin()->type->isVoidPointerType()) {
 auto IRArgs = IRFunctionArgs.getIRArgs(0);
@@ -2304,13 +2304,13 @@ void CodeGenModule::ConstructAttributeList(
 
 llvm::AttrBuilder Attrs;
 
-QualType ThisTy =
-FI.arg_begin()->type.castAs()->getPointeeType();
-
 if (!CodeGenOpts.NullPointerIsValid &&
 getContext().getTargetAddressSpace(FI.arg_begin()->type) == 0) {
   Attrs.addAttribute(llvm::Attribute::NonNull);
-  Attrs.addDereferenceableAttr(getMinimumObjectSize(ThisTy).getQuantity());
+  Attrs.addDereferenceableAttr(
+  getMinimumObjectSize(
+  FI.arg_begin()->type.castAs()->getPointeeType())
+  .getQuantity());
 } else {
   // FIXME dereferenceable should be correct here, regardless of
   // NullPointerIsValid. However, dereferenceable currently does not always
@@ -2322,12 +2322,6 @@ void CodeGenModule::ConstructAttributeList(
   .getQuantity());
 }
 
-llvm::Align Alignment =
-getNaturalTypeAlignment(ThisTy, /*BaseInfo=*/nullptr,
-/*TBAAInfo=*/nullptr, /*forPointeeType=*/true)
-.getAsAlign();
-Attrs.addAlignmentAttr(Alignment);
-
 ArgAttrs[IRArgs.first] = llvm::AttributeSet::get(getLLVMContext(), Attrs);
   }
 

diff  --git a/clang/test/CodeGen/attr-nomerge.cpp 
b/clang/test/CodeGen/attr-nomerge.cpp
index da0c33bb384c7..fc26af379fdb7 100644
--- a/clang/test/CodeGen/attr-nomerge.cpp
+++ b/clang/test/CodeGen/attr-nomerge.cpp
@@ -77,7 +77,7 @@ void something_else_again() {
 // CHECK: %[[AG:.*]] = load void (%class.A*)*, void (%class.A*)**
 // CHECK-NEXT: call void %[[AG]](%class.A* {{.*}}) #[[ATTR0]]
 // CHECK: %[[BG:.*]] = load void (%class.B*)*, void (%class.B*)**
-// CHECK-NEXT: call void %[[BG]](%class.B* nonnull align {{.*}} dereferenceable
+// CHECK-NEXT: call void %[[BG]](%class.B* nonnull dereferenceable
 // CHECK: call void @_ZN1AC1Ev({{.*}}) #[[ATTR0]]
 // CHECK: call void @_ZN1A1fEv({{.*}}) #[[ATTR0]]
 // CHECK: call void @_ZN1A1gEv({{.*}}) #[[ATTR0]]

diff  --git a/clang/test/CodeGenCXX/this-nonnull.cpp 
b/clang/test/CodeGenCXX/this-nonnull.cpp
index 7f146b6613991..63873388b0707 100644
--- a/clang/test/CodeGenCXX/this-nonnull.cpp
+++ b/clang/test/CodeGenCXX/this-nonnull.cpp
@@ -11,10 +11,10 @@ struct Struct {
 void TestReturnsVoid(Struct ) {
   s.ReturnsVoid();
 
-  // CHECK-YES: call void @_ZN6Struct11ReturnsVoidEv(%struct.Struct* nonnull 
align 4 dereferenceable(12) %0)
+  // CHECK-YES: call void @_ZN6Struct11ReturnsVoidEv(%struct.Struct* nonnull 
dereferenceable(12) %0)
   /// FIXME Use dereferenceable after dereferenceable respects 
NullPointerIsValid.
-  // CHECK-NO: call void @_ZN6Struct11ReturnsVoidEv(%struct.Struct* align 4 
dereferenceable_or_null(12) %0)
+  // CHECK-NO: call void @_ZN6Struct11ReturnsVoidEv(%struct.Struct* 
dereferenceable_or_null(12) %0)
 }
 
-// CHECK-YES: declare void @_ZN6Struct11ReturnsVoidEv(%struct.Struct* nonnull 
align 4 dereferenceable(12))
-// CHECK-NO: declare void @_ZN6Struct11ReturnsVoidEv(%struct.Struct* align 4 
dereferenceable_or_null(12))
+// CHECK-YES: declare void @_ZN6Struct11ReturnsVoidEv(%struct.Struct* nonnull 
dereferenceable(12))
+// CHECK-NO: declare void @_ZN6Struct11ReturnsVoidEv(%struct.Struct* 

[clang] 2829094 - Reland [InstCombine] Fold `((X - Y) - Z)` to `X - (Y + Z)` (PR49858)

2021-04-07 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-04-07T12:06:25+03:00
New Revision: 2829094a8e252d04f13aabdf6f416c42a06af695

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

LOG: Reland [InstCombine] Fold `((X - Y) - Z)` to `X - (Y + Z)` (PR49858)

This reverts commit a547b4e26b311e417cd51100e379693f51a3f448,
relanding commit 31d219d2997fed1b7dc97e0adf170d5aaf65883e,
which was reverted because there was a conflicting inverse transform,
which was causing an endless combine loop, which has now been adjusted.

Original commit message:

https://alive2.llvm.org/ce/z/67w-wQ

We prefer `add`s over `sub`, and this particular xform
allows further folds to happen:

Fixes https://bugs.llvm.org/show_bug.cgi?id=49858

Added: 


Modified: 
clang/test/CodeGen/builtins-ppc-quadword-noi128.c
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/test/Transforms/InstCombine/abs-1.ll
llvm/test/Transforms/InstCombine/sub-from-sub.ll

Removed: 




diff  --git a/clang/test/CodeGen/builtins-ppc-quadword-noi128.c 
b/clang/test/CodeGen/builtins-ppc-quadword-noi128.c
index bc97db2be1e9..d42a82958b08 100644
--- a/clang/test/CodeGen/builtins-ppc-quadword-noi128.c
+++ b/clang/test/CodeGen/builtins-ppc-quadword-noi128.c
@@ -75,8 +75,8 @@ vector unsigned char test_sube(vector unsigned char a, vector 
unsigned char b,
 // CHECK-LE-NEXT:[[TMP0:%.*]] = bitcast <16 x i8> [[B:%.*]] to <1 x i128>
 // CHECK-LE-NEXT:[[TMP1:%.*]] = bitcast <16 x i8> [[C:%.*]] to <1 x i128>
 // CHECK-LE-NEXT:[[TMP2:%.*]] = bitcast <16 x i8> [[A:%.*]] to <1 x i128>
-// CHECK-LE-NEXT:[[VADDUQM_I_NEG:%.*]] = sub <1 x i128> [[TMP2]], [[TMP0]]
-// CHECK-LE-NEXT:[[VSUBUQM_I:%.*]] = sub <1 x i128> [[VADDUQM_I_NEG]], 
[[TMP1]]
+// CHECK-LE-NEXT:[[VADDUQM_I_NEG:%.*]] = add <1 x i128> [[TMP0]], [[TMP1]]
+// CHECK-LE-NEXT:[[VSUBUQM_I:%.*]] = sub <1 x i128> [[TMP2]], 
[[VADDUQM_I_NEG]]
 // CHECK-LE-NEXT:[[TMP3:%.*]] = bitcast <1 x i128> [[VSUBUQM_I]] to <16 x 
i8>
 // CHECK-LE-NEXT:ret <16 x i8> [[TMP3]]
 //
@@ -85,8 +85,8 @@ vector unsigned char test_sube(vector unsigned char a, vector 
unsigned char b,
 // CHECK-AIX-NEXT:[[TMP0:%.*]] = bitcast <16 x i8> [[B:%.*]] to <1 x i128>
 // CHECK-AIX-NEXT:[[TMP1:%.*]] = bitcast <16 x i8> [[C:%.*]] to <1 x i128>
 // CHECK-AIX-NEXT:[[TMP2:%.*]] = bitcast <16 x i8> [[A:%.*]] to <1 x i128>
-// CHECK-AIX-NEXT:[[VADDUQM_I_NEG:%.*]] = sub <1 x i128> [[TMP2]], [[TMP0]]
-// CHECK-AIX-NEXT:[[VSUBUQM_I:%.*]] = sub <1 x i128> [[VADDUQM_I_NEG]], 
[[TMP1]]
+// CHECK-AIX-NEXT:[[VADDUQM_I_NEG:%.*]] = add <1 x i128> [[TMP0]], [[TMP1]]
+// CHECK-AIX-NEXT:[[VSUBUQM_I:%.*]] = sub <1 x i128> [[TMP2]], 
[[VADDUQM_I_NEG]]
 // CHECK-AIX-NEXT:[[TMP3:%.*]] = bitcast <1 x i128> [[VSUBUQM_I]] to <16 x 
i8>
 // CHECK-AIX-NEXT:ret <16 x i8> [[TMP3]]
 //

diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index 98cd7af4bf0c..7b33e29c59de 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -1802,6 +1802,12 @@ Instruction *InstCombinerImpl::visitSub(BinaryOperator 
) {
 return BinaryOperator::CreateSub(XZ, YW);
   }
 
+  // ((X - Y) - Op1)  -->  X - (Y + Op1)
+  if (match(Op0, m_OneUse(m_Sub(m_Value(X), m_Value(Y) {
+Value *Add = Builder.CreateAdd(Y, Op1);
+return BinaryOperator::CreateSub(X, Add);
+  }
+
   auto m_AddRdx = [](Value *) {
 return m_OneUse(m_Intrinsic(m_Value(Vec)));
   };

diff  --git a/llvm/test/Transforms/InstCombine/abs-1.ll 
b/llvm/test/Transforms/InstCombine/abs-1.ll
index 7452798ead77..ea77dfb5fef4 100644
--- a/llvm/test/Transforms/InstCombine/abs-1.ll
+++ b/llvm/test/Transforms/InstCombine/abs-1.ll
@@ -305,9 +305,9 @@ define i32 @nabs_canonical_8(i32 %a) {
 define i32 @nabs_canonical_9(i32 %a, i32 %b) {
 ; CHECK-LABEL: @nabs_canonical_9(
 ; CHECK-NEXT:[[T1:%.*]] = sub i32 [[A:%.*]], [[B:%.*]]
-; CHECK-NEXT:[[T2:%.*]] = sub i32 [[B]], [[A]]
 ; CHECK-NEXT:[[TMP1:%.*]] = call i32 @llvm.abs.i32(i32 [[T1]], i1 false)
-; CHECK-NEXT:[[ADD:%.*]] = sub i32 [[T2]], [[TMP1]]
+; CHECK-NEXT:[[TMP2:%.*]] = add i32 [[TMP1]], [[A]]
+; CHECK-NEXT:[[ADD:%.*]] = sub i32 [[B]], [[TMP2]]
 ; CHECK-NEXT:ret i32 [[ADD]]
 ;
   %t1 = sub i32 %a, %b

diff  --git a/llvm/test/Transforms/InstCombine/sub-from-sub.ll 
b/llvm/test/Transforms/InstCombine/sub-from-sub.ll
index 4d5ba0ea4dbc..0669efe2dd0e 100644
--- a/llvm/test/Transforms/InstCombine/sub-from-sub.ll
+++ b/llvm/test/Transforms/InstCombine/sub-from-sub.ll
@@ -8,8 +8,8 @@ declare void @use8(i8)
 ; Basic test
 define i8 @t0(i8 %x, i8 %y, i8 %z) {
 ; CHECK-LABEL: @t0(
-; CHECK-NEXT:[[I0:%.*]] = sub i8 [[X:%.*]], 

[clang] 0aa0458 - [CGCall] Annotate `this` argument with alignment

2021-04-07 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-04-07T11:02:01+03:00
New Revision: 0aa0458f1429372038ca6a4edc7e94c96cd9a753

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

LOG: [CGCall] Annotate `this` argument with alignment

As it is being noted in D99249, lack of alignment information on `this`
has been preventing LICM from happening.

For some time now, lack of alignment attribute does *not* imply
natural alignment, but an alignment of `1`.
Also, we used to treat dereferenceable as implying alignment,
but we no longer do, so it's a bugfix.

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

Added: 


Modified: 
clang/lib/CodeGen/CGCall.cpp
clang/test/CodeGen/attr-nomerge.cpp
clang/test/CodeGenCXX/this-nonnull.cpp
clang/test/CodeGenCoroutines/coro-symmetric-transfer-01.cpp
clang/test/CodeGenObjCXX/objc-struct-cxx-abi.mm
clang/test/OpenMP/irbuilder_for_iterator.cpp
clang/test/OpenMP/irbuilder_for_rangefor.cpp
clang/test/utils/update_cc_test_checks/Inputs/basic-cplusplus.cpp.expected

Removed: 




diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 1d71148d67e67..06f9253e6bfb1 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -2295,7 +2295,7 @@ void CodeGenModule::ConstructAttributeList(
 llvm::AttributeSet::get(getLLVMContext(), Attrs);
   }
 
-  // Apply `nonnull` and `dereferencable(N)` to the `this` argument.
+  // Apply `nonnull`, `dereferencable(N)` and `align N` to the `this` argument.
   if (FI.isInstanceMethod() && !IRFunctionArgs.hasInallocaArg() &&
   !FI.arg_begin()->type->isVoidPointerType()) {
 auto IRArgs = IRFunctionArgs.getIRArgs(0);
@@ -2304,13 +2304,13 @@ void CodeGenModule::ConstructAttributeList(
 
 llvm::AttrBuilder Attrs;
 
+QualType ThisTy =
+FI.arg_begin()->type.castAs()->getPointeeType();
+
 if (!CodeGenOpts.NullPointerIsValid &&
 getContext().getTargetAddressSpace(FI.arg_begin()->type) == 0) {
   Attrs.addAttribute(llvm::Attribute::NonNull);
-  Attrs.addDereferenceableAttr(
-  getMinimumObjectSize(
-  FI.arg_begin()->type.castAs()->getPointeeType())
-  .getQuantity());
+  Attrs.addDereferenceableAttr(getMinimumObjectSize(ThisTy).getQuantity());
 } else {
   // FIXME dereferenceable should be correct here, regardless of
   // NullPointerIsValid. However, dereferenceable currently does not always
@@ -2322,6 +2322,12 @@ void CodeGenModule::ConstructAttributeList(
   .getQuantity());
 }
 
+llvm::Align Alignment =
+getNaturalTypeAlignment(ThisTy, /*BaseInfo=*/nullptr,
+/*TBAAInfo=*/nullptr, /*forPointeeType=*/true)
+.getAsAlign();
+Attrs.addAlignmentAttr(Alignment);
+
 ArgAttrs[IRArgs.first] = llvm::AttributeSet::get(getLLVMContext(), Attrs);
   }
 

diff  --git a/clang/test/CodeGen/attr-nomerge.cpp 
b/clang/test/CodeGen/attr-nomerge.cpp
index fc26af379fdb7..da0c33bb384c7 100644
--- a/clang/test/CodeGen/attr-nomerge.cpp
+++ b/clang/test/CodeGen/attr-nomerge.cpp
@@ -77,7 +77,7 @@ void something_else_again() {
 // CHECK: %[[AG:.*]] = load void (%class.A*)*, void (%class.A*)**
 // CHECK-NEXT: call void %[[AG]](%class.A* {{.*}}) #[[ATTR0]]
 // CHECK: %[[BG:.*]] = load void (%class.B*)*, void (%class.B*)**
-// CHECK-NEXT: call void %[[BG]](%class.B* nonnull dereferenceable
+// CHECK-NEXT: call void %[[BG]](%class.B* nonnull align {{.*}} dereferenceable
 // CHECK: call void @_ZN1AC1Ev({{.*}}) #[[ATTR0]]
 // CHECK: call void @_ZN1A1fEv({{.*}}) #[[ATTR0]]
 // CHECK: call void @_ZN1A1gEv({{.*}}) #[[ATTR0]]

diff  --git a/clang/test/CodeGenCXX/this-nonnull.cpp 
b/clang/test/CodeGenCXX/this-nonnull.cpp
index 63873388b0707..7f146b6613991 100644
--- a/clang/test/CodeGenCXX/this-nonnull.cpp
+++ b/clang/test/CodeGenCXX/this-nonnull.cpp
@@ -11,10 +11,10 @@ struct Struct {
 void TestReturnsVoid(Struct ) {
   s.ReturnsVoid();
 
-  // CHECK-YES: call void @_ZN6Struct11ReturnsVoidEv(%struct.Struct* nonnull 
dereferenceable(12) %0)
+  // CHECK-YES: call void @_ZN6Struct11ReturnsVoidEv(%struct.Struct* nonnull 
align 4 dereferenceable(12) %0)
   /// FIXME Use dereferenceable after dereferenceable respects 
NullPointerIsValid.
-  // CHECK-NO: call void @_ZN6Struct11ReturnsVoidEv(%struct.Struct* 
dereferenceable_or_null(12) %0)
+  // CHECK-NO: call void @_ZN6Struct11ReturnsVoidEv(%struct.Struct* align 4 
dereferenceable_or_null(12) %0)
 }
 
-// CHECK-YES: declare void @_ZN6Struct11ReturnsVoidEv(%struct.Struct* nonnull 
dereferenceable(12))
-// CHECK-NO: declare void @_ZN6Struct11ReturnsVoidEv(%struct.Struct* 
dereferenceable_or_null(12))
+// CHECK-YES: declare void @_ZN6Struct11ReturnsVoidEv(%struct.Struct* nonnull 
align 4 

[clang] 849d372 - [NFC][Clang] Speculative fix for builtins-ppc-quadword-noi128.c

2021-04-06 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-04-06T16:15:23+03:00
New Revision: 849d3729433e05e6d89892c1814fa07ed3ec18e2

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

LOG: [NFC][Clang] Speculative fix for builtins-ppc-quadword-noi128.c

Added: 


Modified: 
clang/test/CodeGen/builtins-ppc-quadword-noi128.c

Removed: 




diff  --git a/clang/test/CodeGen/builtins-ppc-quadword-noi128.c 
b/clang/test/CodeGen/builtins-ppc-quadword-noi128.c
index bc97db2be1e9..d42a82958b08 100644
--- a/clang/test/CodeGen/builtins-ppc-quadword-noi128.c
+++ b/clang/test/CodeGen/builtins-ppc-quadword-noi128.c
@@ -75,8 +75,8 @@ vector unsigned char test_sube(vector unsigned char a, vector 
unsigned char b,
 // CHECK-LE-NEXT:[[TMP0:%.*]] = bitcast <16 x i8> [[B:%.*]] to <1 x i128>
 // CHECK-LE-NEXT:[[TMP1:%.*]] = bitcast <16 x i8> [[C:%.*]] to <1 x i128>
 // CHECK-LE-NEXT:[[TMP2:%.*]] = bitcast <16 x i8> [[A:%.*]] to <1 x i128>
-// CHECK-LE-NEXT:[[VADDUQM_I_NEG:%.*]] = sub <1 x i128> [[TMP2]], [[TMP0]]
-// CHECK-LE-NEXT:[[VSUBUQM_I:%.*]] = sub <1 x i128> [[VADDUQM_I_NEG]], 
[[TMP1]]
+// CHECK-LE-NEXT:[[VADDUQM_I_NEG:%.*]] = add <1 x i128> [[TMP0]], [[TMP1]]
+// CHECK-LE-NEXT:[[VSUBUQM_I:%.*]] = sub <1 x i128> [[TMP2]], 
[[VADDUQM_I_NEG]]
 // CHECK-LE-NEXT:[[TMP3:%.*]] = bitcast <1 x i128> [[VSUBUQM_I]] to <16 x 
i8>
 // CHECK-LE-NEXT:ret <16 x i8> [[TMP3]]
 //
@@ -85,8 +85,8 @@ vector unsigned char test_sube(vector unsigned char a, vector 
unsigned char b,
 // CHECK-AIX-NEXT:[[TMP0:%.*]] = bitcast <16 x i8> [[B:%.*]] to <1 x i128>
 // CHECK-AIX-NEXT:[[TMP1:%.*]] = bitcast <16 x i8> [[C:%.*]] to <1 x i128>
 // CHECK-AIX-NEXT:[[TMP2:%.*]] = bitcast <16 x i8> [[A:%.*]] to <1 x i128>
-// CHECK-AIX-NEXT:[[VADDUQM_I_NEG:%.*]] = sub <1 x i128> [[TMP2]], [[TMP0]]
-// CHECK-AIX-NEXT:[[VSUBUQM_I:%.*]] = sub <1 x i128> [[VADDUQM_I_NEG]], 
[[TMP1]]
+// CHECK-AIX-NEXT:[[VADDUQM_I_NEG:%.*]] = add <1 x i128> [[TMP0]], [[TMP1]]
+// CHECK-AIX-NEXT:[[VSUBUQM_I:%.*]] = sub <1 x i128> [[TMP2]], 
[[VADDUQM_I_NEG]]
 // CHECK-AIX-NEXT:[[TMP3:%.*]] = bitcast <1 x i128> [[VSUBUQM_I]] to <16 x 
i8>
 // CHECK-AIX-NEXT:ret <16 x i8> [[TMP3]]
 //



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


[clang] be87321 - [clang][Codegen] EmitBranchOnBoolExpr(): emit prof branch counts even at -O0

2021-03-21 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-03-21T23:24:27+03:00
New Revision: be8732128029530a0b8671af3a47ce6085039fa2

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

LOG: [clang][Codegen] EmitBranchOnBoolExpr(): emit prof branch counts even at 
-O0

This restores the original behaviour before i unadvertedly broke it in
e3a470162738871bba982416748ae5f5e3572947 and clang/test/Profile/ caught it.

Added: 


Modified: 
clang/lib/CodeGen/CodeGenFunction.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 1c538262737d..fd708849e609 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1774,27 +1774,27 @@ void CodeGenFunction::EmitBranchOnBoolExpr(const Expr 
*Cond,
   llvm::MDNode *Weights = nullptr;
   llvm::MDNode *Unpredictable = nullptr;
 
-  // If optimizing, lower unpredictability/probability knowledge about cond.
-  if (CGM.getCodeGenOpts().OptimizationLevel != 0) {
-// If the branch has a condition wrapped by __builtin_unpredictable,
-// create metadata that specifies that the branch is unpredictable.
-if (auto *Call = dyn_cast(Cond->IgnoreImpCasts())) {
-  auto *FD = dyn_cast_or_null(Call->getCalleeDecl());
-  if (FD && FD->getBuiltinID() == Builtin::BI__builtin_unpredictable) {
-llvm::MDBuilder MDHelper(getLLVMContext());
-Unpredictable = MDHelper.createUnpredictable();
-  }
+  // If the branch has a condition wrapped by __builtin_unpredictable,
+  // create metadata that specifies that the branch is unpredictable.
+  // Don't bother if not optimizing because that metadata would not be used.
+  auto *Call = dyn_cast(Cond->IgnoreImpCasts());
+  if (Call && CGM.getCodeGenOpts().OptimizationLevel != 0) {
+auto *FD = dyn_cast_or_null(Call->getCalleeDecl());
+if (FD && FD->getBuiltinID() == Builtin::BI__builtin_unpredictable) {
+  llvm::MDBuilder MDHelper(getLLVMContext());
+  Unpredictable = MDHelper.createUnpredictable();
 }
+  }
 
-// If there is a Likelihood knowledge for the cond, lower it.
-llvm::Value *NewCondV = emitCondLikelihoodViaExpectIntrinsic(CondV, LH);
-if (CondV != NewCondV)
-  CondV = NewCondV;
-else {
-  // Otherwise, lower profile counts.
-  uint64_t CurrentCount = std::max(getCurrentProfileCount(), TrueCount);
-  Weights = createProfileWeights(TrueCount, CurrentCount - TrueCount);
-}
+  // If there is a Likelihood knowledge for the cond, lower it.
+  // Note that if not optimizing this won't emit anything.
+  llvm::Value *NewCondV = emitCondLikelihoodViaExpectIntrinsic(CondV, LH);
+  if (CondV != NewCondV)
+CondV = NewCondV;
+  else {
+// Otherwise, lower profile counts. Note that we do this even at -O0.
+uint64_t CurrentCount = std::max(getCurrentProfileCount(), TrueCount);
+Weights = createProfileWeights(TrueCount, CurrentCount - TrueCount);
   }
 
   Builder.CreateCondBr(CondV, TrueBlock, FalseBlock, Weights, Unpredictable);



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


[clang] e3a4701 - [clang][CodeGen] Lower Likelihood attributes to @llvm.expect intrin instead of branch weights

2021-03-21 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-03-21T22:50:21+03:00
New Revision: e3a470162738871bba982416748ae5f5e3572947

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

LOG: [clang][CodeGen] Lower Likelihood attributes to @llvm.expect intrin 
instead of branch weights

08196e0b2e1f8aaa8a854585335c17ba479114df exposed LowerExpectIntrinsic's
internal implementation detail in the form of
LikelyBranchWeight/UnlikelyBranchWeight options to the outside.

While this isn't incorrect from the results viewpoint,
this is suboptimal from the layering viewpoint,
and causes confusion - should transforms also use those weights,
or should they use something else, D98898?

So go back to status quo by making LikelyBranchWeight/UnlikelyBranchWeight
internal again, and fixing all the code that used it directly,
which currently is only clang codegen, thankfully,
to emit proper @llvm.expect intrinsics instead.

Added: 


Modified: 
clang/lib/CodeGen/CGStmt.cpp
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/test/CodeGenCXX/attr-likelihood-iteration-stmt.cpp
clang/test/CodeGenCXX/attr-likelihood-switch-branch-weights.cpp
llvm/include/llvm/Transforms/Scalar/LowerExpectIntrinsic.h
llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 38f3aa941415e..fb719efb1a35d 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -821,8 +821,11 @@ void CodeGenFunction::EmitWhileStmt(const WhileStmt ,
 llvm::BasicBlock *ExitBlock = LoopExit.getBlock();
 if (ConditionScope.requiresCleanups())
   ExitBlock = createBasicBlock("while.exit");
-llvm::MDNode *Weights = createProfileOrBranchWeightsForLoop(
-S.getCond(), getProfileCount(S.getBody()), S.getBody());
+llvm::MDNode *Weights =
+createProfileWeightsForLoop(S.getCond(), getProfileCount(S.getBody()));
+if (!Weights && CGM.getCodeGenOpts().OptimizationLevel)
+  BoolCondVal = emitCondLikelihoodViaExpectIntrinsic(
+  BoolCondVal, Stmt::getLikelihood(S.getBody()));
 Builder.CreateCondBr(BoolCondVal, LoopBody, ExitBlock, Weights);
 
 if (ExitBlock != LoopExit.getBlock()) {
@@ -1008,8 +1011,11 @@ void CodeGenFunction::EmitForStmt(const ForStmt ,
 // C99 6.8.5p2/p4: The first substatement is executed if the expression
 // compares unequal to 0.  The condition must be a scalar type.
 llvm::Value *BoolCondVal = EvaluateExprAsBool(S.getCond());
-llvm::MDNode *Weights = createProfileOrBranchWeightsForLoop(
-S.getCond(), getProfileCount(S.getBody()), S.getBody());
+llvm::MDNode *Weights =
+createProfileWeightsForLoop(S.getCond(), getProfileCount(S.getBody()));
+if (!Weights && CGM.getCodeGenOpts().OptimizationLevel)
+  BoolCondVal = emitCondLikelihoodViaExpectIntrinsic(
+  BoolCondVal, Stmt::getLikelihood(S.getBody()));
 
 if (llvm::ConstantInt *C = dyn_cast(BoolCondVal))
   if (C->isOne())
@@ -1094,8 +1100,11 @@ CodeGenFunction::EmitCXXForRangeStmt(const 
CXXForRangeStmt ,
   // The body is executed if the expression, contextually converted
   // to bool, is true.
   llvm::Value *BoolCondVal = EvaluateExprAsBool(S.getCond());
-  llvm::MDNode *Weights = createProfileOrBranchWeightsForLoop(
-  S.getCond(), getProfileCount(S.getBody()), S.getBody());
+  llvm::MDNode *Weights =
+  createProfileWeightsForLoop(S.getCond(), getProfileCount(S.getBody()));
+  if (!Weights && CGM.getCodeGenOpts().OptimizationLevel)
+BoolCondVal = emitCondLikelihoodViaExpectIntrinsic(
+BoolCondVal, Stmt::getLikelihood(S.getBody()));
   Builder.CreateCondBr(BoolCondVal, ForBody, ExitBlock, Weights);
 
   if (ExitBlock != LoopExit.getBlock()) {
@@ -1369,7 +1378,7 @@ void CodeGenFunction::EmitCaseStmtRange(const CaseStmt ,
 // this case.
 (*SwitchWeights)[0] += ThisCount;
   } else if (SwitchLikelihood)
-Weights = createBranchWeights(LH);
+Cond = emitCondLikelihoodViaExpectIntrinsic(Cond, LH);
 
   Builder.CreateCondBr(Cond, CaseDest, FalseDest, Weights);
 

diff  --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index a00ae74fa165f..1c538262737dd 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1764,31 +1764,39 @@ void CodeGenFunction::EmitBranchOnBoolExpr(const Expr 
*Cond,
 return;
   }
 
-  // If the branch has a condition wrapped by __builtin_unpredictable,
-  // create metadata that specifies that the branch is unpredictable.
-  // Don't bother if not optimizing because that metadata would not be used.
-  llvm::MDNode *Unpredictable = nullptr;
-  auto *Call = dyn_cast(Cond->IgnoreImpCasts());
-  if 

[clang] 37d6be9 - Revert "[BranchProbability] move options for 'likely' and 'unlikely'"

2021-03-21 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-03-21T22:50:21+03:00
New Revision: 37d6be90524ca1659521ab879aaae5e5501f1e97

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

LOG: Revert "[BranchProbability] move options for 'likely' and 'unlikely'"

Upon reviewing D98898 i've come to realization that these are
implementation detail of LowerExpectIntrinsicPass,
and they should not be exposed to outside of it.

This reverts commit ee8b53815ddf6f6f94ade0068903cd5ae843fafa.

Added: 


Modified: 
clang/lib/CodeGen/CodeGenFunction.cpp
llvm/include/llvm/Support/BranchProbability.h
llvm/include/llvm/Transforms/Scalar/LowerExpectIntrinsic.h
llvm/lib/Support/BranchProbability.cpp
llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 18927b46958c8..a00ae74fa165f 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -42,8 +42,8 @@
 #include "llvm/IR/Intrinsics.h"
 #include "llvm/IR/MDBuilder.h"
 #include "llvm/IR/Operator.h"
-#include "llvm/Support/BranchProbability.h"
 #include "llvm/Support/CRC.h"
+#include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"
 #include "llvm/Transforms/Utils/PromoteMemToReg.h"
 using namespace clang;
 using namespace CodeGen;

diff  --git a/llvm/include/llvm/Support/BranchProbability.h 
b/llvm/include/llvm/Support/BranchProbability.h
index f977c70221a5d..6c7ad1fe2a52c 100644
--- a/llvm/include/llvm/Support/BranchProbability.h
+++ b/llvm/include/llvm/Support/BranchProbability.h
@@ -13,7 +13,6 @@
 #ifndef LLVM_SUPPORT_BRANCHPROBABILITY_H
 #define LLVM_SUPPORT_BRANCHPROBABILITY_H
 
-#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/DataTypes.h"
 #include 
 #include 
@@ -22,9 +21,6 @@
 
 namespace llvm {
 
-extern cl::opt LikelyBranchWeight;
-extern cl::opt UnlikelyBranchWeight;
-
 class raw_ostream;
 
 // This class represents Branch Probability as a non-negative fraction that is

diff  --git a/llvm/include/llvm/Transforms/Scalar/LowerExpectIntrinsic.h 
b/llvm/include/llvm/Transforms/Scalar/LowerExpectIntrinsic.h
index 4e47ff70d5574..22b2e649e4d48 100644
--- a/llvm/include/llvm/Transforms/Scalar/LowerExpectIntrinsic.h
+++ b/llvm/include/llvm/Transforms/Scalar/LowerExpectIntrinsic.h
@@ -17,6 +17,7 @@
 
 #include "llvm/IR/Function.h"
 #include "llvm/IR/PassManager.h"
+#include "llvm/Support/CommandLine.h"
 
 namespace llvm {
 
@@ -31,6 +32,8 @@ struct LowerExpectIntrinsicPass : 
PassInfoMixin {
   PreservedAnalyses run(Function , FunctionAnalysisManager &);
 };
 
+extern cl::opt LikelyBranchWeight;
+extern cl::opt UnlikelyBranchWeight;
 }
 
 #endif

diff  --git a/llvm/lib/Support/BranchProbability.cpp 
b/llvm/lib/Support/BranchProbability.cpp
index d93d9cffb9f73..60d5478a90529 100644
--- a/llvm/lib/Support/BranchProbability.cpp
+++ b/llvm/lib/Support/BranchProbability.cpp
@@ -19,20 +19,6 @@
 
 using namespace llvm;
 
-// These default values are chosen to represent an extremely skewed outcome for
-// a condition, but they leave some room for interpretation by later passes.
-//
-// If the documentation for __builtin_expect() was made explicit that it should
-// only be used in extreme cases, we could make this ratio higher. As it 
stands,
-// programmers may be using __builtin_expect() / llvm.expect to annotate that a
-// branch is only mildly likely or unlikely to be taken.
-cl::opt llvm::LikelyBranchWeight(
-"likely-branch-weight", cl::Hidden, cl::init(2000),
-cl::desc("Weight of the branch likely to be taken (default = 2000)"));
-cl::opt llvm::UnlikelyBranchWeight(
-"unlikely-branch-weight", cl::Hidden, cl::init(1),
-cl::desc("Weight of the branch unlikely to be taken (default = 1)"));
-
 constexpr uint32_t BranchProbability::D;
 
 raw_ostream ::print(raw_ostream ) const {

diff  --git a/llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp 
b/llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
index d862fcfe8ce56..da13075dfee26 100644
--- a/llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
+++ b/llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
@@ -24,7 +24,6 @@
 #include "llvm/IR/Metadata.h"
 #include "llvm/InitializePasses.h"
 #include "llvm/Pass.h"
-#include "llvm/Support/BranchProbability.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Transforms/Scalar.h"
 
@@ -35,6 +34,25 @@ using namespace llvm;
 STATISTIC(ExpectIntrinsicsHandled,
   "Number of 'expect' intrinsic instructions handled");
 
+// These default values are chosen to represent an extremely skewed outcome for
+// a condition, but they leave some room for interpretation by later passes.
+//
+// If the documentation for __builtin_expect() was made explicit that it should
+// only be used in extreme 

[clang] 897c985 - [InstCombine] Canonicalize SPF to abs intrinsic

2020-12-18 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2020-12-18T21:18:14+03:00
New Revision: 897c985e1e21927b2870f964bb07ff293bd74407

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

LOG: [InstCombine] Canonicalize SPF to abs intrinsic

This patch enables canonicalization of SPF_ABS and SPF_ABS
to the abs intrinsic.

This is a recommit, the original try was
05d4c4ebc2fb006b8a2bd05b24c6aba10dd2eef8,
but it was reverted due to an apparent miscompile,
which since then has just been fixed by the previous commit.

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

Added: 


Modified: 
clang/test/CodeGen/builtins-wasm.c
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
llvm/test/Transforms/InstCombine/abs-1.ll
llvm/test/Transforms/InstCombine/abs_abs.ll
llvm/test/Transforms/InstCombine/call-callconv.ll
llvm/test/Transforms/InstCombine/cttz-abs.ll
llvm/test/Transforms/InstCombine/icmp.ll
llvm/test/Transforms/InstCombine/max-of-nots.ll
llvm/test/Transforms/InstCombine/select_meta.ll
llvm/test/Transforms/InstCombine/sub-of-negatible.ll
llvm/test/Transforms/PhaseOrdering/X86/vector-reductions.ll
llvm/test/Transforms/PhaseOrdering/min-max-abs-cse.ll

Removed: 




diff  --git a/clang/test/CodeGen/builtins-wasm.c 
b/clang/test/CodeGen/builtins-wasm.c
index 92fd9843e44b..76dd2622fe2f 100644
--- a/clang/test/CodeGen/builtins-wasm.c
+++ b/clang/test/CodeGen/builtins-wasm.c
@@ -384,26 +384,20 @@ u8x16 sub_saturate_u_i8x16(u8x16 x, u8x16 y) {
 
 i8x16 abs_i8x16(i8x16 v) {
   return __builtin_wasm_abs_i8x16(v);
-  // WEBASSEMBLY: %neg = sub <16 x i8> zeroinitializer, %v
-  // WEBASSEMBLY: %abscond = icmp slt <16 x i8> %v, zeroinitializer
-  // WEBASSEMBLY: %abs = select <16 x i1> %abscond, <16 x i8> %neg, <16 x i8> 
%v
-  // WEBASSEMBLY: ret <16 x i8> %abs
+  // WEBASSEMBLY: call <16 x i8> @llvm.abs.v16i8(<16 x i8> %v, i1 false)
+  // WEBASSEMBLY-NEXT: ret
 }
 
 i16x8 abs_i16x8(i16x8 v) {
   return __builtin_wasm_abs_i16x8(v);
-  // WEBASSEMBLY: %neg = sub <8 x i16> zeroinitializer, %v
-  // WEBASSEMBLY: %abscond = icmp slt <8 x i16> %v, zeroinitializer
-  // WEBASSEMBLY: %abs = select <8 x i1> %abscond, <8 x i16> %neg, <8 x i16> %v
-  // WEBASSEMBLY: ret <8 x i16> %abs
+  // WEBASSEMBLY: call <8 x i16> @llvm.abs.v8i16(<8 x i16> %v, i1 false)
+  // WEBASSEMBLY-NEXT: ret
 }
 
 i32x4 abs_i32x4(i32x4 v) {
   return __builtin_wasm_abs_i32x4(v);
-  // WEBASSEMBLY: %neg = sub <4 x i32> zeroinitializer, %v
-  // WEBASSEMBLY: %abscond = icmp slt <4 x i32> %v, zeroinitializer
-  // WEBASSEMBLY: %abs = select <4 x i1> %abscond, <4 x i32> %neg, <4 x i32> %v
-  // WEBASSEMBLY: ret <4 x i32> %abs
+  // WEBASSEMBLY: call <4 x i32> @llvm.abs.v4i32(<4 x i32> %v, i1 false)
+  // WEBASSEMBLY-NEXT: ret
 }
 
 i8x16 min_s_i8x16(i8x16 x, i8x16 y) {

diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index d6f8d2dcc7ce..e05fa4ffa403 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -1047,89 +1047,28 @@ static Instruction 
*canonicalizeMinMaxWithConstant(SelectInst ,
   return 
 }
 
-/// There are many select variants for each of ABS/NABS.
-/// In matchSelectPattern(), there are 
diff erent compare constants, compare
-/// predicates/operands and select operands.
-/// In isKnownNegation(), there are 
diff erent formats of negated operands.
-/// Canonicalize all these variants to 1 pattern.
-/// This makes CSE more likely.
 static Instruction *canonicalizeAbsNabs(SelectInst , ICmpInst ,
 InstCombinerImpl ) {
   if (!Cmp.hasOneUse() || !isa(Cmp.getOperand(1)))
 return nullptr;
 
-  // Choose a sign-bit check for the compare (likely simpler for codegen).
-  // ABS:  (X hasOneUse() || (RHS->hasNUses(2) && CmpUsesNegatedOp)))
-  return nullptr;
+  bool IntMinIsPoison = match(RHS, m_NSWNeg(m_Specific(LHS)));
+  Constant *IntMinIsPoisonC =
+  ConstantInt::get(Type::getInt1Ty(Sel.getContext()), IntMinIsPoison);
+  Instruction *Abs =
+  IC.Builder.CreateBinaryIntrinsic(Intrinsic::abs, LHS, IntMinIsPoisonC);
 
-  // Create the canonical compare: icmp slt LHS 0.
-  if (!CmpCanonicalized) {
-Cmp.setPredicate(ICmpInst::ICMP_SLT);
-Cmp.setOperand(1, ConstantInt::getNullValue(Cmp.getOperand(0)->getType()));
-if (CmpUsesNegatedOp)
-  Cmp.setOperand(0, LHS);
-  }
-
-  // Create the canonical RHS: RHS = sub (0, LHS).
-  if (!RHSCanonicalized) {
-assert(RHS->hasOneUse() && "RHS use number is not right");
-RHS = IC.Builder.CreateNeg(LHS);
-if (TVal == LHS) {
-  // Replace false value.
-  IC.replaceOperand(Sel, 2, RHS);
-  FVal = RHS;
-} else {
-  // Replace 

[clang-tools-extra] 39431e4 - [clang-tidy] Introduce misc No Integer To Pointer Cast check

2020-12-08 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2020-12-08T22:55:13+03:00
New Revision: 39431e479ffddc81120911f031921b2d637e967f

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

LOG: [clang-tidy] Introduce misc No Integer To Pointer Cast check

While casting an (integral) pointer to an integer is obvious - you just get
the integral value of the pointer, casting an integer to an (integral) pointer
is deceivingly different. While you will get a pointer with that integral value,
if you got that integral value via a pointer-to-integer cast originally,
the new pointer will lack the provenance information from the original pointer.

So while (integral) pointer to integer casts are effectively no-ops,
and are transparent to the optimizer, integer to (integral) pointer casts
are *NOT* transparent, and may conceal information from optimizer.

While that may be the intention, it is not always so. For example,
let's take a look at a routine to align the pointer up to the multiple of 16:
The obvious, naive implementation for that is:

```
  char* src(char* maybe_underbiased_ptr) {
uintptr_t maybe_underbiased_intptr = (uintptr_t)maybe_underbiased_ptr;
uintptr_t aligned_biased_intptr = maybe_underbiased_intptr + 15;
uintptr_t aligned_intptr = aligned_biased_intptr & (~15);
return (char*)aligned_intptr; // warning: avoid integer to pointer casts 
[misc-no-inttoptr]
  }
```

The check will rightfully diagnose that cast.

But when provenance concealment is not the goal of the code, but an accident,
this example can be rewritten as follows, without using integer to pointer cast:

```
  char*
  tgt(char* maybe_underbiased_ptr) {
  uintptr_t maybe_underbiased_intptr = (uintptr_t)maybe_underbiased_ptr;
  uintptr_t aligned_biased_intptr = maybe_underbiased_intptr + 15;
  uintptr_t aligned_intptr = aligned_biased_intptr & (~15);
  uintptr_t bias = aligned_intptr - maybe_underbiased_intptr;
  return maybe_underbiased_ptr + bias;
  }
```

See also:
* D71499
* [[ https://www.cs.utah.edu/~regehr/oopsla18.pdf | Juneyoung Lee, Chung-Kil 
Hur, Ralf Jung, Zhengyang Liu, John Regehr, and Nuno P. Lopes. 2018. 
Reconciling High-Level Optimizations and Low-Level Code in LLVM. Proc. ACM 
Program. Lang. 2, OOPSLA, Article 125 (November 2018), 28 pages. ]]

Reviewed By: aaron.ballman

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

Added: 
clang-tools-extra/clang-tidy/performance/NoIntToPtrCheck.cpp
clang-tools-extra/clang-tidy/performance/NoIntToPtrCheck.h
clang-tools-extra/docs/clang-tidy/checks/performance-no-int-to-ptr.rst
clang-tools-extra/test/clang-tidy/checkers/performance-no-int-to-ptr.c
clang-tools-extra/test/clang-tidy/checkers/performance-no-int-to-ptr.cpp

Modified: 
clang-tools-extra/clang-tidy/performance/CMakeLists.txt
clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/performance/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/performance/CMakeLists.txt
index 0e38e9fc5c0c..315364641692 100644
--- a/clang-tools-extra/clang-tidy/performance/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/performance/CMakeLists.txt
@@ -13,6 +13,7 @@ add_clang_library(clangTidyPerformanceModule
   MoveConstArgCheck.cpp
   MoveConstructorInitCheck.cpp
   NoAutomaticMoveCheck.cpp
+  NoIntToPtrCheck.cpp
   NoexceptMoveConstructorCheck.cpp
   PerformanceTidyModule.cpp
   TriviallyDestructibleCheck.cpp

diff  --git a/clang-tools-extra/clang-tidy/performance/NoIntToPtrCheck.cpp 
b/clang-tools-extra/clang-tidy/performance/NoIntToPtrCheck.cpp
new file mode 100644
index ..bc82a21bbf5a
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/performance/NoIntToPtrCheck.cpp
@@ -0,0 +1,34 @@
+//===--- NoIntToPtrCheck.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 "NoIntToPtrCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace performance {
+
+void NoIntToPtrCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(castExpr(hasCastKind(CK_IntegralToPointer),
+  unless(hasSourceExpression(integerLiteral(
+ .bind("x"),
+ this);
+}
+
+void NoIntToPtrCheck::check(const MatchFinder::MatchResult ) 

[clang-tools-extra] ae7ec47 - [NFC][clang-tidy] Port rename_check.py to Python3

2020-12-01 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2020-12-01T20:10:19+03:00
New Revision: ae7ec47fc655537ce82c0bfee0b587921663eaff

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

LOG: [NFC][clang-tidy] Port rename_check.py to Python3

Added: 


Modified: 
clang-tools-extra/clang-tidy/rename_check.py

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/rename_check.py 
b/clang-tools-extra/clang-tidy/rename_check.py
index 4d5311c9a293..2410041fd5d2 100755
--- a/clang-tools-extra/clang-tidy/rename_check.py
+++ b/clang-tools-extra/clang-tidy/rename_check.py
@@ -120,16 +120,15 @@ def adapt_cmake(module_path, check_name_camel):
   if (not file_added) and (cpp_line or cpp_found):
 cpp_found = True
 if (line.strip() > cpp_file) or (not cpp_line):
-  f.write('  ' + cpp_file + '\n')
+  f.write(('  ' + cpp_file + '\n').encode())
   file_added = True
-  f.write(line)
+  f.write(line.encode())
 
   return True
 
 # Modifies the module to include the new check.
 def adapt_module(module_path, module, check_name, check_name_camel):
-  modulecpp = filter(lambda p: p.lower() == module.lower() + 'tidymodule.cpp',
- os.listdir(module_path))[0]
+  modulecpp = next(filter(lambda p: p.lower() == module.lower() + 
'tidymodule.cpp', os.listdir(module_path)))
   filename = os.path.join(module_path, modulecpp)
   with open(filename, 'r') as f:
 lines = f.readlines()
@@ -149,21 +148,21 @@ def adapt_module(module_path, module, check_name, 
check_name_camel):
   header_found = True
   if match.group(1) > check_name_camel:
 header_added = True
-f.write('#include "' + check_name_camel + '.h"\n')
+f.write(('#include "' + check_name_camel + '.h"\n').encode())
 elif header_found:
   header_added = True
-  f.write('#include "' + check_name_camel + '.h"\n')
+  f.write(('#include "' + check_name_camel + '.h"\n').encode())
 
   if not check_added:
 if line.strip() == '}':
   check_added = True
-  f.write(check_decl)
+  f.write(check_decl.encode())
 else:
   match = re.search('registerCheck<(.*)>', line)
   if match and match.group(1) > check_name_camel:
 check_added = True
-f.write(check_decl)
-  f.write(line)
+f.write(check_decl.encode())
+  f.write(line.encode())
 
 
 # Adds a release notes entry.
@@ -198,22 +197,22 @@ def add_release_notes(clang_tidy_path, old_check_name, 
new_check_name):
 
 if match:
   header_found = True
-  f.write(line)
+  f.write(line.encode())
   continue
 
 if line.startswith(''):
-  f.write(line)
+  f.write(line.encode())
   continue
 
 if header_found and add_note_here:
   if not line.startswith(''):
-f.write("""- The '%s' check was renamed to :doc:`%s
+f.write(("""- The '%s' check was renamed to :doc:`%s
   `
 
-""" % (old_check_name, new_check_name, new_check_name))
+""" % (old_check_name, new_check_name, new_check_name)).encode())
 note_added = True
 
-  f.write(line)
+  f.write(line.encode())
 
 def main():
   parser = argparse.ArgumentParser(description='Rename clang-tidy check.')
@@ -259,9 +258,9 @@ def main():
 (check_name_camel, cmake_lists))
   return 1
 
-modulecpp = filter(
+modulecpp = next(filter(
 lambda p: p.lower() == old_module.lower() + 'tidymodule.cpp',
-os.listdir(old_module_path))[0]
+os.listdir(old_module_path)))
 deleteMatchingLines(os.path.join(old_module_path, modulecpp),
   '\\b' + check_name_camel + '|\\b' + args.old_check_name)
 



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


[clang-tools-extra] 317ca3e - [NFC][clang-tidy] Do link FrontendOpenMP into concurrency module after all

2020-11-30 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2020-11-30T13:34:00+03:00
New Revision: 317ca3ecf8244cabb4ca9d45e626ad3cf0f8e4b2

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

LOG: [NFC][clang-tidy] Do link FrontendOpenMP into concurrency module after all

It seems that while clangASTMatchers does add FrontendOpenMP into
it's LLVM_LINK_COMPONENTS, it's still not being propagated transitively.

Added: 


Modified: 
clang-tools-extra/clang-tidy/concurrency/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/concurrency/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/concurrency/CMakeLists.txt
index df329662b0df..b757d6a60b78 100644
--- a/clang-tools-extra/clang-tidy/concurrency/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/concurrency/CMakeLists.txt
@@ -1,4 +1,5 @@
 set(LLVM_LINK_COMPONENTS
+  FrontendOpenMP
   Support
   )
 



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


[clang-tools-extra] cac5be4 - [clang-tidy] implement concurrency-mt-unsafe

2020-11-30 Thread Roman Lebedev via cfe-commits

Author: Vasily Kulikov
Date: 2020-11-30T12:27:17+03:00
New Revision: cac5be495ed88b269ad7a3000305e714cce60e63

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

LOG: [clang-tidy] implement concurrency-mt-unsafe

Checks for some thread-unsafe functions against a black list
of known-to-be-unsafe functions. Usually they access static variables
without synchronization (e.g. gmtime(3)) or utilize signals
in a racy way (e.g. sleep(3)).

The patch adds a check instead of auto-fix as thread-safe alternatives
usually have API with an additional argument
(e.g. gmtime(3) v.s. gmtime_r(3)) or have a different semantics
(e.g. exit(3) v.s. __exit(3)), so it is a rather tricky
or non-expected fix.

An option specifies which functions in libc should be considered
thread-safe, possible values are `posix`, `glibc`,
or `any` (the most strict check). It defaults to 'any' as it is
unknown what target libc type is - clang-tidy may be run
on linux but check sources compiled for other *NIX.

The check is used in Yandex Taxi backend and has caught
many unpleasant bugs. A similar patch for coroutine-unsafe API
is coming next.

Reviewed By: lebedev.ri

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

Added: 
clang-tools-extra/clang-tidy/concurrency/MtUnsafeCheck.cpp
clang-tools-extra/clang-tidy/concurrency/MtUnsafeCheck.h
clang-tools-extra/docs/clang-tidy/checks/concurrency-mt-unsafe.rst
clang-tools-extra/test/clang-tidy/checkers/concurrency-mt-unsafe-any.cpp
clang-tools-extra/test/clang-tidy/checkers/concurrency-mt-unsafe-glibc.cpp
clang-tools-extra/test/clang-tidy/checkers/concurrency-mt-unsafe-posix.cpp

Modified: 
clang-tools-extra/clang-tidy/concurrency/CMakeLists.txt
clang-tools-extra/clang-tidy/concurrency/ConcurrencyTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/concurrency/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/concurrency/CMakeLists.txt
index e09de74706d8..df329662b0df 100644
--- a/clang-tools-extra/clang-tidy/concurrency/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/concurrency/CMakeLists.txt
@@ -4,6 +4,7 @@ set(LLVM_LINK_COMPONENTS
 
 add_clang_library(clangTidyConcurrencyModule
   ConcurrencyTidyModule.cpp
+  MtUnsafeCheck.cpp
 
   LINK_LIBS
   clangTidy

diff  --git 
a/clang-tools-extra/clang-tidy/concurrency/ConcurrencyTidyModule.cpp 
b/clang-tools-extra/clang-tidy/concurrency/ConcurrencyTidyModule.cpp
index be8fa7e8ef53..ea4131e0ca51 100644
--- a/clang-tools-extra/clang-tidy/concurrency/ConcurrencyTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/concurrency/ConcurrencyTidyModule.cpp
@@ -9,6 +9,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "MtUnsafeCheck.h"
 
 namespace clang {
 namespace tidy {
@@ -16,7 +17,10 @@ namespace concurrency {
 
 class ConcurrencyModule : public ClangTidyModule {
 public:
-  void addCheckFactories(ClangTidyCheckFactories ) override {}
+  void addCheckFactories(ClangTidyCheckFactories ) override {
+CheckFactories.registerCheck(
+"concurrency-mt-unsafe");
+  }
 };
 
 } // namespace concurrency

diff  --git a/clang-tools-extra/clang-tidy/concurrency/MtUnsafeCheck.cpp 
b/clang-tools-extra/clang-tidy/concurrency/MtUnsafeCheck.cpp
new file mode 100644
index ..bc9f7403b6e9
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/concurrency/MtUnsafeCheck.cpp
@@ -0,0 +1,316 @@
+//===--- MtUnsafeCheck.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 "MtUnsafeCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+// Initial list was extracted from gcc documentation
+static const clang::StringRef GlibcFunctions[] = {
+"::argp_error",
+"::argp_help",
+"::argp_parse",
+"::argp_state_help",
+"::argp_usage",
+"::asctime",
+"::clearenv",
+"::crypt",
+"::ctime",
+"::cuserid",
+"::drand48",
+"::ecvt",
+"::encrypt",
+"::endfsent",
+"::endgrent",
+"::endhostent",
+"::endnetent",
+"::endnetgrent",
+"::endprotoent",
+"::endpwent",
+"::endservent",
+"::endutent",
+"::endutxent",
+"::erand48",
+"::error_at_line",
+"::exit",
+"::fcloseall",
+"::fcvt",
+"::fgetgrent",
+"::fgetpwent",
+"::gammal",
+"::getchar_unlocked",
+"::getdate",

[clang-tools-extra] 8da7efb - [clang-tidy] add concurrency module

2020-11-30 Thread Roman Lebedev via cfe-commits

Author: Vasily Kulikov
Date: 2020-11-30T12:27:17+03:00
New Revision: 8da7efbb0d5ec315a27b7b5286dbdd25694905ad

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

LOG: [clang-tidy] add concurrency module

The module will contain checks related to concurrent programming (including 
threads, fibers, coroutines, etc.).

Reviewed By: lebedev.ri

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

Added: 
clang-tools-extra/clang-tidy/concurrency/CMakeLists.txt
clang-tools-extra/clang-tidy/concurrency/ConcurrencyTidyModule.cpp

Modified: 
clang-tools-extra/clang-tidy/CMakeLists.txt
clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/index.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/CMakeLists.txt
index ca7a5afed6b0..455645050d93 100644
--- a/clang-tools-extra/clang-tidy/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/CMakeLists.txt
@@ -55,6 +55,7 @@ add_subdirectory(altera)
 add_subdirectory(boost)
 add_subdirectory(bugprone)
 add_subdirectory(cert)
+add_subdirectory(concurrency)
 add_subdirectory(cppcoreguidelines)
 add_subdirectory(darwin)
 add_subdirectory(fuchsia)
@@ -81,6 +82,7 @@ set(ALL_CLANG_TIDY_CHECKS
   clangTidyBoostModule
   clangTidyBugproneModule
   clangTidyCERTModule
+  clangTidyConcurrencyModule
   clangTidyCppCoreGuidelinesModule
   clangTidyDarwinModule
   clangTidyFuchsiaModule

diff  --git a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h 
b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
index 3a5330c85c3b..2691d90fa521 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
@@ -45,6 +45,11 @@ extern volatile int CERTModuleAnchorSource;
 static int LLVM_ATTRIBUTE_UNUSED CERTModuleAnchorDestination =
 CERTModuleAnchorSource;
 
+// This anchor is used to force the linker to link the ConcurrencyModule.
+extern volatile int ConcurrencyModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED ConcurrencyModuleAnchorDestination =
+ConcurrencyModuleAnchorSource;
+
 // This anchor is used to force the linker to link the CppCoreGuidelinesModule.
 extern volatile int CppCoreGuidelinesModuleAnchorSource;
 static int LLVM_ATTRIBUTE_UNUSED CppCoreGuidelinesModuleAnchorDestination =

diff  --git a/clang-tools-extra/clang-tidy/concurrency/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/concurrency/CMakeLists.txt
new file mode 100644
index ..e09de74706d8
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/concurrency/CMakeLists.txt
@@ -0,0 +1,22 @@
+set(LLVM_LINK_COMPONENTS
+  Support
+  )
+
+add_clang_library(clangTidyConcurrencyModule
+  ConcurrencyTidyModule.cpp
+
+  LINK_LIBS
+  clangTidy
+  clangTidyUtils
+  )
+
+clang_target_link_libraries(clangTidyConcurrencyModule
+  PRIVATE
+  clangAnalysis
+  clangAST
+  clangASTMatchers
+  clangBasic
+  clangLex
+  clangSerialization
+  clangTooling
+  )

diff  --git 
a/clang-tools-extra/clang-tidy/concurrency/ConcurrencyTidyModule.cpp 
b/clang-tools-extra/clang-tidy/concurrency/ConcurrencyTidyModule.cpp
new file mode 100644
index ..be8fa7e8ef53
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/concurrency/ConcurrencyTidyModule.cpp
@@ -0,0 +1,33 @@
+//===--- ConcurrencyTidyModule.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 "../ClangTidy.h"
+#include "../ClangTidyModule.h"
+#include "../ClangTidyModuleRegistry.h"
+
+namespace clang {
+namespace tidy {
+namespace concurrency {
+
+class ConcurrencyModule : public ClangTidyModule {
+public:
+  void addCheckFactories(ClangTidyCheckFactories ) override {}
+};
+
+} // namespace concurrency
+
+// Register the ConcurrencyTidyModule using this statically initialized 
variable.
+static ClangTidyModuleRegistry::Add
+X("concurrency-module", "Adds concurrency checks.");
+
+// This anchor is used to force the linker to link in the generated object file
+// and thus register the ConcurrencyModule.
+volatile int ConcurrencyModuleAnchorSource = 0;
+
+} // namespace tidy
+} // namespace clang

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 46bb36c271d3..46461a2a6e8d 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -82,6 +82,11 @@ New modules
   `Altera SDK for OpenCL: Best Practices Guide
   

[clang] 544a6aa - [InstCombine] combineLoadToOperationType(): don't fold int<->ptr cast into load

2020-10-11 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2020-10-11T20:24:28+03:00
New Revision: 544a6aa2674e3875e4014eafb101a982f9296439

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

LOG: [InstCombine] combineLoadToOperationType(): don't fold int<->ptr cast into 
load

And another step towards transforms not introducing inttoptr and/or
ptrtoint casts that weren't there already.

As we've been establishing (see D88788/D88789), if there is a int<->ptr cast,
it basically must stay as-is, we can't do much with it.

I've looked, and the most source of new such casts being introduces,
as far as i can tell, is this transform, which, ironically,
tries to reduce count of casts..

On vanilla llvm test-suite + RawSpeed, @ `-O3`, this results in
-33.58% less `IntToPtr`s (19014 -> 12629)
and +76.20% more `PtrToInt`s (18589 -> 32753),
which is an increase of +20.69% in total.

However just on RawSpeed, where i know there are basically
none `IntToPtr` in the original source code,
this results in -99.27% less `IntToPtr`s (2724 -> 20)
and +82.92% more `PtrToInt`s (4513 -> 8255).
which is again an increase of 14.34% in total.

To me this does seem like the step in the right direction,
we end up with strictly less `IntToPtr`, but strictly more `PtrToInt`,
which seems like a reasonable trade-off.

See https://reviews.llvm.org/D88860 / https://reviews.llvm.org/D88995
for some more discussion on the subject.

(Eventually, `CastInst::isNoopCast()`/`CastInst::isEliminableCastPair`
should be taught about this, yes)

Reviewed By: nlopes, nikic

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

Added: 


Modified: 
clang/test/CodeGen/arm64_32-vaarg.c
llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
llvm/test/Transforms/InstCombine/PR30597.ll
llvm/test/Transforms/InstCombine/intptr1.ll
llvm/test/Transforms/InstCombine/load-bitcast32.ll
llvm/test/Transforms/InstCombine/load-bitcast64.ll
llvm/test/Transforms/InstCombine/memset_chk-1.ll

Removed: 




diff  --git a/clang/test/CodeGen/arm64_32-vaarg.c 
b/clang/test/CodeGen/arm64_32-vaarg.c
index 7ee0277a167d..0f88841c7848 100644
--- a/clang/test/CodeGen/arm64_32-vaarg.c
+++ b/clang/test/CodeGen/arm64_32-vaarg.c
@@ -27,20 +27,20 @@ typedef struct {
 
 // Minimum slot size is 4 bytes, so address needs rounding up to multiple of 8.
 long long test_longlong(OneLongLong input, va_list *mylist) {
-// CHECK-LABEL: define i64 @test_longlong(i64 %input
-// CHECK: [[STARTPTR:%.*]] = bitcast i8** %mylist to i32*
-// CHECK: [[START:%.*]] = load i32, i32* [[STARTPTR]]
-
-// CHECK: [[ALIGN_TMP:%.*]] = add i32 [[START]], 7
-// CHECK: [[ALIGNED:%.*]] = and i32 [[ALIGN_TMP]], -8
-// CHECK: [[ALIGNED_ADDR:%.*]] = inttoptr i32 [[ALIGNED]] to i8*
-// CHECK: [[NEXT:%.*]] = getelementptr inbounds i8, i8* [[ALIGNED_ADDR]], i32 8
-// CHECK: store i8* [[NEXT]], i8** %mylist
-
-// CHECK: [[ADDR_STRUCT:%.*]] = inttoptr i32 [[ALIGNED]] to 
%struct.OneLongLong*
-// CHECK: [[ADDR_I64:%.*]] = getelementptr inbounds %struct.OneLongLong, 
%struct.OneLongLong* [[ADDR_STRUCT]], i32 0, i32 0
-// CHECK: [[RES:%.*]] = load i64, i64* [[ADDR_I64]]
-// CHECK: ret i64 [[RES]]
+  // CHECK-LABEL: define i64 @test_longlong(i64 %input
+  // CHECK: [[STARTPTR:%.*]] = load i8*, i8** %mylist
+  // CHECK: [[START:%.*]] = ptrtoint i8* [[STARTPTR]] to i32
+
+  // CHECK: [[ALIGN_TMP:%.*]] = add i32 [[START]], 7
+  // CHECK: [[ALIGNED:%.*]] = and i32 [[ALIGN_TMP]], -8
+  // CHECK: [[ALIGNED_ADDR:%.*]] = inttoptr i32 [[ALIGNED]] to i8*
+  // CHECK: [[NEXT:%.*]] = getelementptr inbounds i8, i8* [[ALIGNED_ADDR]], 
i32 8
+  // CHECK: store i8* [[NEXT]], i8** %mylist
+
+  // CHECK: [[ADDR_STRUCT:%.*]] = inttoptr i32 [[ALIGNED]] to 
%struct.OneLongLong*
+  // CHECK: [[ADDR_I64:%.*]] = getelementptr inbounds %struct.OneLongLong, 
%struct.OneLongLong* [[ADDR_STRUCT]], i32 0, i32 0
+  // CHECK: [[RES:%.*]] = load i64, i64* [[ADDR_I64]]
+  // CHECK: ret i64 [[RES]]
 
   return va_arg(*mylist, OneLongLong).a;
 }

diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
index b7bb34022ecc..8050c575c1f8 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -557,12 +557,12 @@ static Instruction 
*combineLoadToOperationType(InstCombinerImpl ,
   const DataLayout  = IC.getDataLayout();
 
   // Fold away bit casts of the loaded value by loading the desired type.
-  // We can do this for BitCastInsts as well as casts from and to pointer 
types,
-  // as long as those are noops (i.e., the source or dest type have the same
-  // bitwidth as the target's pointers).
+  // Note that we should not do this for pointer<->integer casts,
+  

Re: [clang] 4eb627e - first upstream review

2020-10-09 Thread Roman Lebedev via cfe-commits
On Fri, Oct 9, 2020 at 3:21 PM Ben Dunbobbin via cfe-commits
 wrote:
>
>
> Author: Ben Dunbobbin
> Date: 2020-10-09T13:21:03+01:00
> New Revision: 4eb627ed96e3f2f9f24aec8a0654ce5204874bb8
>
> URL: 
> https://github.com/llvm/llvm-project/commit/4eb627ed96e3f2f9f24aec8a0654ce5204874bb8
> DIFF: 
> https://github.com/llvm/llvm-project/commit/4eb627ed96e3f2f9f24aec8a0654ce5204874bb8.diff
>
> LOG: first upstream review
This is a very much not useful commit message.
If this is not an accidental commit, i suggest reverting and
recommitting with a proper commit.

Roman.

> Added:
>
>
> Modified:
> clang/lib/Sema/SemaDecl.cpp
> clang/lib/Sema/SemaDeclAttr.cpp
> clang/lib/Sema/SemaDeclCXX.cpp
> clang/test/Sema/dllimport.c
> clang/test/SemaCXX/dllexport.cpp
> clang/test/SemaCXX/dllimport.cpp
>
> Removed:
>
>
>
> 
> diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
> index c92d906580eb..9a6682e837dd 100644
> --- a/clang/lib/Sema/SemaDecl.cpp
> +++ b/clang/lib/Sema/SemaDecl.cpp
> @@ -6497,7 +6497,9 @@ static void checkDLLAttributeRedeclaration(Sema , 
> NamedDecl *OldDecl,
>// special MSVC extension: in the last case, the declaration is treated as 
> if
>// it were marked dllexport.
>bool IsInline = false, IsStaticDataMember = false, IsQualifiedFriend = 
> false;
> -  bool IsMicrosoft = S.Context.getTargetInfo().getCXXABI().isMicrosoft();
> +  bool IsMicrosoft =
> +  S.Context.getTargetInfo().getCXXABI().isMicrosoft() ||
> +  S.Context.getTargetInfo().getTriple().isWindowsItaniumEnvironment();
>if (const auto *VD = dyn_cast(NewDecl)) {
>  // Ignore static data because out-of-line definitions are diagnosed
>  // separately.
>
> diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp 
> b/clang/lib/Sema/SemaDeclAttr.cpp
> index c07e5f792d14..0ccfb1504636 100644
> --- a/clang/lib/Sema/SemaDeclAttr.cpp
> +++ b/clang/lib/Sema/SemaDeclAttr.cpp
> @@ -6731,14 +6731,16 @@ DLLExportAttr *Sema::mergeDLLExportAttr(Decl *D,
>
>  static void handleDLLAttr(Sema , Decl *D, const ParsedAttr ) {
>if (isa(D) &&
> -  S.Context.getTargetInfo().getCXXABI().isMicrosoft()) {
> +  (S.Context.getTargetInfo().getCXXABI().isMicrosoft() ||
> +   S.Context.getTargetInfo().getTriple().isWindowsItaniumEnvironment())) 
> {
>  S.Diag(A.getRange().getBegin(), diag::warn_attribute_ignored) << A;
>  return;
>}
>
>if (const auto *FD = dyn_cast(D)) {
>  if (FD->isInlined() && A.getKind() == ParsedAttr::AT_DLLImport &&
> -!S.Context.getTargetInfo().getCXXABI().isMicrosoft()) {
> +!(S.Context.getTargetInfo().getCXXABI().isMicrosoft() ||
> +  
> S.Context.getTargetInfo().getTriple().isWindowsItaniumEnvironment())) {
>// MinGW doesn't allow dllimport on inline functions.
>S.Diag(A.getRange().getBegin(), diag::warn_attribute_ignored_on_inline)
><< A;
> @@ -6747,7 +6749,8 @@ static void handleDLLAttr(Sema , Decl *D, const 
> ParsedAttr ) {
>}
>
>if (const auto *MD = dyn_cast(D)) {
> -if (S.Context.getTargetInfo().getCXXABI().isMicrosoft() &&
> +if ((S.Context.getTargetInfo().getCXXABI().isMicrosoft() ||
> + 
> S.Context.getTargetInfo().getTriple().isWindowsItaniumEnvironment()) &&
>  MD->getParent()->isLambda()) {
>S.Diag(A.getRange().getBegin(), diag::err_attribute_dll_lambda) << A;
>return;
>
> diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
> index 1275fc0c95b5..138faa161c4e 100644
> --- a/clang/lib/Sema/SemaDeclCXX.cpp
> +++ b/clang/lib/Sema/SemaDeclCXX.cpp
> @@ -6060,7 +6060,8 @@ void Sema::checkClassLevelDLLAttribute(CXXRecordDecl 
> *Class) {
>Attr *ClassAttr = getDLLAttr(Class);
>
>// MSVC inherits DLL attributes to partial class template specializations.
> -  if (Context.getTargetInfo().getCXXABI().isMicrosoft() && !ClassAttr) {
> +  if ((Context.getTargetInfo().getCXXABI().isMicrosoft() ||
> +   Context.getTargetInfo().getTriple().isWindowsItaniumEnvironment()) && 
> !ClassAttr) {
>  if (auto *Spec = 
> dyn_cast(Class)) {
>if (Attr *TemplateAttr =
>
> getDLLAttr(Spec->getSpecializedTemplate()->getTemplatedDecl())) {
> @@ -6080,7 +6081,8 @@ void Sema::checkClassLevelDLLAttribute(CXXRecordDecl 
> *Class) {
>  return;
>}
>
> -  if (Context.getTargetInfo().getCXXABI().isMicrosoft() &&
> +  if ((Context.getTargetInfo().getCXXABI().isMicrosoft() ||
> +   Context.getTargetInfo().getTriple().isWindowsItaniumEnvironment()) &&
>!ClassAttr->isInherited()) {
>  // Diagnose dll attributes on members of class with dll attribute.
>  for (Decl *Member : Class->decls()) {
>
> diff  --git a/clang/test/Sema/dllimport.c b/clang/test/Sema/dllimport.c
> index 988a8e33a7ef..66bd2703e648 100644
> --- a/clang/test/Sema/dllimport.c
> +++ b/clang/test/Sema/dllimport.c
> @@ -1,8 +1,10 @@
> -// RUN: 

[clang] e00f189 - [InstCombine] Revert rL226781 "Teach InstCombine to canonicalize loads which are only ever stored to always use a legal integer type if one is available." (PR47592)

2020-10-05 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2020-10-06T00:00:30+03:00
New Revision: e00f189d392dd9bf95f6a98f05f2d341d06cd65c

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

LOG: [InstCombine] Revert rL226781 "Teach InstCombine to canonicalize loads 
which are only ever stored to always use a legal integer type if one is 
available." (PR47592)

(it was introduced in 
https://lists.llvm.org/pipermail/llvm-dev/2015-January/080956.html)

This canonicalization seems dubious.

Most importantly, while it does not create `inttoptr` casts by itself,
it may cause them to appear later, see e.g. D88788.

I think it's pretty obvious that it is an undesirable outcome,
by now we've established that seemingly no-op `inttoptr`/`ptrtoint` casts
are not no-op, and are no longer eager to look past them.
Which e.g. means that given
```
%a = load i32
%b = inttoptr %a
%c = inttoptr %a
```
we likely won't be able to tell that `%b` and `%c` is the same thing.

As we can see in D88789 / D88788 / D88806 / D75505,
we can't really teach SCEV about this (not without the 
https://bugs.llvm.org/show_bug.cgi?id=47592 at least)
And we can't recover the situation post-inlining in instcombine.

So it really does look like this fold is actively breaking
otherwise-good IR, in a way that is not recoverable.
And that means, this fold isn't helpful in exposing the passes
that are otherwise unaware of these patterns it produces.

Thusly, i propose to simply not perform such a canonicalization.
The original motivational RFC does not state what larger problem
that canonicalization was trying to solve, so i'm not sure
how this plays out in the larger picture.

On vanilla llvm test-suite + RawSpeed, this results in
increase of asm instructions and final object size by ~+0.05%
decreases final count of bitcasts by -4.79% (-28990),
ptrtoint casts by -15.41% (-3423),
and of inttoptr casts by -25.59% (-6919, *sic*).
Overall, there's -0.04% less IR blocks, -0.39% instructions.

See https://bugs.llvm.org/show_bug.cgi?id=47592

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

Added: 


Modified: 
clang/test/CodeGen/attr-arm-sve-vector-bits-bitcast.c
clang/test/CodeGen/attr-arm-sve-vector-bits-call.c
clang/test/CodeGen/attr-arm-sve-vector-bits-cast.c
clang/test/CodeGen/attr-arm-sve-vector-bits-globals.c
llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
llvm/test/Transforms/InstCombine/atomic.ll
llvm/test/Transforms/InstCombine/load.ll
llvm/test/Transforms/InstCombine/loadstore-metadata.ll
llvm/test/Transforms/InstCombine/non-integral-pointers.ll
llvm/test/Transforms/PhaseOrdering/instcombine-sroa-inttoptr.ll

Removed: 




diff  --git a/clang/test/CodeGen/attr-arm-sve-vector-bits-bitcast.c 
b/clang/test/CodeGen/attr-arm-sve-vector-bits-bitcast.c
index 3a5628d7f57e..5df1e83b13bf 100644
--- a/clang/test/CodeGen/attr-arm-sve-vector-bits-bitcast.c
+++ b/clang/test/CodeGen/attr-arm-sve-vector-bits-bitcast.c
@@ -255,22 +255,20 @@ svbool_t read_bool(struct struct_bool *s) {
 // CHECK-256-NEXT:  entry:
 // CHECK-256-NEXT:[[X_ADDR:%.*]] = alloca , align 16
 // CHECK-256-NEXT:store  [[X:%.*]], * 
[[X_ADDR]], align 16, [[TBAA15:!tbaa !.*]]
-// CHECK-256-NEXT:[[TMP0:%.*]] = bitcast * [[X_ADDR]] to 
i32*
-// CHECK-256-NEXT:[[TMP1:%.*]] = load i32, i32* [[TMP0]], align 16, 
[[TBAA6]]
-// CHECK-256-NEXT:[[Y:%.*]] = getelementptr inbounds 
[[STRUCT_STRUCT_BOOL:%.*]], %struct.struct_bool* [[S:%.*]], i64 0, i32 1
-// CHECK-256-NEXT:[[TMP2:%.*]] = bitcast [3 x <4 x i8>]* [[Y]] to i32*
-// CHECK-256-NEXT:store i32 [[TMP1]], i32* [[TMP2]], align 2, [[TBAA6]]
+// CHECK-256-NEXT:[[TMP0:%.*]] = bitcast * [[X_ADDR]] to 
<4 x i8>*
+// CHECK-256-NEXT:[[TMP1:%.*]] = load <4 x i8>, <4 x i8>* [[TMP0]], align 
16, [[TBAA6]]
+// CHECK-256-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds 
[[STRUCT_STRUCT_BOOL:%.*]], %struct.struct_bool* [[S:%.*]], i64 0, i32 1, i64 0
+// CHECK-256-NEXT:store <4 x i8> [[TMP1]], <4 x i8>* [[ARRAYIDX]], align 
2, [[TBAA6]]
 // CHECK-256-NEXT:ret void
 //
 // CHECK-512-LABEL: @write_bool(
 // CHECK-512-NEXT:  entry:
 // CHECK-512-NEXT:[[X_ADDR:%.*]] = alloca , align 16
 // CHECK-512-NEXT:store  [[X:%.*]], * 
[[X_ADDR]], align 16, [[TBAA15:!tbaa !.*]]
-// CHECK-512-NEXT:[[TMP0:%.*]] = bitcast * [[X_ADDR]] to 
i64*
-// CHECK-512-NEXT:[[TMP1:%.*]] = load i64, i64* [[TMP0]], align 16, 
[[TBAA6]]
-// CHECK-512-NEXT:[[Y:%.*]] = getelementptr inbounds 
[[STRUCT_STRUCT_BOOL:%.*]], %struct.struct_bool* [[S:%.*]], i64 0, i32 1
-// CHECK-512-NEXT:[[TMP2:%.*]] = bitcast [3 x <8 x i8>]* [[Y]] to i64*
-// CHECK-512-NEXT:store i64 [[TMP1]], i64* [[TMP2]], align 2, [[TBAA6]]
+// CHECK-512-NEXT:[[TMP0:%.*]] = bitcast * [[X_ADDR]] to 

[clang] aaae13d - [NFC][clang][codegen] Autogenerate a few ARM SVE tests that are being affected by an upcoming patch

2020-10-04 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2020-10-04T19:54:09+03:00
New Revision: aaae13d0c29ec2a20f93e6adb9d9b5c2656d2af6

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

LOG: [NFC][clang][codegen] Autogenerate a few ARM SVE tests that are being 
affected by an upcoming patch

Added: 


Modified: 
clang/test/CodeGen/attr-arm-sve-vector-bits-bitcast.c
clang/test/CodeGen/attr-arm-sve-vector-bits-call.c
clang/test/CodeGen/attr-arm-sve-vector-bits-cast.c
clang/test/CodeGen/attr-arm-sve-vector-bits-globals.c

Removed: 




diff  --git a/clang/test/CodeGen/attr-arm-sve-vector-bits-bitcast.c 
b/clang/test/CodeGen/attr-arm-sve-vector-bits-bitcast.c
index 84559e9edb9a..3a5628d7f57e 100644
--- a/clang/test/CodeGen/attr-arm-sve-vector-bits-bitcast.c
+++ b/clang/test/CodeGen/attr-arm-sve-vector-bits-bitcast.c
@@ -31,21 +31,21 @@ DEFINE_STRUCT(bool)
 // CHECK-128-NEXT:  entry:
 // CHECK-128-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds 
[[STRUCT_STRUCT_INT64:%.*]], %struct.struct_int64* [[S:%.*]], i64 0, i32 1, i64 0
 // CHECK-128-NEXT:[[TMP0:%.*]] = bitcast <2 x i64>* [[ARRAYIDX]] to 
*
-// CHECK-128-NEXT:[[TMP1:%.*]] = load , * [[TMP0]], align 16, [[TBAA2:!tbaa !.*]]
+// CHECK-128-NEXT:[[TMP1:%.*]] = load , * [[TMP0]], align 16, [[TBAA6:!tbaa !.*]]
 // CHECK-128-NEXT:ret  [[TMP1]]
 //
 // CHECK-256-LABEL: @read_int64(
 // CHECK-256-NEXT:  entry:
 // CHECK-256-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds 
[[STRUCT_STRUCT_INT64:%.*]], %struct.struct_int64* [[S:%.*]], i64 0, i32 1, i64 0
 // CHECK-256-NEXT:[[TMP0:%.*]] = bitcast <4 x i64>* [[ARRAYIDX]] to 
*
-// CHECK-256-NEXT:[[TMP1:%.*]] = load , * [[TMP0]], align 16, [[TBAA2:!tbaa !.*]]
+// CHECK-256-NEXT:[[TMP1:%.*]] = load , * [[TMP0]], align 16, [[TBAA6:!tbaa !.*]]
 // CHECK-256-NEXT:ret  [[TMP1]]
 //
 // CHECK-512-LABEL: @read_int64(
 // CHECK-512-NEXT:  entry:
 // CHECK-512-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds 
[[STRUCT_STRUCT_INT64:%.*]], %struct.struct_int64* [[S:%.*]], i64 0, i32 1, i64 0
 // CHECK-512-NEXT:[[TMP0:%.*]] = bitcast <8 x i64>* [[ARRAYIDX]] to 
*
-// CHECK-512-NEXT:[[TMP1:%.*]] = load , * [[TMP0]], align 16, [[TBAA2:!tbaa !.*]]
+// CHECK-512-NEXT:[[TMP1:%.*]] = load , * [[TMP0]], align 16, [[TBAA6:!tbaa !.*]]
 // CHECK-512-NEXT:ret  [[TMP1]]
 //
 svint64_t read_int64(struct struct_int64 *s) {
@@ -55,31 +55,31 @@ svint64_t read_int64(struct struct_int64 *s) {
 // CHECK-128-LABEL: @write_int64(
 // CHECK-128-NEXT:  entry:
 // CHECK-128-NEXT:[[X_ADDR:%.*]] = alloca , align 16
-// CHECK-128-NEXT:store  [[X:%.*]], * 
[[X_ADDR]], align 16, [[TBAA5:!tbaa !.*]]
+// CHECK-128-NEXT:store  [[X:%.*]], * 
[[X_ADDR]], align 16, [[TBAA9:!tbaa !.*]]
 // CHECK-128-NEXT:[[TMP0:%.*]] = bitcast * [[X_ADDR]] to 
<2 x i64>*
-// CHECK-128-NEXT:[[TMP1:%.*]] = load <2 x i64>, <2 x i64>* [[TMP0]], 
align 16, [[TBAA2]]
+// CHECK-128-NEXT:[[TMP1:%.*]] = load <2 x i64>, <2 x i64>* [[TMP0]], 
align 16, [[TBAA6]]
 // CHECK-128-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds 
[[STRUCT_STRUCT_INT64:%.*]], %struct.struct_int64* [[S:%.*]], i64 0, i32 1, i64 0
-// CHECK-128-NEXT:store <2 x i64> [[TMP1]], <2 x i64>* [[ARRAYIDX]], align 
16, [[TBAA2]]
+// CHECK-128-NEXT:store <2 x i64> [[TMP1]], <2 x i64>* [[ARRAYIDX]], align 
16, [[TBAA6]]
 // CHECK-128-NEXT:ret void
 //
 // CHECK-256-LABEL: @write_int64(
 // CHECK-256-NEXT:  entry:
 // CHECK-256-NEXT:[[X_ADDR:%.*]] = alloca , align 16
-// CHECK-256-NEXT:store  [[X:%.*]], * 
[[X_ADDR]], align 16, [[TBAA5:!tbaa !.*]]
+// CHECK-256-NEXT:store  [[X:%.*]], * 
[[X_ADDR]], align 16, [[TBAA9:!tbaa !.*]]
 // CHECK-256-NEXT:[[TMP0:%.*]] = bitcast * [[X_ADDR]] to 
<4 x i64>*
-// CHECK-256-NEXT:[[TMP1:%.*]] = load <4 x i64>, <4 x i64>* [[TMP0]], 
align 16, [[TBAA2]]
+// CHECK-256-NEXT:[[TMP1:%.*]] = load <4 x i64>, <4 x i64>* [[TMP0]], 
align 16, [[TBAA6]]
 // CHECK-256-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds 
[[STRUCT_STRUCT_INT64:%.*]], %struct.struct_int64* [[S:%.*]], i64 0, i32 1, i64 0
-// CHECK-256-NEXT:store <4 x i64> [[TMP1]], <4 x i64>* [[ARRAYIDX]], align 
16, [[TBAA2]]
+// CHECK-256-NEXT:store <4 x i64> [[TMP1]], <4 x i64>* [[ARRAYIDX]], align 
16, [[TBAA6]]
 // CHECK-256-NEXT:ret void
 //
 // CHECK-512-LABEL: @write_int64(
 // CHECK-512-NEXT:  entry:
 // CHECK-512-NEXT:[[X_ADDR:%.*]] = alloca , align 16
-// CHECK-512-NEXT:store  [[X:%.*]], * 
[[X_ADDR]], align 16, [[TBAA5:!tbaa !.*]]
+// CHECK-512-NEXT:store  [[X:%.*]], * 
[[X_ADDR]], align 16, [[TBAA9:!tbaa !.*]]
 // CHECK-512-NEXT:[[TMP0:%.*]] = bitcast * [[X_ADDR]] to 
<8 x i64>*
-// CHECK-512-NEXT:[[TMP1:%.*]] = load <8 x i64>, <8 x i64>* [[TMP0]], 
align 16, [[TBAA2]]
+// 

[clang] 03bd519 - [OldPM] Pass manager: run SROA after (simple) loop unrolling

2020-10-04 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2020-10-04T11:53:50+03:00
New Revision: 03bd5198b6f7d9f49d72e6516d813a206f3b6d0d

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

LOG: [OldPM] Pass manager: run SROA after (simple) loop unrolling

I have stumbled into this pretty accidentally, when rewriting
some spaghetti-like code into something more structured,
which involved using some `std::array<>`s. And to my surprise,
the `alloca`s remained, causing about `+160%` perf regression.

https://llvm-compile-time-tracker.com/compare.php?from=bb6f4d32aac3eecb51909f4facc625219307ee68=d563e66f40f9d4d145cb2050e41cb961e2b37785=instructions
suggests that this has geomean compile-time cost of `+0.08%`.

Note that D68593 / cecc0d27ad58c0aed8ef9ed99bbf691e137a0f26
already did this chage for NewPM, but left OldPM in a pessimized state.

This fixes [[ https://bugs.llvm.org/show_bug.cgi?id=40011 | PR40011 ]], [[ 
https://bugs.llvm.org/show_bug.cgi?id=42794 | PR42794 ]] and probably some 
other reports.

Reviewed By: nikic, xbolva00

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

Added: 


Modified: 
clang/test/CodeGenCXX/union-tbaa2.cpp
clang/test/Misc/loop-opt-setup.c
llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
llvm/test/Other/opt-O2-pipeline.ll
llvm/test/Other/opt-O3-pipeline-enable-matrix.ll
llvm/test/Other/opt-O3-pipeline.ll
llvm/test/Other/opt-Os-pipeline.ll
llvm/test/Transforms/PhaseOrdering/X86/SROA-after-loop-unrolling.ll

Removed: 




diff  --git a/clang/test/CodeGenCXX/union-tbaa2.cpp 
b/clang/test/CodeGenCXX/union-tbaa2.cpp
index 5d13ff1ad8d9..65872d4a98ae 100644
--- a/clang/test/CodeGenCXX/union-tbaa2.cpp
+++ b/clang/test/CodeGenCXX/union-tbaa2.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -O2 -fno-experimental-new-pass-manager -std=c++11 
-triple x86_64-unknown-linux-gnu -target-cpu x86-64 -target-feature +sse4.2 
-target-feature +avx -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -O1 -std=c++11 -triple x86_64-unknown-linux-gnu 
-target-cpu x86-64 -target-feature +sse4.2 -target-feature +avx -emit-llvm -o - 
| FileCheck %s
 
 // Testcase from llvm.org/PR32056
 

diff  --git a/clang/test/Misc/loop-opt-setup.c 
b/clang/test/Misc/loop-opt-setup.c
index 868c716c6ed7..322f5e0e6d4a 100644
--- a/clang/test/Misc/loop-opt-setup.c
+++ b/clang/test/Misc/loop-opt-setup.c
@@ -1,5 +1,5 @@
-// RUN: %clang -O1 -fexperimental-new-pass-manager -fno-unroll-loops -S -o - 
%s -emit-llvm | FileCheck %s -check-prefix=CHECK-NEWPM
-// RUN: %clang -O1 -fno-experimental-new-pass-manager -fno-unroll-loops -S -o 
- %s -emit-llvm | FileCheck %s -check-prefix=CHECK-OLDPM
+// RUN: %clang -O1 -fno-unroll-loops -S -o - %s -emit-llvm | FileCheck %s
+
 extern int a[16];
 int b = 0;
 int foo(void) {
@@ -9,10 +9,8 @@ int foo(void) {
   return b;
 }
 // Check br i1 to make sure that the loop is fully unrolled
-// CHECK-LABEL-NEWPM: foo
-// CHECK-NOT-NEWPM: br i1
-// CHECK-LABEL-OLDPM: foo
-// CHECK-NOT-OLDPM: br i1
+// CHECK-LABEL: foo
+// CHECK-NOT: br i1
 
 void Helper() {
   const int *nodes[5];
@@ -26,17 +24,7 @@ void Helper() {
 }
 
 // Check br i1 to make sure the loop is gone, there will still be a label 
branch for the infinite loop.
-// CHECK-LABEL-NEWPM: Helper
-// CHECK-NEWPM: br label
-// CHECK-NEWPM-NOT: br i1
-// CHECK-NEWPM: br label
-
-// The old pass manager doesn't remove the while loop so check for 5 load i32*.
-// CHECK-LABEL-OLDPM: Helper
-// CHECK-OLDPM: br label
-// CHECK-OLDPM: load i32*
-// CHECK-OLDPM: load i32*
-// CHECK-OLDPM: load i32*
-// CHECK-OLDPM: load i32*
-// CHECK-OLDPM: load i32*
-// CHECK-OLDPM: ret
+// CHECK-LABEL: Helper
+// CHECK: br label
+// CHECK-NOT: br i1
+// CHECK: br label

diff  --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
index ccc493640b29..043effc97f2b 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
@@ -479,14 +479,6 @@ void 
AMDGPUTargetMachine::adjustPassManager(PassManagerBuilder ) {
   if (EnableOpt)
 PM.add(createAMDGPUPromoteAllocaToVector());
   });
-
-  Builder.addExtension(
-  PassManagerBuilder::EP_LoopOptimizerEnd,
-  [](const PassManagerBuilder &, legacy::PassManagerBase ) {
-// Add SROA after loop unrolling as more promotable patterns are
-// exposed after small loops are fully unrolled.
-PM.add(createSROAPass());
-  });
 }
 
 
//===--===//

diff  --git a/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp 
b/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
index c63705a4ee94..088f1e25f3d1 100644
--- 

[clang-tools-extra] 1596cc8 - [NFCI][clang-tidy] FunctionCognitiveComplexityCheck::check(): try to fix windows arm build bots

2020-10-03 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2020-10-03T16:02:19+03:00
New Revision: 1596cc83509342eb37dbfe6b95e906759afc6741

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

LOG: [NFCI][clang-tidy] FunctionCognitiveComplexityCheck::check(): try to fix 
windows arm build bots

http://lab.llvm.org:8011/builders/llvm-clang-win-x-armv7l/builds/1482/steps/build-llvm-project/logs/stdio
http://lab.llvm.org:8011/builders/llvm-clang-win-x-aarch64/builds/3285/steps/build-llvm-project/logs/stdio

Added: 


Modified: 

clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
index 548aec7543ac..96fe9a2e29a4 100644
--- 
a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
@@ -533,7 +533,7 @@ void FunctionCognitiveComplexityCheck::check(
 // Increase, on the other hand, can be 0.
 
 diag(Detail.Loc, Msgs[MsgId], DiagnosticIDs::Note)
-<< Increase << Detail.Nesting << 1 + Detail.Nesting;
+<< (unsigned)Increase << (unsigned)Detail.Nesting << 1 + 
Detail.Nesting;
   }
 }
 



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


[clang-tools-extra] ace6440 - [clang-tidy] Implement readability-function-cognitive-complexity check

2020-10-02 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2020-10-03T00:27:13+03:00
New Revision: ace644030e67506114d3ac9a221cf8eb5d10159c

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

LOG: [clang-tidy] Implement readability-function-cognitive-complexity check

Currently, there is basically just one clang-tidy check to impose
some sanity limits on functions - `clang-tidy-readability-function-size`.
It is nice, allows to limit line count, total number of statements,
number of branches, number of function parameters (not counting
implicit `this`), nesting level.

However, those are simple generic metrics. It is still trivially possible
to write a function, which does not violate any of these metrics,
yet is still rather unreadable.

Thus, some additional, slightly more complicated metric is needed.
There is a well-known [[ https://en.wikipedia.org/wiki/Cyclomatic_complexity | 
Cyclomatic complexity]], but certainly has its downsides.
And there is a [[ https://www.sonarsource.com/docs/CognitiveComplexity.pdf | 
COGNITIVE COMPLEXITY by SonarSource ]], which is available for opensource on 
https://sonarcloud.io/.

This check checks function Cognitive Complexity metric, and flags
the functions with Cognitive Complexity exceeding the configured limit.
The default limit is `25`, same as in 'upstream'.

The metric is implemented as per [[ 
https://www.sonarsource.com/docs/CognitiveComplexity.pdf | COGNITIVE COMPLEXITY 
by SonarSource ]] specification version 1.2 (19 April 2017), with two notable 
exceptions:
   * `preprocessor conditionals` (`#ifdef`, `#if`, `#elif`, `#else`,
 `#endif`) are not accounted for.
  Could be done. Currently, upstream does not account for them either.
   * `each method in a recursion cycle` is not accounted for.
  It can't be fully implemented, because cross-translational-unit
  analysis would be needed, which is not possible in clang-tidy.
  Thus, at least right now, i completely avoided implementing it.

There are some further possible improvements:
* Are GNU statement expressions (`BinaryConditionalOperator`) really free?
  They should probably cause nesting level increase,
  and complexity level increase when they are nested within eachother.
* Microsoft SEH support
* ???

Reviewed By: aaron.ballman, JonasToth, lattner

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

Added: 

clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.h

clang-tools-extra/docs/clang-tidy/checks/readability-function-cognitive-complexity.rst

clang-tools-extra/test/clang-tidy/checkers/readability-function-cognitive-complexity.cpp

Modified: 
clang-tools-extra/clang-tidy/readability/CMakeLists.txt
clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 4539ab177ced..ecf37b5b9157 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -12,6 +12,7 @@ add_clang_library(clangTidyReadabilityModule
   DeleteNullPointerCheck.cpp
   DeletedDefaultCheck.cpp
   ElseAfterReturnCheck.cpp
+  FunctionCognitiveComplexityCheck.cpp
   FunctionSizeCheck.cpp
   IdentifierNamingCheck.cpp
   ImplicitBoolConversionCheck.cpp

diff  --git 
a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
new file mode 100644
index ..548aec7543ac
--- /dev/null
+++ 
b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
@@ -0,0 +1,542 @@
+//===--- FunctionCognitiveComplexityCheck.cpp - clang-tidy --*- 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
+//
+//===--===//
+
+#include "FunctionCognitiveComplexityCheck.h"
+#include "../ClangTidyDiagnosticConsumer.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclBase.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersInternal.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticIDs.h"
+#include "clang/Basic/LLVM.h"
+#include 

Re: [clang-tools-extra] 772bd8a - Revert "[CUDA][HIP] Defer overloading resolution diagnostics for host device functions"

2020-09-17 Thread Roman Lebedev via cfe-commits
Same comment about commit message, thanks

On Thu, Sep 17, 2020 at 8:56 PM Yaxun Liu via cfe-commits
 wrote:
>
>
> Author: Yaxun (Sam) Liu
> Date: 2020-09-17T13:55:31-04:00
> New Revision: 772bd8a7d99b8db899f594d393986e4b6cd85aa1
>
> URL: 
> https://github.com/llvm/llvm-project/commit/772bd8a7d99b8db899f594d393986e4b6cd85aa1
> DIFF: 
> https://github.com/llvm/llvm-project/commit/772bd8a7d99b8db899f594d393986e4b6cd85aa1.diff
>
> LOG: Revert "[CUDA][HIP] Defer overloading resolution diagnostics for host 
> device functions"
>
> This reverts commit 7f1f89ec8d9944559042bb6d3b1132eabe3409de.
>
> This reverts commit 40df06cdafc010002fc9cfe1dda73d689b7d27a6.
>
> Added:
>
>
> Modified:
> clang-tools-extra/clangd/Diagnostics.cpp
> clang/include/clang/Basic/Diagnostic.td
> clang/include/clang/Basic/DiagnosticAST.h
> clang/include/clang/Basic/DiagnosticAnalysis.h
> clang/include/clang/Basic/DiagnosticComment.h
> clang/include/clang/Basic/DiagnosticCrossTU.h
> clang/include/clang/Basic/DiagnosticDriver.h
> clang/include/clang/Basic/DiagnosticFrontend.h
> clang/include/clang/Basic/DiagnosticIDs.h
> clang/include/clang/Basic/DiagnosticLex.h
> clang/include/clang/Basic/DiagnosticParse.h
> clang/include/clang/Basic/DiagnosticRefactoring.h
> clang/include/clang/Basic/DiagnosticSema.h
> clang/include/clang/Basic/DiagnosticSemaKinds.td
> clang/include/clang/Basic/DiagnosticSerialization.h
> clang/include/clang/Basic/LangOptions.def
> clang/include/clang/Driver/Options.td
> clang/include/clang/Sema/Sema.h
> clang/lib/Basic/DiagnosticIDs.cpp
> clang/lib/Driver/ToolChains/Cuda.cpp
> clang/lib/Driver/ToolChains/HIP.cpp
> clang/lib/Frontend/CompilerInvocation.cpp
> clang/lib/Sema/AnalysisBasedWarnings.cpp
> clang/lib/Sema/Sema.cpp
> clang/lib/Sema/SemaAttr.cpp
> clang/lib/Sema/SemaCUDA.cpp
> clang/lib/Sema/SemaDecl.cpp
> clang/lib/Sema/SemaExprObjC.cpp
> clang/lib/Sema/SemaOpenMP.cpp
> clang/lib/Sema/SemaOverload.cpp
> clang/lib/Sema/SemaSYCL.cpp
> clang/lib/Sema/SemaStmt.cpp
> clang/lib/Sema/SemaStmtAsm.cpp
> clang/lib/Sema/SemaTemplateInstantiate.cpp
> clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
> clang/lib/Sema/SemaTemplateVariadic.cpp
> clang/lib/Sema/SemaType.cpp
> clang/test/TableGen/DiagnosticBase.inc
> clang/tools/diagtool/DiagnosticNames.cpp
> clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
>
> Removed:
> clang/test/SemaCUDA/deferred-oeverload.cu
> clang/test/TableGen/deferred-diag.td
>
>
> 
> diff  --git a/clang-tools-extra/clangd/Diagnostics.cpp 
> b/clang-tools-extra/clangd/Diagnostics.cpp
> index 18ff96202e0a..afa72f9d4051 100644
> --- a/clang-tools-extra/clangd/Diagnostics.cpp
> +++ b/clang-tools-extra/clangd/Diagnostics.cpp
> @@ -43,7 +43,7 @@ namespace {
>  const char *getDiagnosticCode(unsigned ID) {
>switch (ID) {
>  #define DIAG(ENUM, CLASS, DEFAULT_MAPPING, DESC, GROPU, SFINAE, NOWERROR,
>   \
> - SHOWINSYSHEADER, DEFERRABLE, CATEGORY)  
>   \
> + SHOWINSYSHEADER, CATEGORY)  
>   \
>case clang::diag::ENUM:
>   \
>  return #ENUM;
>  #include "clang/Basic/DiagnosticASTKinds.inc"
>
> diff  --git a/clang/include/clang/Basic/Diagnostic.td 
> b/clang/include/clang/Basic/Diagnostic.td
> index ab2c738a2ace..48ba8c0f469f 100644
> --- a/clang/include/clang/Basic/Diagnostic.td
> +++ b/clang/include/clang/Basic/Diagnostic.td
> @@ -45,7 +45,6 @@ class TextSubstitution {
>// diagnostics
>string Component = "";
>string CategoryName = "";
> -  bit Deferrable = 0;
>  }
>
>  // Diagnostic Categories.  These can be applied to groups or individual
> @@ -84,7 +83,6 @@ class Diagnostic defaultmapping> {
>bitAccessControl = 0;
>bitWarningNoWerror = 0;
>bitShowInSystemHeader = 0;
> -  bitDeferrable = 0;
>Severity   DefaultSeverity = defaultmapping;
>DiagGroup  Group;
>string CategoryName = "";
> @@ -108,14 +106,6 @@ class SuppressInSystemHeader {
>bit ShowInSystemHeader = 0;
>  }
>
> -class Deferrable {
> -  bit Deferrable = 1;
> -}
> -
> -class NonDeferrable {
> -  bit Deferrable = 0;
> -}
> -
>  // FIXME: ExtWarn and Extension should also be SFINAEFailure by default.
>  class Error : Diagnostic, 
> SFINAEFailure {
>bit ShowInSystemHeader = 1;
>
> diff  --git a/clang/include/clang/Basic/DiagnosticAST.h 
> b/clang/include/clang/Basic/DiagnosticAST.h
> index 76c31ad9508e..afe5f62e2012 100644
> --- a/clang/include/clang/Basic/DiagnosticAST.h
> +++ b/clang/include/clang/Basic/DiagnosticAST.h
> @@ -15,7 +15,7 @@ namespace clang {
>  namespace diag {
>  enum {
>  #define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, 

Re: [clang] 829d14e - Revert "[NFC] Refactor DiagnosticBuilder and PartialDiagnostic"

2020-09-17 Thread Roman Lebedev via cfe-commits
On Thu, Sep 17, 2020 at 8:57 PM Yaxun Liu via cfe-commits
 wrote:
>
>
> Author: Yaxun (Sam) Liu
> Date: 2020-09-17T13:56:09-04:00
> New Revision: 829d14ee0a6aa79c89f7f3d9fcd9d27d3efd2b91
>
> URL: 
> https://github.com/llvm/llvm-project/commit/829d14ee0a6aa79c89f7f3d9fcd9d27d3efd2b91
> DIFF: 
> https://github.com/llvm/llvm-project/commit/829d14ee0a6aa79c89f7f3d9fcd9d27d3efd2b91.diff
>
> LOG: Revert "[NFC] Refactor DiagnosticBuilder and PartialDiagnostic"
>
> This reverts commit ee5519d323571c4a9a7d92cb817023c9b95334cd.

It is a really good idea for a commit message to actually explain what
the commit does, not just state what it is.

> Added:
>
>
> Modified:
> clang/include/clang/AST/ASTContext.h
> clang/include/clang/AST/Attr.h
> clang/include/clang/AST/CanonicalType.h
> clang/include/clang/AST/Decl.h
> clang/include/clang/AST/DeclCXX.h
> clang/include/clang/AST/DeclarationName.h
> clang/include/clang/AST/NestedNameSpecifier.h
> clang/include/clang/AST/TemplateBase.h
> clang/include/clang/AST/TemplateName.h
> clang/include/clang/AST/Type.h
> clang/include/clang/Basic/Diagnostic.h
> clang/include/clang/Basic/PartialDiagnostic.h
> clang/include/clang/Sema/Ownership.h
> clang/include/clang/Sema/ParsedAttr.h
> clang/include/clang/Sema/Sema.h
> clang/lib/AST/ASTContext.cpp
> clang/lib/AST/DeclCXX.cpp
> clang/lib/AST/TemplateBase.cpp
> clang/lib/AST/TemplateName.cpp
> clang/lib/Basic/Diagnostic.cpp
>
> Removed:
>
>
>
> 
> diff  --git a/clang/include/clang/AST/ASTContext.h 
> b/clang/include/clang/AST/ASTContext.h
> index 397fee4d866b..de0d1198b6d4 100644
> --- a/clang/include/clang/AST/ASTContext.h
> +++ b/clang/include/clang/AST/ASTContext.h
> @@ -3064,9 +3064,8 @@ OPT_LIST(V)
>  };
>
>  /// Insertion operator for diagnostics.
> -const StreamableDiagnosticBase &
> -operator<<(const StreamableDiagnosticBase ,
> -   const ASTContext::SectionInfo );
> +const DiagnosticBuilder <<(const DiagnosticBuilder ,
> +const ASTContext::SectionInfo );
>
>  /// Utility function for constructing a nullary selector.
>  inline Selector GetNullarySelector(StringRef name, ASTContext ) {
>
> diff  --git a/clang/include/clang/AST/Attr.h b/clang/include/clang/AST/Attr.h
> index b4dce8f41c67..b3729b2e0d99 100644
> --- a/clang/include/clang/AST/Attr.h
> +++ b/clang/include/clang/AST/Attr.h
> @@ -350,12 +350,19 @@ struct ParsedTargetAttr {
>
>  #include "clang/AST/Attrs.inc"
>
> -inline const StreamableDiagnosticBase &
> -operator<<(const StreamableDiagnosticBase , const Attr *At) {
> +inline const DiagnosticBuilder <<(const DiagnosticBuilder ,
> +   const Attr *At) {
>DB.AddTaggedVal(reinterpret_cast(At),
>DiagnosticsEngine::ak_attr);
>return DB;
>  }
> +
> +inline const PartialDiagnostic <<(const PartialDiagnostic ,
> +   const Attr *At) {
> +  PD.AddTaggedVal(reinterpret_cast(At),
> +  DiagnosticsEngine::ak_attr);
> +  return PD;
> +}
>  }  // end namespace clang
>
>  #endif
>
> diff  --git a/clang/include/clang/AST/CanonicalType.h 
> b/clang/include/clang/AST/CanonicalType.h
> index b6d9b69db09a..488284713bce 100644
> --- a/clang/include/clang/AST/CanonicalType.h
> +++ b/clang/include/clang/AST/CanonicalType.h
> @@ -215,8 +215,8 @@ inline CanQualType Type::getCanonicalTypeUnqualified() 
> const {
>return CanQualType::CreateUnsafe(getCanonicalTypeInternal());
>  }
>
> -inline const StreamableDiagnosticBase &
> -operator<<(const StreamableDiagnosticBase , CanQualType T) {
> +inline const DiagnosticBuilder <<(const DiagnosticBuilder ,
> +   CanQualType T) {
>DB << static_cast(T);
>return DB;
>  }
>
> diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
> index 852ba2316f82..c2511514fe72 100644
> --- a/clang/include/clang/AST/Decl.h
> +++ b/clang/include/clang/AST/Decl.h
> @@ -4513,8 +4513,14 @@ class EmptyDecl : public Decl {
>
>  /// Insertion operator for diagnostics.  This allows sending NamedDecl's
>  /// into a diagnostic with <<.
> -inline const StreamableDiagnosticBase &
> -operator<<(const StreamableDiagnosticBase , const NamedDecl *ND) {
> +inline const DiagnosticBuilder <<(const DiagnosticBuilder ,
> +   const NamedDecl* ND) {
> +  DB.AddTaggedVal(reinterpret_cast(ND),
> +  DiagnosticsEngine::ak_nameddecl);
> +  return DB;
> +}
> +inline const PartialDiagnostic <<(const PartialDiagnostic ,
> +   const NamedDecl* ND) {
>PD.AddTaggedVal(reinterpret_cast(ND),
>DiagnosticsEngine::ak_nameddecl);
>return PD;
>
> diff  --git a/clang/include/clang/AST/DeclCXX.h 
> b/clang/include/clang/AST/DeclCXX.h
> index 

[clang-tools-extra] ebf496d - Revert "[clang-tidy] New check readability-prefer-member-initializer"

2020-09-10 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2020-09-10T16:32:18+03:00
New Revision: ebf496d805521b53022a351f35854de977fee844

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

LOG: Revert "[clang-tidy] New check readability-prefer-member-initializer"

Either contains unbounded loops, or has *very* high runtime,
100+x of all the current clang-tidy checks.

This reverts commit f5fd7486d6c0debb465de3e927fcc31884874280.

Added: 


Modified: 
clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt

clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 

clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp

clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.h

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-prefer-member-initializer.rst

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer-modernize-use-default-member-init-assignment.cpp

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer-modernize-use-default-member-init.cpp

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp



diff  --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
index a9f5b3e0c15b..39c2c552eb73 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
@@ -13,7 +13,6 @@ add_clang_library(clangTidyCppCoreGuidelinesModule
   NarrowingConversionsCheck.cpp
   NoMallocCheck.cpp
   OwningMemoryCheck.cpp
-  PreferMemberInitializerCheck.cpp
   ProBoundsArrayToPointerDecayCheck.cpp
   ProBoundsConstantArrayIndexCheck.cpp
   ProBoundsPointerArithmeticCheck.cpp

diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
index bf613109f0eb..4cb5022888d3 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
@@ -22,7 +22,6 @@
 #include "NarrowingConversionsCheck.h"
 #include "NoMallocCheck.h"
 #include "OwningMemoryCheck.h"
-#include "PreferMemberInitializerCheck.h"
 #include "ProBoundsArrayToPointerDecayCheck.h"
 #include "ProBoundsConstantArrayIndexCheck.h"
 #include "ProBoundsPointerArithmeticCheck.h"
@@ -67,8 +66,6 @@ class CppCoreGuidelinesModule : public ClangTidyModule {
 "cppcoreguidelines-non-private-member-variables-in-classes");
 CheckFactories.registerCheck(
 "cppcoreguidelines-owning-memory");
-CheckFactories.registerCheck(
-"cppcoreguidelines-prefer-member-initializer");
 CheckFactories.registerCheck(
 "cppcoreguidelines-pro-bounds-array-to-pointer-decay");
 CheckFactories.registerCheck(

diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
deleted file mode 100644
index 97ae586f9fdb..
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
+++ /dev/null
@@ -1,233 +0,0 @@
-//===--- PreferMemberInitializerCheck.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 "PreferMemberInitializerCheck.h"
-#include "clang/AST/ASTContext.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/Lex/Lexer.h"
-
-using namespace clang::ast_matchers;
-
-namespace clang {
-namespace tidy {
-namespace cppcoreguidelines {
-
-static bool isControlStatement(const Stmt *S) {
-  return isa(S) || isa(S) || isa(S) ||
- isa(S) || isa(S) || isa(S) ||
- isa(S) || isa(S) || isa(S);
-}
-
-static bool isNoReturnCallStatement(const Stmt *S) {
-  const auto *Call = dyn_cast(S);
-  if (!Call)
-return false;
-
-  const FunctionDecl *Func = Call->getDirectCallee();
-  if (!Func)
-return false;
-
-  return Func->isNoReturn();
-}
-
-static bool isLiteral(const Expr *E) {
-  return isa(E) || isa(E) ||
- isa(E) || isa(E) ||
- isa(E) || isa(E);
-}
-
-static bool isUnaryExprOfLiteral(const Expr *E) {
-  if (const auto *UnOp = dyn_cast(E))
-return isLiteral(UnOp->getSubExpr());
-  

[clang] 8427885 - Temporairly revert "Thread safety analysis: Consider global variables in scope" & followup

2020-09-09 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2020-09-09T12:15:56+03:00
New Revision: 8427885e27813c457dccb011f65e8ded7e31

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

LOG: Temporairly revert "Thread safety analysis: Consider global variables in 
scope" & followup

This appears to cause false-positives because it started to warn on local 
non-global variables.

Repro posted to https://reviews.llvm.org/D84604#2262745

This reverts commit 9dcc82f34ea9b623d82d2577b93aaf67d36dabd2.
This reverts commit b2ce79ef66157dd752e3864ece57915e23a73f5d.

Added: 


Modified: 
clang/lib/Analysis/ThreadSafety.cpp
clang/lib/Analysis/ThreadSafetyCommon.cpp
clang/test/SemaCXX/warn-thread-safety-analysis.cpp
clang/test/SemaCXX/warn-thread-safety-negative.cpp

Removed: 




diff  --git a/clang/lib/Analysis/ThreadSafety.cpp 
b/clang/lib/Analysis/ThreadSafety.cpp
index 5b97265a6d8a..64e0da9e64b1 100644
--- a/clang/lib/Analysis/ThreadSafety.cpp
+++ b/clang/lib/Analysis/ThreadSafety.cpp
@@ -1266,21 +1266,13 @@ ClassifyDiagnostic(const AttrTy *A) {
 }
 
 bool ThreadSafetyAnalyzer::inCurrentScope(const CapabilityExpr ) {
-  const threadSafety::til::SExpr *SExp = CapE.sexpr();
-  assert(SExp && "Null expressions should be ignored");
-
-  // Global variables are always in scope.
-  if (isa(SExp))
-return true;
-
-  // Members are in scope from methods of the same class.
-  if (const auto *P = dyn_cast(SExp)) {
-if (!CurrentMethod)
+  if (!CurrentMethod)
   return false;
-const ValueDecl *VD = P->clangDecl();
-return VD->getDeclContext() == CurrentMethod->getDeclContext();
+  if (const auto *P = dyn_cast_or_null(CapE.sexpr())) {
+const auto *VD = P->clangDecl();
+if (VD)
+  return VD->getDeclContext() == CurrentMethod->getDeclContext();
   }
-
   return false;
 }
 

diff  --git a/clang/lib/Analysis/ThreadSafetyCommon.cpp 
b/clang/lib/Analysis/ThreadSafetyCommon.cpp
index aee918576007..1b8c55e56d47 100644
--- a/clang/lib/Analysis/ThreadSafetyCommon.cpp
+++ b/clang/lib/Analysis/ThreadSafetyCommon.cpp
@@ -274,7 +274,7 @@ til::SExpr *SExprBuilder::translateDeclRefExpr(const 
DeclRefExpr *DRE,
   const auto *VD = cast(DRE->getDecl()->getCanonicalDecl());
 
   // Function parameters require substitution and/or renaming.
-  if (const auto *PV = dyn_cast(VD)) {
+  if (const auto *PV = dyn_cast_or_null(VD)) {
 unsigned I = PV->getFunctionScopeIndex();
 const DeclContext *D = PV->getDeclContext();
 if (Ctx && Ctx->FunArgs) {

diff  --git a/clang/test/SemaCXX/warn-thread-safety-analysis.cpp 
b/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
index d1520b1decbd..91bd15def577 100644
--- a/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
+++ b/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
@@ -5036,8 +5036,7 @@ void spawn_fake_flight_control_thread(void) {
 }
 
 extern const char *deque_log_msg(void) 
__attribute__((requires_capability(Logger)));
-void logger_entry(void) __attribute__((requires_capability(Logger)))
-__attribute__((requires_capability(!FlightControl))) {
+void logger_entry(void) __attribute__((requires_capability(Logger))) {
   const char *msg;
 
   while ((msg = deque_log_msg())) {
@@ -5045,13 +5044,13 @@ void logger_entry(void) 
__attribute__((requires_capability(Logger)))
   }
 }
 
-void spawn_fake_logger_thread(void) 
__attribute__((requires_capability(!FlightControl))) {
+void spawn_fake_logger_thread(void) {
   acquire(Logger);
   logger_entry();
   release(Logger);
 }
 
-int main(void) __attribute__((requires_capability(!FlightControl))) {
+int main(void) {
   spawn_fake_flight_control_thread();
   spawn_fake_logger_thread();
 

diff  --git a/clang/test/SemaCXX/warn-thread-safety-negative.cpp 
b/clang/test/SemaCXX/warn-thread-safety-negative.cpp
index 68e30f4a3225..456fe16e6574 100644
--- a/clang/test/SemaCXX/warn-thread-safety-negative.cpp
+++ b/clang/test/SemaCXX/warn-thread-safety-negative.cpp
@@ -81,35 +81,6 @@ class Foo {
 
 }  // end namespace SimpleTest
 
-Mutex globalMutex;
-
-namespace ScopeTest {
-
-void f() EXCLUSIVE_LOCKS_REQUIRED(!globalMutex);
-void fq() EXCLUSIVE_LOCKS_REQUIRED(!::globalMutex);
-
-namespace ns {
-  Mutex globalMutex;
-  void f() EXCLUSIVE_LOCKS_REQUIRED(!globalMutex);
-  void fq() EXCLUSIVE_LOCKS_REQUIRED(!ns::globalMutex);
-}
-
-void testGlobals() EXCLUSIVE_LOCKS_REQUIRED(!ns::globalMutex) {
-  f(); // expected-warning {{calling function 'f' requires negative 
capability '!globalMutex'}}
-  fq();// expected-warning {{calling function 'fq' requires negative 
capability '!globalMutex'}}
-  ns::f();
-  ns::fq();
-}
-
-void testNamespaceGlobals() EXCLUSIVE_LOCKS_REQUIRED(!globalMutex) {
-  f();
-  fq();
-  ns::f();  // expected-warning {{calling function 'f' requires negative 

[clang] 790878f - [NFC][clang] Adjust test/CodeGenCXX/nrvo.cpp after 03127f795b8244c1039c18d4391374707a3dc75e

2020-08-17 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2020-08-18T00:57:35+03:00
New Revision: 790878f291fa5dc58a1c560cb6cc76fd1bfd1c5a

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

LOG: [NFC][clang] Adjust test/CodeGenCXX/nrvo.cpp after 
03127f795b8244c1039c18d4391374707a3dc75e

Added: 


Modified: 
clang/test/CodeGenCXX/nrvo.cpp

Removed: 




diff  --git a/clang/test/CodeGenCXX/nrvo.cpp b/clang/test/CodeGenCXX/nrvo.cpp
index 1a5e63cd7fd7..51b62e68c3af 100644
--- a/clang/test/CodeGenCXX/nrvo.cpp
+++ b/clang/test/CodeGenCXX/nrvo.cpp
@@ -85,8 +85,6 @@ X test2(bool B) {
   // %lpad: landing pad for ctor of 'y', dtor of 'y'
   // CHECK-EH:  [[CAUGHTVAL:%.*]] = landingpad { i8*, i32 }
   // CHECK-EH-NEXT:   cleanup
-  // CHECK-EH-03-NEXT: extractvalue { i8*, i32 } [[CAUGHTVAL]], 0
-  // CHECK-EH-03-NEXT: extractvalue { i8*, i32 } [[CAUGHTVAL]], 1
   // CHECK-EH-NEXT: br label
   // -> %eh.cleanup
 



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


[clang] ae7f088 - [InstCombine] Aggregate reconstruction simplification (PR47060)

2020-08-16 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2020-08-16T23:27:56+03:00
New Revision: ae7f08812e0995481eb345cecc5dd4529829ba44

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

LOG: [InstCombine] Aggregate reconstruction simplification (PR47060)

This pattern happens in clang C++ exception lowering code, on unwind branch.
We end up having a `landingpad` block after each `invoke`, where RAII
cleanup is performed, and the elements of an aggregate `{i8*, i32}`
holding exception info are `extractvalue`'d, and we then branch to common block
that takes extracted `i8*` and `i32` elements (via `phi` nodes),
form a new aggregate, and finally `resume`'s the exception.

The problem is that, if the cleanup block is effectively empty,
it shouldn't be there, there shouldn't be that `landingpad` and `resume`,
said `invoke` should be a  `call`.

Indeed, we do that simplification in e.g. SimplifyCFG 
`SimplifyCFGOpt::simplifyResume()`.
But the thing is, all this extra `extractvalue` + `phi` + `insertvalue` cruft,
while it is pointless, does not look like "empty cleanup block".
So the `SimplifyCFGOpt::simplifyResume()` fails, and the exception is has
higher cost than it could have on unwind branch :S

This doesn't happen *that* often, but it will basically happen once per C++
function with complex CFG that called more than one other function
that isn't known to be `nounwind`.

I think, this is a missing fold in InstCombine, so i've implemented it.

I think, the algorithm/implementation is rather self-explanatory:
1. Find a chain of `insertvalue`'s that fully tell us the initializer of the 
aggregate.
2. For each element, try to find from which aggregate it was extracted.
   If it was extracted from the aggregate with identical type,
   from identical element index, great.
3. If all elements were found to have been extracted from the same aggregate,
   then we can just use said original source aggregate directly,
   instead of re-creating it.
4. If we fail to find said aggregate when looking only in the current block,
   we need be PHI-aware - we might have different source aggregate when coming
   from each predecessor.

I'm not sure if this already handles everything, and there are some FIXME's,
i'll deal with all that later in followups.

I'd be fine with going with post-commit review here code-wise,
but just in case there are thoughts, i'm posting this.

On RawSpeed, for example, this has the following effect:
```
| statistic name| baseline | proposed | 
Δ |   % | abs(%) |
|---|-:|-:|--:|:|---:|
| instcombine.NumAggregateReconstructionsSimplified |0 | 1253 |  
1253 |   0.00% |  0.00% |
| simplifycfg.NumInvokes|  948 | 1355 |   
407 |  42.93% | 42.93% |
| instcount.NumInsertValueInst  | 4382 | 3210 | 
-1172 | -26.75% | 26.75% |
| simplifycfg.NumSinkCommonCode |  574 |  458 |  
-116 | -20.21% | 20.21% |
| simplifycfg.NumSinkCommonInstrs   | 1154 |  921 |  
-233 | -20.19% | 20.19% |
| instcount.NumExtractValueInst |29017 |26397 | 
-2620 |  -9.03% |  9.03% |
| instcombine.NumDeadInst   |   166618 |   174705 |  
8087 |   4.85% |  4.85% |
| instcount.NumPHIInst  |51526 |50678 |  
-848 |  -1.65% |  1.65% |
| instcount.NumLandingPadInst   |20865 |20609 |  
-256 |  -1.23% |  1.23% |
| instcount.NumInvokeInst   |34023 |33675 |  
-348 |  -1.02% |  1.02% |
| simplifycfg.NumSimpl  |   113634 |   114708 |  
1074 |   0.95% |  0.95% |
| instcombine.NumSunkInst   |15030 |14930 |  
-100 |  -0.67% |  0.67% |
| instcount.TotalBlocks |   219544 |   219024 |  
-520 |  -0.24% |  0.24% |
| instcombine.NumCombined   |   644562 |   645805 |  
1243 |   0.19% |  0.19% |
| instcount.TotalInsts  |  2139506 |  2135377 | 
-4129 |  -0.19% |  0.19% |
| instcount.NumBrInst   |   156988 |   156821 |  
-167 |  -0.11% |  0.11% |
| instcount.NumCallInst |  1206144 |  1207076 |   
932 |   0.08% |  0.08% |
| instcount.NumResumeInst   | 5193 | 5190 |
-3 |  -0.06% |  0.06% |
| asm-printer.EmittedInsts  |   948580 |   948299 |  
-281 |  -0.03% |  0.03% |
| instcount.TotalFuncs  |11509 |11507 |
-2 |  -0.02% |  0.02% |
| inline.NumDeleted |97595 |97597 | 
2 |   0.00% |  0.00% |
| inline.NumInlined   

[clang] 7fed3cf - [clang] Fix two tests that are affected by llvm opt change

2020-07-04 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2020-07-04T18:26:22+03:00
New Revision: 7fed3cfadbdfe1880e16c217a0edac97cbe288d2

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

LOG: [clang] Fix two tests that are affected by llvm opt change

Added: 


Modified: 
clang/test/CodeGen/thinlto-distributed-cfi-devirt.ll
clang/test/CodeGenOpenCL/convergent.cl

Removed: 




diff  --git a/clang/test/CodeGen/thinlto-distributed-cfi-devirt.ll 
b/clang/test/CodeGen/thinlto-distributed-cfi-devirt.ll
index b46845afba26..5c753ba6f93c 100644
--- a/clang/test/CodeGen/thinlto-distributed-cfi-devirt.ll
+++ b/clang/test/CodeGen/thinlto-distributed-cfi-devirt.ll
@@ -93,7 +93,7 @@ cont2:
   ; CHECK-IR: br i1 {{.*}}, label %trap
 
   ; We still have to call it as virtual.
-  ; CHECK-IR: %call3 = tail call i32 %8
+  ; CHECK-IR: %call3 = tail call i32 %7
   %call3 = tail call i32 %8(%struct.A* nonnull %obj, i32 %call)
   ret i32 %call3
 }

diff  --git a/clang/test/CodeGenOpenCL/convergent.cl 
b/clang/test/CodeGenOpenCL/convergent.cl
index 193d391ced20..49d182579e4c 100644
--- a/clang/test/CodeGenOpenCL/convergent.cl
+++ b/clang/test/CodeGenOpenCL/convergent.cl
@@ -70,9 +70,9 @@ void test_merge_if(int a) {
 // CHECK-NOT: call spir_func void @g()
 // CHECK: br label %[[if_end]]
 // CHECK: [[if_end]]:
-// CHECK:  %[[tobool_pr:.+]] = phi i1 [ true, %[[if_then]] ], [ false, %{{.+}} 
]
+// CHECK:  %[[tobool_not_pr:.+]] = phi i1 [ true, %{{.+}} ], [ false, 
%[[if_then]] ]
 // CHECK:  tail call spir_func void @convfun() #[[attr4:.+]]
-// CHECK:  br i1 %[[tobool_pr]], label %[[if_then2:.+]], label %[[if_end3:.+]]
+// CHECK:  br i1 %[[tobool_not_pr]], label %[[if_end3:.+]], label 
%[[if_then2:.+]]
 // CHECK: [[if_then2]]:
 // CHECK: tail call spir_func void @g()
 // CHECK:  br label %[[if_end3:.+]]



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


Re: [clang] 3e39760 - Revert "Return "[InstCombine] Simplify compare of Phi with constant inputs against a constant""

2020-06-15 Thread Roman Lebedev via cfe-commits
Reproducers?

On Mon, Jun 15, 2020 at 9:47 AM Sam Parker via cfe-commits
 wrote:
>
>
> Author: Sam Parker
> Date: 2020-06-15T07:46:28+01:00
> New Revision: 3e39760f8eaad4770efa05824768e67237915cf5
>
> URL: 
> https://github.com/llvm/llvm-project/commit/3e39760f8eaad4770efa05824768e67237915cf5
> DIFF: 
> https://github.com/llvm/llvm-project/commit/3e39760f8eaad4770efa05824768e67237915cf5.diff
>
> LOG: Revert "Return "[InstCombine] Simplify compare of Phi with constant 
> inputs against a constant""
>
> This reverts commit 23291b9863c8af7ad348c4a7d85d8d784df88eb1.
>
> This caused performance regressions.
>
> Added:
>
>
> Modified:
> clang/test/CodeGenObjC/exceptions.m
> llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
> llvm/test/Transforms/InstCombine/icmp-constant-phi.ll
> llvm/test/Transforms/InstCombine/indexed-gep-compares.ll
> llvm/test/Transforms/InstCombine/zext-or-icmp.ll
>
> Removed:
>
>
>
> 
> diff  --git a/clang/test/CodeGenObjC/exceptions.m 
> b/clang/test/CodeGenObjC/exceptions.m
> index 3bb4f86cf025..741f8a819158 100644
> --- a/clang/test/CodeGenObjC/exceptions.m
> +++ b/clang/test/CodeGenObjC/exceptions.m
> @@ -97,7 +97,7 @@ void f3() {
>  // CHECK:call void @objc_exception_try_exit(
>  f3_helper(0, );
>} @finally {
> -// CHECK:[[DEST1:%.*]] = phi i1 [ true, {{%.*}} ], [ false, {{%.*}} ]
> +// CHECK:[[DEST1:%.*]] = phi i32 [ 0, {{%.*}} ], [ 3, {{%.*}} ]
>  // CHECK:call void @objc_exception_try_enter
>  // CHECK:call i32 @_setjmp
>  @try {
> @@ -105,7 +105,7 @@ void f3() {
>// CHECK:  call void @objc_exception_try_exit(
>f3_helper(1, );
>  } @finally {
> -  // CHECK:  [[DEST2:%.*]] = phi i1 [ true, {{%.*}} ], [ false, {{%.*}} ]
> +  // CHECK:  [[DEST2:%.*]] = phi i32 [ 0, {{%.*}} ], [ 5, {{%.*}} ]
>// CHECK:  call void @f3_helper(i32 2, i32* nonnull [[X]])
>f3_helper(2, );
>
>
> diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp 
> b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
> index a7b9ecb9bf3b..48375a1a323f 100644
> --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
> +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
> @@ -1452,27 +1452,6 @@ Instruction 
> *InstCombiner::foldICmpWithConstant(ICmpInst ) {
>  if (Instruction *Res = processUGT_ADDCST_ADD(Cmp, A, B, CI2, CI, *this))
>return Res;
>
> -  // icmp(phi(C1, C2, ...), C) -> phi(icmp(C1, C), icmp(C2, C), ...).
> -  Constant *C = dyn_cast(Op1);
> -  if (!C)
> -return nullptr;
> -
> -  if (auto *Phi = dyn_cast(Op0))
> -if (all_of(Phi->operands(), [](Value *V) { return isa(V); })) {
> -  Type *Ty = Cmp.getType();
> -  Builder.SetInsertPoint(Phi);
> -  PHINode *NewPhi =
> -  Builder.CreatePHI(Ty, Phi->getNumOperands());
> -  for (BasicBlock *Predecessor : predecessors(Phi->getParent())) {
> -auto *Input =
> -cast(Phi->getIncomingValueForBlock(Predecessor));
> -auto *BoolInput = ConstantExpr::getCompare(Pred, Input, C);
> -NewPhi->addIncoming(BoolInput, Predecessor);
> -  }
> -  NewPhi->takeName();
> -  return replaceInstUsesWith(Cmp, NewPhi);
> -}
> -
>return nullptr;
>  }
>
>
> diff  --git a/llvm/test/Transforms/InstCombine/icmp-constant-phi.ll 
> b/llvm/test/Transforms/InstCombine/icmp-constant-phi.ll
> index 7d4b9294143f..9753149f8012 100644
> --- a/llvm/test/Transforms/InstCombine/icmp-constant-phi.ll
> +++ b/llvm/test/Transforms/InstCombine/icmp-constant-phi.ll
> @@ -2,6 +2,8 @@
>  ; RUN: opt < %s -instcombine -S | FileCheck %s
>  ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
>
> +; TODO: Replace with boolean Phi.
> +
>  define i1 @test_eq(i1 %cond) {
>  ; CHECK-LABEL: @test_eq(
>  ; CHECK-NEXT:  entry:
> @@ -11,9 +13,10 @@ define i1 @test_eq(i1 %cond) {
>  ; CHECK:   if.false:
>  ; CHECK-NEXT:br label [[MERGE]]
>  ; CHECK:   merge:
> -; CHECK-NEXT:[[COMPARE:%.*]] = phi i1 [ true, [[IF_FALSE]] ], [ false, 
> [[IF_TRUE]] ]
> +; CHECK-NEXT:[[PHI:%.*]] = phi i32 [ 123, [[IF_TRUE]] ], [ 456, 
> [[IF_FALSE]] ]
>  ; CHECK-NEXT:br label [[EXIT:%.*]]
>  ; CHECK:   exit:
> +; CHECK-NEXT:[[COMPARE:%.*]] = icmp eq i32 [[PHI]], 456
>  ; CHECK-NEXT:ret i1 [[COMPARE]]
>  ;
>  entry:
> @@ -43,9 +46,10 @@ define i1 @test_slt(i1 %cond) {
>  ; CHECK:   if.false:
>  ; CHECK-NEXT:br label [[MERGE]]
>  ; CHECK:   merge:
> -; CHECK-NEXT:[[COMPARE:%.*]] = phi i1 [ false, [[IF_FALSE]] ], [ true, 
> [[IF_TRUE]] ]
> +; CHECK-NEXT:[[PHI:%.*]] = phi i32 [ 123, [[IF_TRUE]] ], [ 456, 
> [[IF_FALSE]] ]
>  ; CHECK-NEXT:br label [[EXIT:%.*]]
>  ; CHECK:   exit:
> +; CHECK-NEXT:[[COMPARE:%.*]] = icmp ult i32 [[PHI]], 456
>  ; CHECK-NEXT:ret i1 [[COMPARE]]
>  ;
>  entry:
> @@ -106,9 +110,10 @@ define i1 @test_ne(i1 %cond) {
>  ; CHECK:   

Re: [clang] 6d2b75e - [clang-misexpect] Fixed typo which causes that --pgo-warn-misexpect option is not passed in the compiler invocation

2020-05-19 Thread Roman Lebedev via cfe-commits
This seems to be missing a test

On Wed, May 20, 2020 at 12:12 AM Dávid Bolvanský via cfe-commits
 wrote:
>
>
> Author: Dávid Bolvanský
> Date: 2020-05-19T23:12:08+02:00
> New Revision: 6d2b75e0887ee87e247756c4d51733616bb2f356
>
> URL: 
> https://github.com/llvm/llvm-project/commit/6d2b75e0887ee87e247756c4d51733616bb2f356
> DIFF: 
> https://github.com/llvm/llvm-project/commit/6d2b75e0887ee87e247756c4d51733616bb2f356.diff
>
> LOG: [clang-misexpect] Fixed typo which causes that --pgo-warn-misexpect 
> option is not passed in the compiler invocation
>
> Added:
>
>
> Modified:
> clang/lib/Frontend/CompilerInvocation.cpp
>
> Removed:
>
>
>
> 
> diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
> b/clang/lib/Frontend/CompilerInvocation.cpp
> index 94ba0dd8e598..5496df79dbfb 100644
> --- a/clang/lib/Frontend/CompilerInvocation.cpp
> +++ b/clang/lib/Frontend/CompilerInvocation.cpp
> @@ -3680,7 +3680,7 @@ bool 
> CompilerInvocation::CreateFromArgs(CompilerInvocation ,
>  }
>}
>
> -  if (Diags.isIgnored(diag::warn_profile_data_misexpect, SourceLocation()))
> +  if (!Diags.isIgnored(diag::warn_profile_data_misexpect, SourceLocation()))
>  Res.FrontendOpts.LLVMArgs.push_back("-pgo-warn-misexpect");
>
>LangOpts.FunctionAlignment =
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang-tools-extra] 9e1af17 - [OpenMP][FIX] Add missing cmake dependence needed after 931c0cd713ee

2020-04-06 Thread Roman Lebedev via cfe-commits
On Mon, Apr 6, 2020 at 5:23 PM Johannes Doerfert  wrote:
>
> On 4/6/20 9:06 AM, Roman Lebedev wrote:
>
> This seems suspicious.
>
>
> Agreed, especially since this is also not the only place.
>
> I was hoping to unblock the builders with this.
>
>
> Does clang-reorder-fields actually explicitly needs something from
> FrontendOpenMP?
> If not, it looks like there dependency is missing elsewhere, or
> there's wrong layering.
>
> The root cause is the use of `isAllowedClauseForDirective` in ASTMatchers.h.
What is the target encompases that include?
I'd guess that is the one that is missing this dep.

> On Mon, Apr 6, 2020 at 5:03 PM Johannes Doerfert via cfe-commits
>  wrote:
>
> Author: Johannes Doerfert
> Date: 2020-04-06T09:01:43-05:00
> New Revision: 9e1af172eec9a06bffac337057a2452b88466288
>
> URL: 
> https://github.com/llvm/llvm-project/commit/9e1af172eec9a06bffac337057a2452b88466288
> DIFF: 
> https://github.com/llvm/llvm-project/commit/9e1af172eec9a06bffac337057a2452b88466288.diff
>
> LOG: [OpenMP][FIX] Add missing cmake dependence needed after 931c0cd713ee
>
> Added:
>
>
> Modified:
> clang-tools-extra/clang-reorder-fields/CMakeLists.txt
>
> Removed:
>
>
>
> 
> diff  --git a/clang-tools-extra/clang-reorder-fields/CMakeLists.txt 
> b/clang-tools-extra/clang-reorder-fields/CMakeLists.txt
> index 9c75d785cc9a..c357d0a3cfbf 100644
> --- a/clang-tools-extra/clang-reorder-fields/CMakeLists.txt
> +++ b/clang-tools-extra/clang-reorder-fields/CMakeLists.txt
> @@ -1,4 +1,7 @@
> -set(LLVM_LINK_COMPONENTS support)
> +set(LLVM_LINK_COMPONENTS
> +  FrontendOpenMP
> +  support
> +)
>
>  add_clang_library(clangReorderFields
>ReorderFieldsAction.cpp
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang-tools-extra] 9e1af17 - [OpenMP][FIX] Add missing cmake dependence needed after 931c0cd713ee

2020-04-06 Thread Roman Lebedev via cfe-commits
This seems suspicious.
Does clang-reorder-fields actually explicitly needs something from
FrontendOpenMP?
If not, it looks like there dependency is missing elsewhere, or
there's wrong layering.

On Mon, Apr 6, 2020 at 5:03 PM Johannes Doerfert via cfe-commits
 wrote:
>
>
> Author: Johannes Doerfert
> Date: 2020-04-06T09:01:43-05:00
> New Revision: 9e1af172eec9a06bffac337057a2452b88466288
>
> URL: 
> https://github.com/llvm/llvm-project/commit/9e1af172eec9a06bffac337057a2452b88466288
> DIFF: 
> https://github.com/llvm/llvm-project/commit/9e1af172eec9a06bffac337057a2452b88466288.diff
>
> LOG: [OpenMP][FIX] Add missing cmake dependence needed after 931c0cd713ee
>
> Added:
>
>
> Modified:
> clang-tools-extra/clang-reorder-fields/CMakeLists.txt
>
> Removed:
>
>
>
> 
> diff  --git a/clang-tools-extra/clang-reorder-fields/CMakeLists.txt 
> b/clang-tools-extra/clang-reorder-fields/CMakeLists.txt
> index 9c75d785cc9a..c357d0a3cfbf 100644
> --- a/clang-tools-extra/clang-reorder-fields/CMakeLists.txt
> +++ b/clang-tools-extra/clang-reorder-fields/CMakeLists.txt
> @@ -1,4 +1,7 @@
> -set(LLVM_LINK_COMPONENTS support)
> +set(LLVM_LINK_COMPONENTS
> +  FrontendOpenMP
> +  support
> +)
>
>  add_clang_library(clangReorderFields
>ReorderFieldsAction.cpp
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang-tools-extra] 54928ba - [clang-tidy] Use more widely available headers for protability-restrict-system-includes-check's test

2020-03-11 Thread Roman Lebedev via cfe-commits
On Wed, Mar 11, 2020 at 2:54 AM Paula Toth via cfe-commits
 wrote:
>
>
> Author: Paula Toth
> Date: 2020-03-10T16:54:11-07:00
> New Revision: 54928ba0ec8355edbbdb31c7b01bb45eb2d384b6
>
> URL: 
> https://github.com/llvm/llvm-project/commit/54928ba0ec8355edbbdb31c7b01bb45eb2d384b6
> DIFF: 
> https://github.com/llvm/llvm-project/commit/54928ba0ec8355edbbdb31c7b01bb45eb2d384b6.diff
>
> LOG: [clang-tidy] Use more widely available headers for 
> protability-restrict-system-includes-check's test
>
> Added:
>
>
> Modified:
> 
> clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
> 
> clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
> 
> clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-glob.cpp
>
> Removed:
>
>
>
> 
> diff  --git 
> a/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
>  
> b/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
> index faab977ad340..e3a9376a8638 100644
> --- 
> a/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
> +++ 
> b/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
> @@ -1,9 +1,9 @@
>  // RUN: %check_clang_tidy %s portability-restrict-system-includes %t \
> -// RUN: -- -config="{CheckOptions: [{key: 
> portability-restrict-system-includes.Includes, value: '*,-stdio.h'}]}"
> +// RUN: -- -config="{CheckOptions: [{key: 
> portability-restrict-system-includes.Includes, value: '*,-stddef.h'}]}"
>
> -// Test block-list functionality: allow all but stdio.h.
> +// Test block-list functionality: allow all but stddef.h.
>
> -#include 
> -// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include stdio.h not 
> allowed
> -#include 
> -#include 
> +#include 
> +// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include stddef.h not 
> allowed
> +#include 
> +#include 
In this test, are these actual system headers, or are they mocked?
Tests should not be using system headers.

> diff  --git 
> a/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
>  
> b/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
> index 58c1d4396ee5..f73cbbfc816d 100644
> --- 
> a/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
> +++ 
> b/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
> @@ -1,10 +1,10 @@
>  // RUN: %check_clang_tidy %s portability-restrict-system-includes %t \
> -// RUN: -- -config="{CheckOptions: [{key: 
> portability-restrict-system-includes.Includes, value: '-*,stdio.h'}]}"
> +// RUN: -- -config="{CheckOptions: [{key: 
> portability-restrict-system-includes.Includes, value: '-*,stddef.h'}]}"
>
> -// Test allow-list functionality: disallow all but stdio.h.
> +// Test allow-list functionality: disallow all but stddef.h.
>
> -#include 
> -#include 
> -// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include stdlib.h not 
> allowed
> -#include 
> -// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include string.h not 
> allowed
> +#include 
> +#include 
> +// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include stdint.h not 
> allowed
> +#include 
> +// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include float.h not 
> allowed
>
> diff  --git 
> a/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-glob.cpp
>  
> b/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-glob.cpp
> index ccde9438d93c..bee7ec73438c 100644
> --- 
> a/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-glob.cpp
> +++ 
> b/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-glob.cpp
> @@ -4,7 +4,7 @@
>  // Test glob functionality: disallow all headers except those that match
>  // pattern "std*.h".
>
> -#include 
> -#include 
> -#include 
> -// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include string.h not 
> allowed
> +#include 
> +#include 
> +#include 
> +// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include float.h not 
> allowed
Roman

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


Re: [clang] 4569b3a - Revert "Devirtualize a call on alloca without waiting for post inline cleanup and next"

2020-02-27 Thread Roman Lebedev via cfe-commits
Is there a reproducer in progress?

On Thu, Feb 27, 2020 at 5:59 PM Kirill Bobyrev via cfe-commits
 wrote:
>
>
> Author: Kirill Bobyrev
> Date: 2020-02-27T15:58:39+01:00
> New Revision: 4569b3a86f8a4b1b8ad28fe2321f936f9d7ffd43
>
> URL: 
> https://github.com/llvm/llvm-project/commit/4569b3a86f8a4b1b8ad28fe2321f936f9d7ffd43
> DIFF: 
> https://github.com/llvm/llvm-project/commit/4569b3a86f8a4b1b8ad28fe2321f936f9d7ffd43.diff
>
> LOG: Revert "Devirtualize a call on alloca without waiting for post inline 
> cleanup and next"
>
> This reverts commit 59fb9cde7a4a96fe8485a80d9010e4420ffdca82.
>
> The patch caused internal miscompilations.
>
> Added:
>
>
> Modified:
> clang/test/CodeGenCXX/member-function-pointer-calls.cpp
> llvm/lib/Transforms/IPO/Inliner.cpp
>
> Removed:
> llvm/test/Transforms/Inline/devirtualize-4.ll
>
>
> 
> diff  --git a/clang/test/CodeGenCXX/member-function-pointer-calls.cpp 
> b/clang/test/CodeGenCXX/member-function-pointer-calls.cpp
> index 232b1f06df89..0e98b12e6e9d 100644
> --- a/clang/test/CodeGenCXX/member-function-pointer-calls.cpp
> +++ b/clang/test/CodeGenCXX/member-function-pointer-calls.cpp
> @@ -11,8 +11,12 @@ int f(A* a, int (A::*fp)()) {
>  }
>
>  // CHECK-LABEL: define i32 @_Z2g1v()
> -// CHECK-NOT: }
> -// CHECK: ret i32 1
> +// CHECK-LEGACY: ret i32 1
> +// CHECK-NEWPM: [[A:%.*]] = alloca %struct.A, align 8
> +// CHECK-NEWPM: [[TMP:%.*]] = getelementptr inbounds %struct.A, %struct.A* 
> %a, i64 0, i32 0
> +// CHECK-NEWPM: store i32 (...)** bitcast (i8** getelementptr inbounds ({ [4 
> x i8*] }, { [4 x i8*] }* @_ZTV1A, i64 0, inrange i32 0, i64 2) to i32 
> (...)**), i32 (...)*** [[TMP]], align 8
> +// CHECK-NEWPM: [[RET:%.*]] = call i32 @_ZN1A3vf1Ev(%struct.A* nonnull %a) #2
> +// CHECK-NEWPM: ret i32 [[RET]]
>  // MINGW64-LABEL: define dso_local i32 @_Z2g1v()
>  // MINGW64: call i32 @_Z1fP1AMS_FivE(%struct.A* %{{.*}}, { i64, i64 }* 
> %{{.*}})
>  int g1() {
> @@ -21,7 +25,6 @@ int g1() {
>  }
>
>  // CHECK-LABEL: define i32 @_Z2g2v()
> -// CHECK-NOT: }
>  // CHECK: ret i32 2
>  // MINGW64-LABEL: define dso_local i32 @_Z2g2v()
>  // MINGW64: call i32 @_Z1fP1AMS_FivE(%struct.A* %{{.*}}, { i64, i64 }* 
> %{{.*}})
>
> diff  --git a/llvm/lib/Transforms/IPO/Inliner.cpp 
> b/llvm/lib/Transforms/IPO/Inliner.cpp
> index 55753d979b2c..4f9f4bd1cd04 100644
> --- a/llvm/lib/Transforms/IPO/Inliner.cpp
> +++ b/llvm/lib/Transforms/IPO/Inliner.cpp
> @@ -35,7 +35,6 @@
>  #include "llvm/Analysis/TargetLibraryInfo.h"
>  #include "llvm/Analysis/TargetTransformInfo.h"
>  #include "llvm/Transforms/Utils/Local.h"
> -#include "llvm/Transforms/Utils/CallPromotionUtils.h"
>  #include "llvm/IR/Attributes.h"
>  #include "llvm/IR/BasicBlock.h"
>  #include "llvm/IR/CallSite.h"
> @@ -1101,20 +1100,10 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC 
> ,
>if (!IFI.InlinedCallSites.empty()) {
>  int NewHistoryID = InlineHistory.size();
>  InlineHistory.push_back({, InlineHistoryID});
> -for (CallSite  : reverse(IFI.InlinedCallSites)) {
> -  Function *NewCallee = CS.getCalledFunction();
> -  if (!NewCallee) {
> -// Try to promote an indirect (virtual) call without waiting for 
> the
> -// post-inline cleanup and the next DevirtSCCRepeatedPass 
> iteration
> -// because the next iteration may not happen and we may miss
> -// inlining it.
> -if (tryPromoteCall(CS))
> -  NewCallee = CS.getCalledFunction();
> -  }
> -  if (NewCallee)
> +for (CallSite  : reverse(IFI.InlinedCallSites))
> +  if (Function *NewCallee = CS.getCalledFunction())
>  if (!NewCallee->isDeclaration())
>Calls.push_back({CS, NewHistoryID});
> -}
>}
>
>if (InlinerFunctionImportStats != InlinerFunctionImportStatsOpts::No)
>
> diff  --git a/llvm/test/Transforms/Inline/devirtualize-4.ll 
> b/llvm/test/Transforms/Inline/devirtualize-4.ll
> deleted file mode 100644
> index 2205dae7aa23..
> --- a/llvm/test/Transforms/Inline/devirtualize-4.ll
> +++ /dev/null
> @@ -1,214 +0,0 @@
> -; RUN: opt < %s -passes='cgscc(devirt<4>(inline)),function(sroa,early-cse)' 
> -S | FileCheck %s
> -; RUN: opt < %s -passes='default' -S | FileCheck %s
> -
> -; Check that DoNotOptimize is inlined into Test.
> -; CHECK: @_Z4Testv()
> -; CHECK-NOT: ret void
> -; CHECK: call void asm
> -; CHECK: ret void
> -
> -;template 
> -;void DoNotOptimize(const T& var) {
> -;  asm volatile("" : "+m"(const_cast(var)));
> -;}
> -;
> -;class Interface {
> -; public:
> -;  virtual void Run() = 0;
> -;};
> -;
> -;class Impl : public Interface {
> -; public:
> -;  Impl() : f(3) {}
> -;  void Run() { DoNotOptimize(this); }
> -;
> -; private:
> -;  int f;
> -;};
> -;
> -;static void IndirectRun(Interface& o) { o.Run(); }
> -;
> -;void Test() {
> -;  Impl o;
> -;  IndirectRun(o);
> -;}

[clang] 3dd5a29 - [clang] Annotating C++'s `operator new` with more attributes

2020-02-25 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2020-02-26T01:37:17+03:00
New Revision: 3dd5a298bfff48c0939448c9b4bc987cf6bb5385

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

LOG: [clang] Annotating C++'s `operator new` with more attributes

Summary:
Right now we annotate C++'s `operator new` with `noalias` attribute,
which very much is healthy for optimizations.

However as per [[ http://eel.is/c++draft/basic.stc.dynamic.allocation | 
`[basic.stc.dynamic.allocation]` ]],
there are more promises on global `operator new`, namely:
* non-`std::nothrow_t` `operator new` *never* returns `nullptr`
* If `std::align_val_t align` parameter is taken, the pointer will also be 
`align`-aligned
* ~~global `operator new`-returned pointer is 
`__STDCPP_DEFAULT_NEW_ALIGNMENT__`-aligned ~~ It's more caveated than that.

Supplying this information may not cause immediate landslide effects
on any specific benchmarks, but it for sure will be healthy for optimizer
in the sense that the IR will better reflect the guarantees provided in the 
source code.

The caveat is `-fno-assume-sane-operator-new`, which currently prevents 
emitting `noalias`
attribute, and is automatically passed by Sanitizers ([[ 
https://bugs.llvm.org/show_bug.cgi?id=16386 | PR16386 ]]) - should it also 
cover these attributes?
The problem is that the flag is back-end-specific, as seen in 
`test/Modules/explicit-build-flags.cpp`.
But while it is okay to add `noalias` metadata in backend, we really should be 
adding at least
the alignment metadata to the AST, since that allows us to perform sema checks 
on it.

Reviewers: erichkeane, rjmccall, jdoerfert, eugenis, rsmith

Reviewed By: rsmith

Subscribers: xbolva00, jrtc27, atanasyan, nlopes, cfe-commits

Tags: #llvm, #clang

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

Added: 


Modified: 
clang/include/clang/AST/Decl.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/Decl.cpp
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/test/AST/ast-dump-stmt-json.cpp
clang/test/Analysis/new-ctor-malloc.cpp
clang/test/Analysis/new-ctor-null-throw.cpp
clang/test/Analysis/new-ctor-null.cpp
clang/test/CodeGenCXX/align-avx-complete-objects.cpp
clang/test/CodeGenCXX/arm.cpp
clang/test/CodeGenCXX/builtin-calling-conv.cpp
clang/test/CodeGenCXX/builtin-is-constant-evaluated.cpp
clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp
clang/test/CodeGenCXX/cxx11-initializer-array-new.cpp
clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
clang/test/CodeGenCXX/delete-two-arg.cpp
clang/test/CodeGenCXX/dllexport.cpp
clang/test/CodeGenCXX/dllimport.cpp
clang/test/CodeGenCXX/exceptions.cpp
clang/test/CodeGenCXX/goto.cpp
clang/test/CodeGenCXX/microsoft-abi-array-cookies.cpp
clang/test/CodeGenCXX/mips-size_t-ptrdiff_t.cpp
clang/test/CodeGenCXX/multi-dim-operator-new.cpp
clang/test/CodeGenCXX/new-alias.cpp
clang/test/CodeGenCXX/new-array-init.cpp
clang/test/CodeGenCXX/new-overflow.cpp
clang/test/CodeGenCXX/new.cpp
clang/test/CodeGenCXX/operator-new.cpp
clang/test/CodeGenCXX/runtime-dllstorage.cpp
clang/test/CodeGenCXX/static-init.cpp
clang/test/CodeGenCoroutines/coro-alloc.cpp
clang/test/CodeGenCoroutines/coro-cleanup.cpp
clang/test/CodeGenCoroutines/coro-gro-nrvo.cpp
clang/test/CodeGenCoroutines/coro-gro.cpp
clang/test/CodeGenCoroutines/coro-return.cpp
clang/test/CodeGenObjCXX/arc-new-delete.mm
clang/test/CodeGenObjCXX/copy.mm
clang/test/SemaCXX/builtin-operator-new-delete.cpp
clang/test/SemaCXX/new-delete.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 43c6c7b85db4..b31cbab50222 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -2306,8 +2306,13 @@ class FunctionDecl : public DeclaratorDecl,
   ///allocation function. [...]
   ///
   /// If this function is an aligned allocation/deallocation function, return
-  /// true through IsAligned.
-  bool isReplaceableGlobalAllocationFunction(bool *IsAligned = nullptr) const;
+  /// the parameter number of the requested alignment through AlignmentParam.
+  ///
+  /// If this function is an allocation/deallocation function that takes
+  /// the `std::nothrow_t` tag, return true through IsNothrow,
+  bool isReplaceableGlobalAllocationFunction(
+  Optional *AlignmentParam = nullptr,
+  bool *IsNothrow = nullptr) const;
 
   /// Determine if this function provides an inline implementation of a 
builtin.
   bool isInlineBuiltinDeclaration() const;

diff  --git 

[clang] b8fdafe - [Sema] Perform call checking when building CXXNewExpr

2020-02-25 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2020-02-26T01:36:44+03:00
New Revision: b8fdafe68ce25b7ff4d31720548622e28db87ebf

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

LOG: [Sema] Perform call checking when building CXXNewExpr

Summary:
There was even a TODO for this.
The main motivation is to make use of call-site based
`__attribute__((alloc_align(param_idx)))` validation (D72996).

Reviewers: rsmith, erichkeane, aaron.ballman, jdoerfert

Reviewed By: rsmith

Subscribers: cfe-commits

Tags: #clang

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

Added: 
clang/test/SemaCXX/operator-new-size-diagnose_if.cpp

Modified: 
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/test/SemaCXX/diagnose_if.cpp
clang/test/SemaCXX/std-align-val-t-in-operator-new.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 7aa115fb03c1..2a66303d6d9a 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3901,8 +3901,9 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
 auto *AA = FDecl->getAttr();
 const Expr *Arg = Args[AA->getParamIndex().getASTIndex()];
 if (!Arg->isValueDependent()) {
-  llvm::APSInt I(64);
-  if (Arg->isIntegerConstantExpr(I, Context)) {
+  Expr::EvalResult Align;
+  if (Arg->EvaluateAsInt(Align, Context)) {
+const llvm::APSInt  = Align.Val.getInt();
 if (!I.isPowerOf2())
   Diag(Arg->getExprLoc(), diag::warn_alignment_not_power_of_two)
   << Arg->getSourceRange();

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 800454555425..9e5c7354a5eb 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -2116,18 +2116,80 @@ Sema::BuildCXXNew(SourceRange Range, bool UseGlobal,
 // arguments. Skip the first parameter because we don't have a 
corresponding
 // argument. Skip the second parameter too if we're passing in the
 // alignment; we've already filled it in.
+unsigned NumImplicitArgs = PassAlignment ? 2 : 1;
 if (GatherArgumentsForCall(PlacementLParen, OperatorNew, Proto,
-   PassAlignment ? 2 : 1, PlacementArgs,
-   AllPlaceArgs, CallType))
+   NumImplicitArgs, PlacementArgs, AllPlaceArgs,
+   CallType))
   return ExprError();
 
 if (!AllPlaceArgs.empty())
   PlacementArgs = AllPlaceArgs;
 
-// FIXME: This is wrong: PlacementArgs misses out the first (size) 
argument.
-DiagnoseSentinelCalls(OperatorNew, PlacementLParen, PlacementArgs);
-
-// FIXME: Missing call to CheckFunctionCall or equivalent
+// We would like to perform some checking on the given `operator new` call,
+// but the PlacementArgs does not contain the implicit arguments,
+// namely allocation size and maybe allocation alignment,
+// so we need to conjure them.
+
+QualType SizeTy = Context.getSizeType();
+unsigned SizeTyWidth = Context.getTypeSize(SizeTy);
+
+llvm::APInt SingleEltSize(
+SizeTyWidth, Context.getTypeSizeInChars(AllocType).getQuantity());
+
+// How many bytes do we want to allocate here?
+llvm::Optional AllocationSize;
+if (!ArraySize.hasValue() && !AllocType->isDependentType()) {
+  // For non-array operator new, we only want to allocate one element.
+  AllocationSize = SingleEltSize;
+} else if (KnownArraySize.hasValue() && !AllocType->isDependentType()) {
+  // For array operator new, only deal with static array size case.
+  bool Overflow;
+  AllocationSize = llvm::APInt(SizeTyWidth, *KnownArraySize)
+   .umul_ov(SingleEltSize, Overflow);
+  (void)Overflow;
+  assert(
+  !Overflow &&
+  "Expected that all the overflows would have been handled already.");
+}
+
+IntegerLiteral AllocationSizeLiteral(
+Context,
+AllocationSize.getValueOr(llvm::APInt::getNullValue(SizeTyWidth)),
+SizeTy, SourceLocation());
+// Otherwise, if we failed to constant-fold the allocation size, we'll
+// just give up and pass-in something opaque, that isn't a null pointer.
+OpaqueValueExpr OpaqueAllocationSize(SourceLocation(), SizeTy, VK_RValue,
+ OK_Ordinary, /*SourceExpr=*/nullptr);
+
+// Let's synthesize the alignment argument in case we will need it.
+// Since we *really* want to allocate these on stack, this is slightly ugly
+// because there might not be a `std::align_val_t` type.
+EnumDecl *StdAlignValT = getStdAlignValT();
+QualType AlignValT =
+StdAlignValT ? 

[clang] 9ea5d17 - [Sema] Demote call-site-based 'alignment is a power of two' check for AllocAlignAttr into a warning

2020-02-20 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2020-02-20T16:39:26+03:00
New Revision: 9ea5d17cc9544838c73e593de4ef224d54fa1cff

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

LOG: [Sema] Demote call-site-based 'alignment is a power of two' check for 
AllocAlignAttr into a warning

Summary:
As @rsmith notes in https://reviews.llvm.org/D73020#inline-672219
while that is certainly UB land, it may not be actually reachable at runtime, 
e.g.:
```
template void *make() {
  if ((N & (N-1)) == 0)
return operator new(N, std::align_val_t(N));
  else
return operator new(N);
}
void *p = make<7>();
```
and we shouldn't really error-out there.

That being said, i'm not really following the logic here.
Which ones of these cases should remain being an error?

Reviewers: rsmith, erichkeane

Reviewed By: erichkeane

Subscribers: cfe-commits, rsmith

Tags: #clang

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

Added: 
clang/test/CodeGen/non-power-of-2-alignment-assumptions.c

Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/CodeGen/CGCall.cpp
clang/lib/Sema/SemaChecking.cpp
clang/test/Sema/alloc-align-attr.c
clang/test/SemaCXX/alloc-align-attr.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1d1c8df6161d..60f2c777676d 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3033,6 +3033,9 @@ def err_alignment_too_big : Error<
   "requested alignment must be %0 or smaller">;
 def err_alignment_not_power_of_two : Error<
   "requested alignment is not a power of 2">;
+def warn_alignment_not_power_of_two : Warning<
+  err_alignment_not_power_of_two.Text>,
+  InGroup>;
 def err_alignment_dependent_typedef_name : Error<
   "requested alignment is dependent but declaration is not dependent">;
 

diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 6cc01540febe..98365dbc223f 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -3892,6 +3892,10 @@ template  class 
AbstractAssumeAlignedAttrEmitter {
 const auto *AlignmentCI = dyn_cast(Alignment);
 if (!AlignmentCI)
   return Attrs;
+// We may legitimately have non-power-of-2 alignment here.
+// If so, this is UB land, emit it via `@llvm.assume` instead.
+if (!AlignmentCI->getValue().isPowerOf2())
+  return Attrs;
 llvm::AttributeList NewAttrs = maybeRaiseRetAlignmentAttribute(
 CGF.getLLVMContext(), Attrs,
 llvm::Align(

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index eca82c559e06..a986ef2bb685 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3898,11 +3898,9 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
 if (!Arg->isValueDependent()) {
   llvm::APSInt I(64);
   if (Arg->isIntegerConstantExpr(I, Context)) {
-if (!I.isPowerOf2()) {
-  Diag(Arg->getExprLoc(), diag::err_alignment_not_power_of_two)
+if (!I.isPowerOf2())
+  Diag(Arg->getExprLoc(), diag::warn_alignment_not_power_of_two)
   << Arg->getSourceRange();
-  return;
-}
 
 if (I > Sema::MaximumAlignment)
   Diag(Arg->getExprLoc(), diag::warn_assume_aligned_too_great)

diff  --git a/clang/test/CodeGen/non-power-of-2-alignment-assumptions.c 
b/clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
new file mode 100644
index ..9467f6228dfc
--- /dev/null
+++ b/clang/test/CodeGen/non-power-of-2-alignment-assumptions.c
@@ -0,0 +1,46 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - | 
FileCheck %s
+
+void *__attribute__((alloc_align(1))) alloc(int align);
+
+// CHECK-LABEL: @t0(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[ALIGN_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:store i32 [[ALIGN:%.*]], i32* [[ALIGN_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load i32, i32* [[ALIGN_ADDR]], align 4
+// CHECK-NEXT:[[CALL:%.*]] = call i8* @alloc(i32 [[TMP0]])
+// CHECK-NEXT:[[ALIGNMENTCAST:%.*]] = zext i32 [[TMP0]] to i64
+// CHECK-NEXT:[[MASK:%.*]] = sub i64 [[ALIGNMENTCAST]], 1
+// CHECK-NEXT:[[PTRINT:%.*]] = ptrtoint i8* [[CALL]] to i64
+// CHECK-NEXT:[[MASKEDPTR:%.*]] = and i64 [[PTRINT]], [[MASK]]
+// CHECK-NEXT:[[MASKCOND:%.*]] = icmp eq i64 [[MASKEDPTR]], 0
+// CHECK-NEXT:call void @llvm.assume(i1 [[MASKCOND]])
+// CHECK-NEXT:ret void
+//
+void t0(int align) {
+  alloc(align);
+}
+// CHECK-LABEL: @t1(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[ALIGN_ADDR:%.*]] = alloca 

[clang] c8f9e52 - [clang-tidy] misc-no-recursion: point to the function defs, not decls

2020-02-20 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2020-02-20T14:17:30+03:00
New Revision: c8f9e526bc5319f2d0beed4012fbf17b11e15161

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

LOG: [clang-tidy] misc-no-recursion: point to the function defs, not decls

Results in slightly better UX.
This actually was the initial intent, but it kinda got lost along the way.

Added: 


Modified: 
clang-tools-extra/clang-tidy/misc/NoRecursionCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
clang/include/clang/Analysis/CallGraph.h

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/NoRecursionCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/NoRecursionCheck.cpp
index cfbd6543e086..d382501d191e 100644
--- a/clang-tools-extra/clang-tidy/misc/NoRecursionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/NoRecursionCheck.cpp
@@ -204,9 +204,8 @@ void NoRecursionCheck::handleSCC(ArrayRef 
SCC) {
 
   // First of all, call out every stongly connected function.
   for (CallGraphNode *N : SCC) {
-Decl *D = N->getDecl();
-diag(D->getLocation(), "function %0 is within a recursive call chain")
-<< cast(D);
+FunctionDecl *D = N->getDefinition();
+diag(D->getLocation(), "function %0 is within a recursive call chain") << 
D;
   }
 
   // Now, SCC only tells us about strongly connected function declarations in
@@ -228,13 +227,13 @@ void NoRecursionCheck::handleSCC(ArrayRef SCC) {
   assert(CyclicCallStack.size() >= 2 && "Cycle requires at least 2 frames");
 
   // Which function we decided to be the entry point that lead to the 
recursion?
-  Decl *CycleEntryFn = CyclicCallStack.front().Callee->getDecl();
+  FunctionDecl *CycleEntryFn = CyclicCallStack.front().Callee->getDefinition();
   // And now, for ease of understanding, let's print the call sequence that
   // forms the cycle in question.
   diag(CycleEntryFn->getLocation(),
"example recursive call chain, starting from function %0",
DiagnosticIDs::Note)
-  << cast(CycleEntryFn);
+  << CycleEntryFn;
   for (int CurFrame = 1, NumFrames = CyclicCallStack.size();
CurFrame != NumFrames; ++CurFrame) {
 CallGraphNode::CallRecord PrevNode = CyclicCallStack[CurFrame - 1];

diff  --git a/clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
index 0cfacfe80cbe..e323c8a36a2b 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
@@ -60,12 +60,12 @@ void indirect_recursion() {
 conditionally_executed();
 }
 
+// CHECK-NOTES: :[[@LINE-9]]:6: warning: function 'conditionally_executed' is 
within a recursive call chain [misc-no-recursion]
+// CHECK-NOTES: :[[@LINE-6]]:6: note: example recursive call chain, starting 
from function 'indirect_recursion'
+// CHECK-NOTES: :[[@LINE-5]]:5: note: Frame #1: function 'indirect_recursion' 
calls function 'conditionally_executed' here:
+// CHECK-NOTES: :[[@LINE-10]]:5: note: Frame #2: function 
'conditionally_executed' calls function 'indirect_recursion' here:
+// CHECK-NOTES: :[[@LINE-11]]:5: note: ... which was the starting point of the 
recursive call chain; there may be other cycles
 // CHECK-NOTES: :[[@LINE-10]]:6: warning: function 'indirect_recursion' is 
within a recursive call chain [misc-no-recursion]
-// CHECK-NOTES: :[[@LINE-10]]:6: warning: function 'conditionally_executed' is 
within a recursive call chain [misc-no-recursion]
-// CHECK-NOTES: :[[@LINE-12]]:6: note: example recursive call chain, starting 
from function 'indirect_recursion'
-// CHECK-NOTES: :[[@LINE-6]]:5: note: Frame #1: function 'indirect_recursion' 
calls function 'conditionally_executed' here:
-// CHECK-NOTES: :[[@LINE-11]]:5: note: Frame #2: function 
'conditionally_executed' calls function 'indirect_recursion' here:
-// CHECK-NOTES: :[[@LINE-12]]:5: note: ... which was the starting point of the 
recursive call chain; there may be other cycles
 
 void taint();
 void maybe_selfrecursion_with_two_backedges() {
@@ -97,13 +97,13 @@ void indirect_recursion_with_alternatives() {
 conditionally_executed_choice_1();
 }
 
-// CHECK-NOTES: :[[@LINE-16]]:6: warning: function 
'indirect_recursion_with_alternatives' is within a recursive call chain 
[misc-no-recursion]
-// CHECK-NOTES: :[[@LINE-16]]:6: warning: function 
'conditionally_executed_choice_0' is within a recursive call chain 
[misc-no-recursion]
-// CHECK-NOTES: :[[@LINE-18]]:6: note: example recursive call chain, starting 
from function 'indirect_recursion_with_alternatives'
-// CHECK-NOTES: :[[@LINE-8]]:5: note: Frame #1: function 
'indirect_recursion_with_alternatives' calls function 
'conditionally_executed_choice_0' here:
-// 

[clang-tools-extra] b7d6640 - [NFC][clang-tidy] Move recently newly-added tests into checkers/ subdir

2020-02-14 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2020-02-14T11:25:05+03:00
New Revision: b7d6640ba9812ec74a0f86ae7bc9850332f5fd2b

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

LOG: [NFC][clang-tidy] Move recently newly-added tests into checkers/ subdir

That's where nowadays those tests reside, those outliers were created
before the migration but committed after,
so they just awkwardly reside in the old place.

Added: 

clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-not-null-terminated-result/not-null-terminated-result-c.h

clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-not-null-terminated-result/not-null-terminated-result-cxx.h

clang-tools-extra/test/clang-tidy/checkers/bugprone-bad-signal-to-kill-thread.cpp

clang-tools-extra/test/clang-tidy/checkers/bugprone-not-null-terminated-result-in-initialization-strlen.c

clang-tools-extra/test/clang-tidy/checkers/bugprone-not-null-terminated-result-memcpy-before-safe.c

clang-tools-extra/test/clang-tidy/checkers/bugprone-not-null-terminated-result-memcpy-safe-cxx.cpp

clang-tools-extra/test/clang-tidy/checkers/bugprone-not-null-terminated-result-memcpy-safe-other.c

clang-tools-extra/test/clang-tidy/checkers/bugprone-not-null-terminated-result-memcpy-safe.c

clang-tools-extra/test/clang-tidy/checkers/bugprone-not-null-terminated-result-strlen.c

clang-tools-extra/test/clang-tidy/checkers/bugprone-not-null-terminated-result-wcslen.cpp

clang-tools-extra/test/clang-tidy/checkers/bugprone-not-null-terminated-result-wmemcpy-safe-cxx.cpp

clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-semicolon-constexpr.cpp

clang-tools-extra/test/clang-tidy/checkers/readability-magic-numbers-userliteral.cpp

clang-tools-extra/test/clang-tidy/checkers/readability-make-member-function-const.cpp

clang-tools-extra/test/clang-tidy/checkers/readability-redundant-access-specifiers-check-first-declaration.cpp

clang-tools-extra/test/clang-tidy/checkers/readability-redundant-access-specifiers.cpp

Modified: 


Removed: 

clang-tools-extra/test/clang-tidy/Inputs/bugprone-not-null-terminated-result/not-null-terminated-result-c.h

clang-tools-extra/test/clang-tidy/Inputs/bugprone-not-null-terminated-result/not-null-terminated-result-cxx.h
clang-tools-extra/test/clang-tidy/bugprone-bad-signal-to-kill-thread.cpp

clang-tools-extra/test/clang-tidy/bugprone-not-null-terminated-result-in-initialization-strlen.c

clang-tools-extra/test/clang-tidy/bugprone-not-null-terminated-result-memcpy-before-safe.c

clang-tools-extra/test/clang-tidy/bugprone-not-null-terminated-result-memcpy-safe-cxx.cpp

clang-tools-extra/test/clang-tidy/bugprone-not-null-terminated-result-memcpy-safe-other.c

clang-tools-extra/test/clang-tidy/bugprone-not-null-terminated-result-memcpy-safe.c

clang-tools-extra/test/clang-tidy/bugprone-not-null-terminated-result-strlen.c

clang-tools-extra/test/clang-tidy/bugprone-not-null-terminated-result-wcslen.cpp

clang-tools-extra/test/clang-tidy/bugprone-not-null-terminated-result-wmemcpy-safe-cxx.cpp

clang-tools-extra/test/clang-tidy/bugprone-suspicious-semicolon-constexpr.cpp
clang-tools-extra/test/clang-tidy/readability-magic-numbers-userliteral.cpp
clang-tools-extra/test/clang-tidy/readability-make-member-function-const.cpp

clang-tools-extra/test/clang-tidy/readability-redundant-access-specifiers-check-first-declaration.cpp

clang-tools-extra/test/clang-tidy/readability-redundant-access-specifiers.cpp



diff  --git 
a/clang-tools-extra/test/clang-tidy/Inputs/bugprone-not-null-terminated-result/not-null-terminated-result-c.h
 
b/clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-not-null-terminated-result/not-null-terminated-result-c.h
similarity index 100%
rename from 
clang-tools-extra/test/clang-tidy/Inputs/bugprone-not-null-terminated-result/not-null-terminated-result-c.h
rename to 
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-not-null-terminated-result/not-null-terminated-result-c.h

diff  --git 
a/clang-tools-extra/test/clang-tidy/Inputs/bugprone-not-null-terminated-result/not-null-terminated-result-cxx.h
 
b/clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-not-null-terminated-result/not-null-terminated-result-cxx.h
similarity index 100%
rename from 
clang-tools-extra/test/clang-tidy/Inputs/bugprone-not-null-terminated-result/not-null-terminated-result-cxx.h
rename to 
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-not-null-terminated-result/not-null-terminated-result-cxx.h

diff  --git 
a/clang-tools-extra/test/clang-tidy/bugprone-bad-signal-to-kill-thread.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone-bad-signal-to-kill-thread.cpp
similarity index 

[clang-tools-extra] 49bffa5 - [clang-tidy] misc-no-recursion: a new check

2020-02-13 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2020-02-13T23:37:53+03:00
New Revision: 49bffa5f8b790b6f180897b2a03840def645d8f0

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

LOG: [clang-tidy] misc-no-recursion: a new check

Summary:
Recursion is a powerful tool, but like any tool
without care it can be dangerous. For example,
if the recursion is unbounded, you will
eventually run out of stack and crash.

You can of course track the recursion depth
but if it is hardcoded, there can always be some
other environment when that depth is too large,
so said magic number would need to be env-dependent.
But then your program's behavior is suddenly more env-dependent.

Also, recursion, while it does not outright stop optimization,
recursive calls are less great than normal calls,
for example they hinder inlining.

Recursion is banned in some coding guidelines:
* SEI CERT DCL56-CPP. Avoid cycles during initialization of static objects
* JPL 2.4 Do not use direct or indirect recursion.
* I'd say it is frowned upon in LLVM, although not banned
And is plain unsupported in some cases:
* OpenCL 1.2, 6.9 Restrictions: i. Recursion is not supported.

So there's clearly a lot of reasons why one might want to
avoid recursion, and replace it with worklist handling.
It would be great to have a enforcement for it though.

This implements such a check.
Here we detect both direct and indirect recursive calls,
although since clang-tidy (unlike clang static analyzer)
is CTU-unaware, if the recursion transcends a single standalone TU,
we will naturally not find it :/

The algorithm is pretty straight-forward:
1. Build call-graph for the entire TU.
   For that, the existing `clang::CallGraph` is re-used,
   although it had to be modified to also track the location of the call.
2. Then, the hard problem: how do we detect recursion?
   Since we have a graph, let's just do the sane thing,
   and look for Strongly Connected Function Declarations - widely known as 
`SCC`.
   For that LLVM provides `llvm::scc_iterator`,
   which is internally an Tarjan's DFS algorithm, and is used throught LLVM,
   so this should be as performant as possible.
3. Now that we've got SCC's, we discard those that don't contain loops.
   Note that there may be more than one loop in SCC!
4. For each loopy SCC, we call out each function, and print a single example
   call graph that shows recursion -- it didn't seem worthwhile enumerating
   every possible loop in SCC, although i suppose it could be implemented.
   * To come up with that call graph cycle example, we start at first SCC node,
 see which callee of the node is within SCC (and is thus known to be in 
cycle),
 and recurse into it until we hit the callee that is already in call stack.

Reviewers: JonasToth, aaron.ballman, ffrankies, Eugene.Zelenko, erichkeane, NoQ

Reviewed By: aaron.ballman

Subscribers: Charusso, Naghasan, bader, riccibruno, mgorny, Anastasia, 
xazax.hun, cfe-commits

Tags: #llvm, #clang

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

Added: 
clang-tools-extra/clang-tidy/misc/NoRecursionCheck.cpp
clang-tools-extra/clang-tidy/misc/NoRecursionCheck.h
clang-tools-extra/docs/clang-tidy/checks/misc-no-recursion.rst
clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp

Modified: 
clang-tools-extra/clang-tidy/misc/CMakeLists.txt
clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
index 3fc152148d6d..7aa14d141fb1 100644
--- a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
@@ -5,6 +5,7 @@ add_clang_library(clangTidyMiscModule
   MiscTidyModule.cpp
   MisplacedConstCheck.cpp
   NewDeleteOverloadsCheck.cpp
+  NoRecursionCheck.cpp
   NonCopyableObjects.cpp
   NonPrivateMemberVariablesInClassesCheck.cpp
   RedundantExpressionCheck.cpp

diff  --git a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp 
b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
index ba160d1dba38..e06768c548bd 100644
--- a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
@@ -12,6 +12,7 @@
 #include "DefinitionsInHeadersCheck.h"
 #include "MisplacedConstCheck.h"
 #include "NewDeleteOverloadsCheck.h"
+#include "NoRecursionCheck.h"
 #include "NonCopyableObjects.h"
 #include "NonPrivateMemberVariablesInClassesCheck.h"
 #include "RedundantExpressionCheck.h"
@@ -35,6 +36,7 @@ class MiscModule : public ClangTidyModule {
 CheckFactories.registerCheck("misc-misplaced-const");
 CheckFactories.registerCheck(
 

[clang] d68c7b8 - [clang][Analysis] CallGraph: store the actual call `Expr*` in the CallGraphNode::CallRecord

2020-02-13 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2020-02-13T23:37:53+03:00
New Revision: d68c7b8e3e4d605912ed36a843bbbcaa36234461

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

LOG: [clang][Analysis] CallGraph: store the actual call `Expr*` in the 
CallGraphNode::CallRecord

Summary:
Storing not just the callee, but the actual call may be interesting for some 
use-cases.
In particular, D72362 would like that to better pretty-print the cycles in call 
graph.

Reviewers: NoQ, erichkeane

Reviewed By: NoQ

Subscribers: martong, Charusso, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clang-move/HelperDeclRefGraph.cpp
clang/include/clang/Analysis/CallGraph.h
clang/lib/Analysis/CallGraph.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-move/HelperDeclRefGraph.cpp 
b/clang-tools-extra/clang-move/HelperDeclRefGraph.cpp
index 5495ae044584..271bd3d6ef20 100644
--- a/clang-tools-extra/clang-move/HelperDeclRefGraph.cpp
+++ b/clang-tools-extra/clang-move/HelperDeclRefGraph.cpp
@@ -27,7 +27,7 @@ void HelperDeclRefGraph::print(raw_ostream ) const {
 OS << " (" << N << ") ";
 OS << " calls: ";
 for (auto CI = N->begin(), CE = N->end(); CI != CE; ++CI) {
-  (*CI)->print(OS);
+  CI->Callee->print(OS);
   OS << " (" << CI << ") ";
 }
 OS << '\n';
@@ -48,7 +48,7 @@ void HelperDeclRefGraph::addEdge(const Decl *Caller, const 
Decl *Callee) {
   // Allocate a new node, mark it as root, and process it's calls.
   CallGraphNode *CallerNode = getOrInsertNode(const_cast(Caller));
   CallGraphNode *CalleeNode = getOrInsertNode(const_cast(Callee));
-  CallerNode->addCallee(CalleeNode);
+  CallerNode->addCallee({CalleeNode, /*CallExpr=*/nullptr});
 }
 
 void HelperDeclRefGraph::dump() const { print(llvm::errs()); }

diff  --git a/clang/include/clang/Analysis/CallGraph.h 
b/clang/include/clang/Analysis/CallGraph.h
index dae2b58ffc10..0e56d1c00623 100644
--- a/clang/include/clang/Analysis/CallGraph.h
+++ b/clang/include/clang/Analysis/CallGraph.h
@@ -24,6 +24,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/iterator_range.h"
 #include 
 
 namespace clang {
@@ -136,14 +137,23 @@ class CallGraph : public RecursiveASTVisitor {
 private:
   /// Add the given declaration to the call graph.
   void addNodeForDecl(Decl *D, bool IsGlobal);
-
-  /// Allocate a new node in the graph.
-  CallGraphNode *allocateNewNode(Decl *);
 };
 
 class CallGraphNode {
 public:
-  using CallRecord = CallGraphNode *;
+  struct CallRecord {
+CallGraphNode *Callee;
+Expr *CallExpr;
+
+CallRecord() = default;
+
+CallRecord(CallGraphNode *Callee_, Expr *CallExpr_)
+: Callee(Callee_), CallExpr(CallExpr_) {}
+
+// The call destination is the only important data here,
+// allow to transparently unwrap into it.
+operator CallGraphNode *() const { return Callee; }
+  };
 
 private:
   /// The function/method declaration.
@@ -164,12 +174,18 @@ class CallGraphNode {
   const_iterator begin() const { return CalledFunctions.begin(); }
   const_iterator end() const { return CalledFunctions.end(); }
 
+  /// Iterator access to callees/children of the node.
+  llvm::iterator_range callees() {
+return llvm::make_range(begin(), end());
+  }
+  llvm::iterator_range callees() const {
+return llvm::make_range(begin(), end());
+  }
+
   bool empty() const { return CalledFunctions.empty(); }
   unsigned size() const { return CalledFunctions.size(); }
 
-  void addCallee(CallGraphNode *N) {
-CalledFunctions.push_back(N);
-  }
+  void addCallee(CallRecord Call) { CalledFunctions.push_back(Call); }
 
   Decl *getDecl() const { return FD; }
 
@@ -177,11 +193,44 @@ class CallGraphNode {
   void dump() const;
 };
 
+// NOTE: we are comparing based on the callee only. So 
diff erent call records
+// (with 
diff erent call expressions) to the same callee will compare equal!
+inline bool operator==(const CallGraphNode::CallRecord ,
+   const CallGraphNode::CallRecord ) {
+  return LHS.Callee == RHS.Callee;
+}
+
 } // namespace clang
 
-// Graph traits for iteration, viewing.
 namespace llvm {
 
+// Specialize DenseMapInfo for clang::CallGraphNode::CallRecord.
+template <> struct DenseMapInfo {
+  static inline clang::CallGraphNode::CallRecord getEmptyKey() {
+return clang::CallGraphNode::CallRecord(
+DenseMapInfo::getEmptyKey(),
+DenseMapInfo::getEmptyKey());
+  }
+
+  static inline clang::CallGraphNode::CallRecord getTombstoneKey() {
+return clang::CallGraphNode::CallRecord(
+DenseMapInfo::getTombstoneKey(),
+DenseMapInfo::getTombstoneKey());
+  }
+
+  static unsigned 

[clang] a8c3608 - [Sema] Provide declarations for MaximumAlignment, MaxAlignmentExponent variables

2020-01-24 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2020-01-24T18:18:15+03:00
New Revision: a8c3608a27a82cf1c66f33b96a06423fe0e708fc

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

LOG: [Sema] Provide declarations for MaximumAlignment, MaxAlignmentExponent 
variables

clang-armv7-linux-build-cache bot is complaining about undefined
references to these variables during linking, so by explicitly
placing them in some TU we should be able to fix that.

Added: 


Modified: 
clang/lib/Sema/Sema.cpp

Removed: 




diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 9cfce5a63b1d..e24db7190496 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -142,6 +142,9 @@ class SemaPPCallbacks : public PPCallbacks {
 } // end namespace sema
 } // end namespace clang
 
+const unsigned Sema::MaxAlignmentExponent;
+const unsigned Sema::MaximumAlignment;
+
 Sema::Sema(Preprocessor , ASTContext , ASTConsumer ,
TranslationUnitKind TUKind, CodeCompleteConsumer *CodeCompleter)
 : ExternalSource(nullptr), isMultiplexExternalSource(false),



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


[clang] 1d0972f - [Sema] Introduce MaximumAlignment value, to be used instead of magical constants

2020-01-24 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2020-01-24T17:49:17+03:00
New Revision: 1d0972ff5eab544579c400ee674d5c9c60391ee1

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

LOG: [Sema] Introduce MaximumAlignment value, to be used instead of magical 
constants

There is llvm::Value::MaximumAlignment, which is numerically
equivalent to these constants, but we can't use it directly
because we can't include llvm IR headers in clang Sema.
So instead, copy-paste the constant, and fixup the places to use it.

This was initially reviewed in https://reviews.llvm.org/D72998

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/CXX/drs/dr6xx.cpp
clang/test/Sema/attr-aligned.c

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index fae1ade80ca9..92d964d6603d 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -372,6 +372,15 @@ class Sema final {
   QualType ResultTy,
   ArrayRef Args);
 
+  /// The maximum alignment, same as in llvm::Value. We duplicate them here
+  /// because that allows us not to duplicate the constants in clang code,
+  /// which we must to since we can't directly use the llvm constants.
+  ///
+  /// This is the greatest alignment value supported by load, store, and alloca
+  /// instructions, and global values.
+  static const unsigned MaxAlignmentExponent = 29;
+  static const unsigned MaximumAlignment = 1u << MaxAlignmentExponent;
+
 public:
   typedef OpaquePtr DeclGroupPtrTy;
   typedef OpaquePtr TemplateTy;

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 4485539f3f1c..186f2b5b990c 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3665,11 +3665,9 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
   return;
 }
 
-// Alignment calculations can wrap around if it's greater than 2**29.
-unsigned MaximumAlignment = 536870912;
-if (I > MaximumAlignment)
+if (I > Sema::MaximumAlignment)
   Diag(Arg->getExprLoc(), diag::warn_assume_aligned_too_great)
-  << Arg->getSourceRange() << MaximumAlignment;
+  << Arg->getSourceRange() << Sema::MaximumAlignment;
   }
 }
   }
@@ -5394,11 +5392,9 @@ bool Sema::SemaBuiltinAssumeAligned(CallExpr *TheCall) {
   return Diag(TheCall->getBeginLoc(), diag::err_alignment_not_power_of_two)
  << Arg->getSourceRange();
 
-// Alignment calculations can wrap around if it's greater than 2**29.
-unsigned MaximumAlignment = 536870912;
-if (Result > MaximumAlignment)
+if (Result > Sema::MaximumAlignment)
   Diag(TheCall->getBeginLoc(), diag::warn_assume_aligned_too_great)
-  << Arg->getSourceRange() << MaximumAlignment;
+  << Arg->getSourceRange() << Sema::MaximumAlignment;
   }
 
   if (NumArgs > 2) {

diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 8ad981f89b6e..e097ec0f1c59 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -1626,11 +1626,9 @@ void Sema::AddAssumeAlignedAttr(Decl *D, const 
AttributeCommonInfo , Expr *E,
   return;
 }
 
-// Alignment calculations can wrap around if it's greater than 2**29.
-unsigned MaximumAlignment = 536870912;
-if (I > MaximumAlignment)
+if (I > Sema::MaximumAlignment)
   Diag(CI.getLoc(), diag::warn_assume_aligned_too_great)
-  << CI.getRange() << MaximumAlignment;
+  << CI.getRange() << Sema::MaximumAlignment;
   }
 
   if (OE) {
@@ -3816,13 +3814,12 @@ void Sema::AddAlignedAttr(Decl *D, const 
AttributeCommonInfo , Expr *E,
 }
   }
 
-  // Alignment calculations can wrap around if it's greater than 2**28.
-  unsigned MaxValidAlignment =
-  Context.getTargetInfo().getTriple().isOSBinFormatCOFF() ? 8192
-  : 268435456;
-  if (AlignVal > MaxValidAlignment) {
+  unsigned MaximumAlignment = Sema::MaximumAlignment;
+  if (Context.getTargetInfo().getTriple().isOSBinFormatCOFF())
+MaximumAlignment = std::min(MaximumAlignment, 8192u);
+  if (AlignVal > MaximumAlignment) {
 Diag(AttrLoc, diag::err_attribute_aligned_too_great)
-<< MaxValidAlignment << E->getSourceRange();
+<< MaximumAlignment << E->getSourceRange();
 return;
   }
 

diff  --git a/clang/test/CXX/drs/dr6xx.cpp b/clang/test/CXX/drs/dr6xx.cpp
index 6ff162545826..7a0adb5fe406 100644
--- a/clang/test/CXX/drs/dr6xx.cpp
+++ b/clang/test/CXX/drs/dr6xx.cpp
@@ -551,9 +551,9 @@ namespace dr648 { 

[clang] 0a002f6 - [Sema] Try 2: Sanity-check alignment requested via `__attribute__((assume_aligned(imm)))`

2020-01-24 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2020-01-24T16:56:39+03:00
New Revision: 0a002f679be4a9d363e6f21b707493c18158930b

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

LOG: [Sema] Try 2: Sanity-check alignment requested via 
`__attribute__((assume_aligned(imm)))`

Summary:
For `__builtin_assume_aligned()`, we do validate that the alignment
is not greater than `536870912` (D68824), but we don't do that for
`__attribute__((assume_aligned(N)))` attribute.
I suspect we should.

This was initially committed in a4cfb15d15a8a353fe316f2a9fe1c8c6a6740ef1
but reverted in 210f0882c9e5d6f504b8f29e8a5eae884f812e5c due to
suspicious bot failures.

Reviewers: erichkeane, aaron.ballman, hfinkel, rsmith, jdoerfert

Reviewed By: erichkeane

Subscribers: cfe-commits, llvm-commits

Tags: #llvm, #clang

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

Added: 


Modified: 
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/Sema/builtin-assume-aligned.c

Removed: 




diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 514fca59ca09..8ad981f89b6e 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -1625,6 +1625,12 @@ void Sema::AddAssumeAlignedAttr(Decl *D, const 
AttributeCommonInfo , Expr *E,
 << E->getSourceRange();
   return;
 }
+
+// Alignment calculations can wrap around if it's greater than 2**29.
+unsigned MaximumAlignment = 536870912;
+if (I > MaximumAlignment)
+  Diag(CI.getLoc(), diag::warn_assume_aligned_too_great)
+  << CI.getRange() << MaximumAlignment;
   }
 
   if (OE) {

diff  --git a/clang/test/Sema/builtin-assume-aligned.c 
b/clang/test/Sema/builtin-assume-aligned.c
index 565dc6609442..b862f865c2ca 100644
--- a/clang/test/Sema/builtin-assume-aligned.c
+++ b/clang/test/Sema/builtin-assume-aligned.c
@@ -46,6 +46,7 @@ int test8(int *a, int j) {
 void test_void_assume_aligned(void) __attribute__((assume_aligned(32))); // 
expected-warning {{'assume_aligned' attribute only applies to return values 
that are pointers}}
 int test_int_assume_aligned(void) __attribute__((assume_aligned(16))); // 
expected-warning {{'assume_aligned' attribute only applies to return values 
that are pointers}}
 void *test_ptr_assume_aligned(void) __attribute__((assume_aligned(64))); // 
no-warning
+void *test_ptr_assume_aligned(void) 
__attribute__((assume_aligned(1073741824))); // expected-warning {{requested 
alignment must be 536870912 bytes or smaller; maximum alignment assumed}}
 
 int j __attribute__((assume_aligned(8))); // expected-warning 
{{'assume_aligned' attribute only applies to Objective-C methods and functions}}
 void *test_no_fn_proto() __attribute__((assume_aligned(32))); // no-warning



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


[clang] ba545c8 - [Sema] Try 2: Attempt to perform call-size-specific `__attribute__((alloc_align(param_idx)))` validation

2020-01-24 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2020-01-24T14:42:45+03:00
New Revision: ba545c814bc19c3b1ec9ce88a7f13575e0e4ce1d

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

LOG: [Sema] Try 2: Attempt to perform call-size-specific 
`__attribute__((alloc_align(param_idx)))` validation

Summary:
`alloc_align` attribute takes parameter number, not the alignment itself,
so given **just** the attribute/function declaration we can't do any
sanity checking for said alignment.

However, at call site, given the actual `Expr` that is passed
into that parameter, we //might// be able to evaluate said `Expr`
as Integer Constant Expression, and perform the sanity checks.
But since there is no requirement for that argument to be an immediate,
we may fail, and that's okay.

However if we did evaluate, we should enforce the same constraints
as with `__builtin_assume_aligned()`/`__attribute__((assume_aligned(imm)))`:
said alignment is a power of two, and is not greater than our magic threshold


This was initially committed in c2a9061ac5166e48fe85ea2b6dbce9457c964958
but reverted in 00756b182398b92abe16559287467079087aa631 because of
suspicious bot failures.

Reviewers: erichkeane, aaron.ballman, hfinkel, rsmith, jdoerfert

Reviewed By: erichkeane

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/lib/Sema/SemaChecking.cpp
clang/test/Sema/alloc-align-attr.c
clang/test/SemaCXX/alloc-align-attr.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 1f361569e09d..4485539f3f1c 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3653,6 +3653,27 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
 }
   }
 
+  if (FDecl && FDecl->hasAttr()) {
+auto *AA = FDecl->getAttr();
+const Expr *Arg = Args[AA->getParamIndex().getASTIndex()];
+if (!Arg->isValueDependent()) {
+  llvm::APSInt I(64);
+  if (Arg->isIntegerConstantExpr(I, Context)) {
+if (!I.isPowerOf2()) {
+  Diag(Arg->getExprLoc(), diag::err_alignment_not_power_of_two)
+  << Arg->getSourceRange();
+  return;
+}
+
+// Alignment calculations can wrap around if it's greater than 2**29.
+unsigned MaximumAlignment = 536870912;
+if (I > MaximumAlignment)
+  Diag(Arg->getExprLoc(), diag::warn_assume_aligned_too_great)
+  << Arg->getSourceRange() << MaximumAlignment;
+  }
+}
+  }
+
   if (FD)
 diagnoseArgDependentDiagnoseIfAttrs(FD, ThisArg, Args, Loc);
 }

diff  --git a/clang/test/Sema/alloc-align-attr.c 
b/clang/test/Sema/alloc-align-attr.c
index ae514343aff4..aa0fbd2cee3d 100644
--- a/clang/test/Sema/alloc-align-attr.c
+++ b/clang/test/Sema/alloc-align-attr.c
@@ -17,3 +17,15 @@ void *test_no_fn_proto(int x, int y) 
__attribute__((alloc_align)); // expected-e
 void *test_no_fn_proto(int x, int y) __attribute__((alloc_align())); // 
expected-error {{'alloc_align' attribute takes one argument}}
 void *test_no_fn_proto(int x, int y) __attribute__((alloc_align(32, 45, 37))); 
// expected-error {{'alloc_align' attribute takes one argument}}
 
+void *passthrought(int a) {
+  return test_ptr_alloc_align(a);
+}
+void *align16() {
+  return test_ptr_alloc_align(16);
+}
+void *align15() {
+  return test_ptr_alloc_align(15); // expected-error {{requested alignment is 
not a power of 2}}
+}
+void *align536870912() {
+  return test_ptr_alloc_align(1073741824); // expected-warning {{requested 
alignment must be 536870912 bytes or smaller; maximum alignment assumed}}
+}

diff  --git a/clang/test/SemaCXX/alloc-align-attr.cpp 
b/clang/test/SemaCXX/alloc-align-attr.cpp
index 74cfb7d7e486..f910cbcf2c90 100644
--- a/clang/test/SemaCXX/alloc-align-attr.cpp
+++ b/clang/test/SemaCXX/alloc-align-attr.cpp
@@ -23,13 +23,19 @@ void* dependent_param_func(T param) 
__attribute__((alloc_align(1)));// expected-
 template 
 void* illegal_align_param(int p) __attribute__((alloc_align(T))); // 
expected-error {{'alloc_align' attribute requires parameter 1 to be an integer 
constant}}
 
-void dependent_impl() {
+void dependent_impl(int align) {
   dependent_ret a; // expected-note {{in instantiation of template class 
'dependent_ret' requested here}}
   a.Foo(1);
   a.Foo2(1);
-  dependent_ret b; 
-  a.Foo(1);
-  a.Foo2(1);
+  dependent_ret b;
+  b.Foo(1);
+  b.Foo2(1);
+  b.Foo(3);   // expected-error {{requested alignment is not a power 
of 2}}
+  b.Foo2(3);  // expected-error {{requested alignment is not a power 
of 2}}
+  b.Foo(1073741824);  // expected-warning {{requested alignment must be 
536870912 bytes or smaller; maximum alignment assumed}}
+  b.Foo2(1073741824); // 

[clang] 1624cba - Partially revert "[IR] Attribute/AttrBuilder: use Value::MaximumAlignment magic constant"

2020-01-23 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2020-01-23T23:30:42+03:00
New Revision: 1624cba7824967c15ac36d9fdd41bb9878463dbe

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

LOG: Partially revert "[IR] Attribute/AttrBuilder: use Value::MaximumAlignment 
magic constant"

Apparently makes bots angry.

This reverts commit d096f8d306b2b16a25f65ffb70849ca7963a0dac.

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaDeclAttr.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 92d964d6603d..fae1ade80ca9 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -372,15 +372,6 @@ class Sema final {
   QualType ResultTy,
   ArrayRef Args);
 
-  /// The maximum alignment, same as in llvm::Value. We duplicate them here
-  /// because that allows us not to duplicate the constants in clang code,
-  /// which we must to since we can't directly use the llvm constants.
-  ///
-  /// This is the greatest alignment value supported by load, store, and alloca
-  /// instructions, and global values.
-  static const unsigned MaxAlignmentExponent = 29;
-  static const unsigned MaximumAlignment = 1u << MaxAlignmentExponent;
-
 public:
   typedef OpaquePtr DeclGroupPtrTy;
   typedef OpaquePtr TemplateTy;

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 1539f3375c41..1f361569e09d 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5373,9 +5373,11 @@ bool Sema::SemaBuiltinAssumeAligned(CallExpr *TheCall) {
   return Diag(TheCall->getBeginLoc(), diag::err_alignment_not_power_of_two)
  << Arg->getSourceRange();
 
-if (Result > Sema::MaximumAlignment)
+// Alignment calculations can wrap around if it's greater than 2**29.
+unsigned MaximumAlignment = 536870912;
+if (Result > MaximumAlignment)
   Diag(TheCall->getBeginLoc(), diag::warn_assume_aligned_too_great)
-  << Arg->getSourceRange() << Sema::MaximumAlignment;
+  << Arg->getSourceRange() << MaximumAlignment;
   }
 
   if (NumArgs > 2) {

diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index b404b45fec59..8aff975b8f2d 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -3810,9 +3810,13 @@ void Sema::AddAlignedAttr(Decl *D, const 
AttributeCommonInfo , Expr *E,
 }
   }
 
-  if (AlignVal > Sema::MaximumAlignment) {
+  // Alignment calculations can wrap around if it's greater than 2**28.
+  unsigned MaxValidAlignment =
+  Context.getTargetInfo().getTriple().isOSBinFormatCOFF() ? 8192
+  : 268435456;
+  if (AlignVal > MaxValidAlignment) {
 Diag(AttrLoc, diag::err_attribute_aligned_too_great)
-<< Sema::MaximumAlignment << E->getSourceRange();
+<< MaxValidAlignment << E->getSourceRange();
 return;
   }
 



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


[clang] 210f088 - Revert "[Sema] Sanity-check alignment requested via `__attribute__((assume_aligned(imm)))`"

2020-01-23 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2020-01-23T23:10:35+03:00
New Revision: 210f0882c9e5d6f504b8f29e8a5eae884f812e5c

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

LOG: Revert "[Sema] Sanity-check alignment requested via 
`__attribute__((assume_aligned(imm)))`"

Likely makes bots angry.

This reverts commit a4cfb15d15a8a353fe316f2a9fe1c8c6a6740ef1.

# Conflicts:
#   clang/lib/Sema/SemaDeclAttr.cpp

Added: 


Modified: 
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/Sema/builtin-assume-aligned.c

Removed: 




diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 54a65f5f26ae..b404b45fec59 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -1625,10 +1625,6 @@ void Sema::AddAssumeAlignedAttr(Decl *D, const 
AttributeCommonInfo , Expr *E,
 << E->getSourceRange();
   return;
 }
-
-if (I > Sema::MaximumAlignment)
-  Diag(CI.getLoc(), diag::warn_assume_aligned_too_great)
-  << CI.getRange() << Sema::MaximumAlignment;
   }
 
   if (OE) {

diff  --git a/clang/test/Sema/builtin-assume-aligned.c 
b/clang/test/Sema/builtin-assume-aligned.c
index b862f865c2ca..565dc6609442 100644
--- a/clang/test/Sema/builtin-assume-aligned.c
+++ b/clang/test/Sema/builtin-assume-aligned.c
@@ -46,7 +46,6 @@ int test8(int *a, int j) {
 void test_void_assume_aligned(void) __attribute__((assume_aligned(32))); // 
expected-warning {{'assume_aligned' attribute only applies to return values 
that are pointers}}
 int test_int_assume_aligned(void) __attribute__((assume_aligned(16))); // 
expected-warning {{'assume_aligned' attribute only applies to return values 
that are pointers}}
 void *test_ptr_assume_aligned(void) __attribute__((assume_aligned(64))); // 
no-warning
-void *test_ptr_assume_aligned(void) 
__attribute__((assume_aligned(1073741824))); // expected-warning {{requested 
alignment must be 536870912 bytes or smaller; maximum alignment assumed}}
 
 int j __attribute__((assume_aligned(8))); // expected-warning 
{{'assume_aligned' attribute only applies to Objective-C methods and functions}}
 void *test_no_fn_proto() __attribute__((assume_aligned(32))); // no-warning



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


[clang] 00756b1 - Revert "[Sema] Attempt to perform call-size-specific `__attribute__((alloc_align(param_idx)))` validation"

2020-01-23 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2020-01-23T23:10:34+03:00
New Revision: 00756b182398b92abe16559287467079087aa631

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

LOG: Revert "[Sema] Attempt to perform call-size-specific 
`__attribute__((alloc_align(param_idx)))` validation"

Likely makes bots angry.

This reverts commit c2a9061ac5166e48fe85ea2b6dbce9457c964958.

Added: 


Modified: 
clang/lib/Sema/SemaChecking.cpp
clang/test/Sema/alloc-align-attr.c
clang/test/SemaCXX/alloc-align-attr.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 186f2b5b990c..1539f3375c41 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3653,25 +3653,6 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
 }
   }
 
-  if (FDecl && FDecl->hasAttr()) {
-auto *AA = FDecl->getAttr();
-const Expr *Arg = Args[AA->getParamIndex().getASTIndex()];
-if (!Arg->isValueDependent()) {
-  llvm::APSInt I(64);
-  if (Arg->isIntegerConstantExpr(I, Context)) {
-if (!I.isPowerOf2()) {
-  Diag(Arg->getExprLoc(), diag::err_alignment_not_power_of_two)
-  << Arg->getSourceRange();
-  return;
-}
-
-if (I > Sema::MaximumAlignment)
-  Diag(Arg->getExprLoc(), diag::warn_assume_aligned_too_great)
-  << Arg->getSourceRange() << Sema::MaximumAlignment;
-  }
-}
-  }
-
   if (FD)
 diagnoseArgDependentDiagnoseIfAttrs(FD, ThisArg, Args, Loc);
 }

diff  --git a/clang/test/Sema/alloc-align-attr.c 
b/clang/test/Sema/alloc-align-attr.c
index aa0fbd2cee3d..ae514343aff4 100644
--- a/clang/test/Sema/alloc-align-attr.c
+++ b/clang/test/Sema/alloc-align-attr.c
@@ -17,15 +17,3 @@ void *test_no_fn_proto(int x, int y) 
__attribute__((alloc_align)); // expected-e
 void *test_no_fn_proto(int x, int y) __attribute__((alloc_align())); // 
expected-error {{'alloc_align' attribute takes one argument}}
 void *test_no_fn_proto(int x, int y) __attribute__((alloc_align(32, 45, 37))); 
// expected-error {{'alloc_align' attribute takes one argument}}
 
-void *passthrought(int a) {
-  return test_ptr_alloc_align(a);
-}
-void *align16() {
-  return test_ptr_alloc_align(16);
-}
-void *align15() {
-  return test_ptr_alloc_align(15); // expected-error {{requested alignment is 
not a power of 2}}
-}
-void *align536870912() {
-  return test_ptr_alloc_align(1073741824); // expected-warning {{requested 
alignment must be 536870912 bytes or smaller; maximum alignment assumed}}
-}

diff  --git a/clang/test/SemaCXX/alloc-align-attr.cpp 
b/clang/test/SemaCXX/alloc-align-attr.cpp
index f910cbcf2c90..74cfb7d7e486 100644
--- a/clang/test/SemaCXX/alloc-align-attr.cpp
+++ b/clang/test/SemaCXX/alloc-align-attr.cpp
@@ -23,19 +23,13 @@ void* dependent_param_func(T param) 
__attribute__((alloc_align(1)));// expected-
 template 
 void* illegal_align_param(int p) __attribute__((alloc_align(T))); // 
expected-error {{'alloc_align' attribute requires parameter 1 to be an integer 
constant}}
 
-void dependent_impl(int align) {
+void dependent_impl() {
   dependent_ret a; // expected-note {{in instantiation of template class 
'dependent_ret' requested here}}
   a.Foo(1);
   a.Foo2(1);
-  dependent_ret b;
-  b.Foo(1);
-  b.Foo2(1);
-  b.Foo(3);   // expected-error {{requested alignment is not a power 
of 2}}
-  b.Foo2(3);  // expected-error {{requested alignment is not a power 
of 2}}
-  b.Foo(1073741824);  // expected-warning {{requested alignment must be 
536870912 bytes or smaller; maximum alignment assumed}}
-  b.Foo2(1073741824); // expected-warning {{requested alignment must be 
536870912 bytes or smaller; maximum alignment assumed}}
-  b.Foo(align);
-  b.Foo2(align);
+  dependent_ret b; 
+  a.Foo(1);
+  a.Foo2(1);
 
   dependent_param_struct c; 
   c.Foo(1);



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


[clang] c2a9061 - [Sema] Attempt to perform call-size-specific `__attribute__((alloc_align(param_idx)))` validation

2020-01-23 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2020-01-23T22:50:49+03:00
New Revision: c2a9061ac5166e48fe85ea2b6dbce9457c964958

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

LOG: [Sema] Attempt to perform call-size-specific 
`__attribute__((alloc_align(param_idx)))` validation

Summary:
`alloc_align` attribute takes parameter number, not the alignment itself,
so given **just** the attribute/function declaration we can't do any
sanity checking for said alignment.

However, at call site, given the actual `Expr` that is passed
into that parameter, we //might// be able to evaluate said `Expr`
as Integer Constant Expression, and perform the sanity checks.
But since there is no requirement for that argument to be an immediate,
we may fail, and that's okay.

However if we did evaluate, we should enforce the same constraints
as with `__builtin_assume_aligned()`/`__attribute__((assume_aligned(imm)))`:
said alignment is a power of two, and is not greater than our magic threshold

Reviewers: erichkeane, aaron.ballman, hfinkel, rsmith, jdoerfert

Reviewed By: erichkeane

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/lib/Sema/SemaChecking.cpp
clang/test/Sema/alloc-align-attr.c
clang/test/SemaCXX/alloc-align-attr.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 1f361569e09d..4485539f3f1c 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3653,6 +3653,27 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
 }
   }
 
+  if (FDecl && FDecl->hasAttr()) {
+auto *AA = FDecl->getAttr();
+const Expr *Arg = Args[AA->getParamIndex().getASTIndex()];
+if (!Arg->isValueDependent()) {
+  llvm::APSInt I(64);
+  if (Arg->isIntegerConstantExpr(I, Context)) {
+if (!I.isPowerOf2()) {
+  Diag(Arg->getExprLoc(), diag::err_alignment_not_power_of_two)
+  << Arg->getSourceRange();
+  return;
+}
+
+// Alignment calculations can wrap around if it's greater than 2**29.
+unsigned MaximumAlignment = 536870912;
+if (I > MaximumAlignment)
+  Diag(Arg->getExprLoc(), diag::warn_assume_aligned_too_great)
+  << Arg->getSourceRange() << MaximumAlignment;
+  }
+}
+  }
+
   if (FD)
 diagnoseArgDependentDiagnoseIfAttrs(FD, ThisArg, Args, Loc);
 }

diff  --git a/clang/test/Sema/alloc-align-attr.c 
b/clang/test/Sema/alloc-align-attr.c
index ae514343aff4..aa0fbd2cee3d 100644
--- a/clang/test/Sema/alloc-align-attr.c
+++ b/clang/test/Sema/alloc-align-attr.c
@@ -17,3 +17,15 @@ void *test_no_fn_proto(int x, int y) 
__attribute__((alloc_align)); // expected-e
 void *test_no_fn_proto(int x, int y) __attribute__((alloc_align())); // 
expected-error {{'alloc_align' attribute takes one argument}}
 void *test_no_fn_proto(int x, int y) __attribute__((alloc_align(32, 45, 37))); 
// expected-error {{'alloc_align' attribute takes one argument}}
 
+void *passthrought(int a) {
+  return test_ptr_alloc_align(a);
+}
+void *align16() {
+  return test_ptr_alloc_align(16);
+}
+void *align15() {
+  return test_ptr_alloc_align(15); // expected-error {{requested alignment is 
not a power of 2}}
+}
+void *align536870912() {
+  return test_ptr_alloc_align(1073741824); // expected-warning {{requested 
alignment must be 536870912 bytes or smaller; maximum alignment assumed}}
+}

diff  --git a/clang/test/SemaCXX/alloc-align-attr.cpp 
b/clang/test/SemaCXX/alloc-align-attr.cpp
index 74cfb7d7e486..f910cbcf2c90 100644
--- a/clang/test/SemaCXX/alloc-align-attr.cpp
+++ b/clang/test/SemaCXX/alloc-align-attr.cpp
@@ -23,13 +23,19 @@ void* dependent_param_func(T param) 
__attribute__((alloc_align(1)));// expected-
 template 
 void* illegal_align_param(int p) __attribute__((alloc_align(T))); // 
expected-error {{'alloc_align' attribute requires parameter 1 to be an integer 
constant}}
 
-void dependent_impl() {
+void dependent_impl(int align) {
   dependent_ret a; // expected-note {{in instantiation of template class 
'dependent_ret' requested here}}
   a.Foo(1);
   a.Foo2(1);
-  dependent_ret b; 
-  a.Foo(1);
-  a.Foo2(1);
+  dependent_ret b;
+  b.Foo(1);
+  b.Foo2(1);
+  b.Foo(3);   // expected-error {{requested alignment is not a power 
of 2}}
+  b.Foo2(3);  // expected-error {{requested alignment is not a power 
of 2}}
+  b.Foo(1073741824);  // expected-warning {{requested alignment must be 
536870912 bytes or smaller; maximum alignment assumed}}
+  b.Foo2(1073741824); // expected-warning {{requested alignment must be 
536870912 bytes or smaller; maximum alignment assumed}}
+  b.Foo(align);
+  b.Foo2(align);
 
   dependent_param_struct c; 
   

  1   2   3   4   >