[clang-tools-extra] [clang-tidy] Improve `ExceptionSpecAnalyzer`s handling of conditional noexcept expressions (PR #68359)
@@ -284,6 +284,12 @@ Changes in existing checks ` check to properly escape single quotes. +- Improved :doc:`performance-noexcept-move-constructor + ` and + :doc:`performance-noexcept-swap` PiotrZSL wrote: duplicate this change note, here leave one for move-constructor, and part about swap merge with next entry in line 293. So we could have 1 entry per check. https://github.com/llvm/llvm-project/pull/68359 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Improve `ExceptionSpecAnalyzer`s handling of conditional noexcept expressions (PR #68359)
https://github.com/PiotrZSL approved this pull request. +- LGTM, just split in release notes is needed. https://github.com/llvm/llvm-project/pull/68359 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][dataflow] Various formatting tweaks to HTMLLogger. (PR #68392)
https://github.com/martinboehme created https://github.com/llvm/llvm-project/pull/68392 * Ensure timeline entries don't have linebreaks by setting `min-width: max-content`. * Give the timeline header some padding on the right so it doesn't run into the "Function" header. * Put some padding around the iteration choosers so they don't run into each other. * Eliminate the "Iteration" text from the iteration choosers, which took up a lot of space. It should be clear what these are without the "Iteration" text. (This makes the above problem of iteration choosers running into each other less likely, but also add the padding nonetheless.) >From c67f864f371469ca77df57b91b4dd8e012c274a4 Mon Sep 17 00:00:00 2001 From: Martin Braenne Date: Fri, 6 Oct 2023 07:24:12 + Subject: [PATCH] [clang][dataflow] Various formatting tweaks to HTMLLogger. * Ensure timeline entries don't have linebreaks by setting `min-width: max-content`. * Give the timeline header some padding on the right so it doesn't run into the "Function" header. * Put some padding around the iteration choosers so they don't run into each other. * Eliminate the "Iteration" text from the iteration choosers, which took up a lot of space. It should be clear what these are without the "Iteration" text. (This makes the above problem of iteration choosers running into each other less likely, but also add the padding nonetheless.) --- clang/lib/Analysis/FlowSensitive/HTMLLogger.css | 7 ++- clang/lib/Analysis/FlowSensitive/HTMLLogger.html | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/clang/lib/Analysis/FlowSensitive/HTMLLogger.css b/clang/lib/Analysis/FlowSensitive/HTMLLogger.css index 4de1d1ccc2b08ee..5da8db8fa87bf2f 100644 --- a/clang/lib/Analysis/FlowSensitive/HTMLLogger.css +++ b/clang/lib/Analysis/FlowSensitive/HTMLLogger.css @@ -19,6 +19,7 @@ section header { color: white; font-weight: bold; font-size: large; + padding-right: 0.5em; } section h2 { font-size: medium; @@ -27,7 +28,7 @@ section h2 { border-top: 1px solid #aaa; } #timeline { - min-width: 0; + min-width: max-content; } #timeline .entry.hover { background-color: #aaa; @@ -62,6 +63,10 @@ section h2 { #iterations .chooser { flex-grow: 1; text-align: center; + padding-left: 0.2em; +} +#iterations .chooser :last-child { + padding-right: 0.2em; } #iterations .chooser:not(.iter-select).hover { background-color: #ddd; diff --git a/clang/lib/Analysis/FlowSensitive/HTMLLogger.html b/clang/lib/Analysis/FlowSensitive/HTMLLogger.html index ec9d74c71d35d98..b9f76c5074c7539 100644 --- a/clang/lib/Analysis/FlowSensitive/HTMLLogger.html +++ b/clang/lib/Analysis/FlowSensitive/HTMLLogger.html @@ -62,7 +62,7 @@ Post-visit - Iteration {{iter.iter}} + {{iter.iter}} →| ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [IPSCCP] Variable not visible at Og. (PR #66745)
https://github.com/CarlosAlbertoEnciso updated https://github.com/llvm/llvm-project/pull/66745 >From b24943f63025822a5c5ba90c4a7b47f7123ec4db Mon Sep 17 00:00:00 2001 From: Carlos Alberto Enciso Date: Mon, 18 Sep 2023 12:29:17 +0100 Subject: [PATCH 1/4] [IPSCCP] Variable not visible at Og: https://bugs.llvm.org/show_bug.cgi?id=51559 https://github.com/llvm/llvm-project/issues/50901 IPSCCP pass removes the global variable and does not create a constant expression for the initializer value. --- llvm/lib/Transforms/IPO/SCCP.cpp | 47 +++ llvm/test/Transforms/SCCP/pr50901.ll | 184 +++ 2 files changed, 231 insertions(+) create mode 100644 llvm/test/Transforms/SCCP/pr50901.ll diff --git a/llvm/lib/Transforms/IPO/SCCP.cpp b/llvm/lib/Transforms/IPO/SCCP.cpp index 84f5bbf7039416b..e09769e00148143 100644 --- a/llvm/lib/Transforms/IPO/SCCP.cpp +++ b/llvm/lib/Transforms/IPO/SCCP.cpp @@ -22,6 +22,7 @@ #include "llvm/Analysis/ValueTracking.h" #include "llvm/IR/AttributeMask.h" #include "llvm/IR/Constants.h" +#include "llvm/IR/DIBuilder.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/ModRef.h" @@ -371,6 +372,52 @@ static bool runIPSCCP( StoreInst *SI = cast(GV->user_back()); SI->eraseFromParent(); } + +// Try to create a debug constant expression for the glbal variable +// initializer value. +SmallVector GVEs; +GV->getDebugInfo(GVEs); +if (GVEs.size() == 1) { + DIBuilder DIB(M); + + // Create integer constant expression. + auto createIntExpression = [&DIB](const Constant *CV) -> DIExpression * { +const APInt &API = dyn_cast(CV)->getValue(); +std::optional InitIntOpt; +if (API.isNonNegative()) + InitIntOpt = API.tryZExtValue(); +else if (auto Temp = API.trySExtValue(); Temp.has_value()) + // Transform a signed optional to unsigned optional. + InitIntOpt = (uint64_t)Temp.value(); +return DIB.createConstantValueExpression(InitIntOpt.value()); + }; + + const Constant *CV = GV->getInitializer(); + Type *Ty = GV->getValueType(); + if (Ty->isIntegerTy()) { +GVEs[0]->replaceOperandWith(1, createIntExpression(CV)); + } else if (Ty->isFloatTy() || Ty->isDoubleTy()) { +const APFloat &APF = dyn_cast(CV)->getValueAPF(); +DIExpression *NewExpr = DIB.createConstantValueExpression( +APF.bitcastToAPInt().getZExtValue()); +GVEs[0]->replaceOperandWith(1, NewExpr); + } else if (Ty->isPointerTy()) { +if (isa(CV)) { + GVEs[0]->replaceOperandWith(1, DIB.createConstantValueExpression(0)); +} else { + if (const ConstantExpr *CE = dyn_cast(CV)) { +if (CE->getNumOperands() == 1) { + const Value *V = CE->getOperand(0); + const Constant *CV = dyn_cast(V); + if (CV && !isa(CV)) +if (const ConstantInt *CI = dyn_cast(CV)) + GVEs[0]->replaceOperandWith(1, createIntExpression(CI)); +} + } +} + } +} + MadeChanges = true; M.eraseGlobalVariable(GV); ++NumGlobalConst; diff --git a/llvm/test/Transforms/SCCP/pr50901.ll b/llvm/test/Transforms/SCCP/pr50901.ll new file mode 100644 index 000..56961d2e32db41c --- /dev/null +++ b/llvm/test/Transforms/SCCP/pr50901.ll @@ -0,0 +1,184 @@ +; RUN: opt -passes=ipsccp -S -o - < %s | FileCheck %s + +; Global variables g_11, g_22, g_33, g_44, g_55, g_66 and g_77 +; are not visible in the debugger. + +; 1 int g_1 = -4; +; 2 float g_2 = 4.44; +; 3 char g_3 = 'a'; +; 4 unsigned g_4 = 4; +; 5 bool g_5 = true; +; 6 int *g_6 = nullptr; +; 7 float*g_7 = nullptr; +; 8 +; 9 static int g_11 = -5; +; 10 static float g_22 = 5.55; +; 11 static char g_33 = 'b'; +; 12 static unsigned g_44 = 5; +; 13 static bool g_55 = true; +; 14 static int *g_66 = nullptr; +; 15 static float*g_77 = (float *)(55 + 15); +; 16 +; 17 void bar() { +; 18 g_1 = g_11; +; 19 g_2 = g_22; +; 20 g_3 = g_33; +; 21 g_4 = g_44; +; 22 g_5 = g_55; +; 23 g_6 = g_66; +; 24 g_7 = g_77; +; 25 } +; 26 +; 27 int main() { +; 28 { +; 29 bar(); +; 30 } +; 31 } + +; CHECK: ![[G1:[0-9]+]] = !DIGlobalVariableExpression(var: ![[DBG1:[0-9]+]], expr: !DIExpression(DW_OP_constu, 18446744073709551611, DW_OP_stack_value)) +; CHECK-DAG: ![[DBG1]] = distinct !DIGlobalVariable(name: "g_11", {{.*}} +; CHECK: ![[G2:[0-9]+]] = !DIGlobalVariableExpression(var: ![[DBG2:[0-9]+]], expr: !DIExpression(DW_OP_constu, 1085381018, DW_OP_stack_value)) +; CHECK-DAG: ![[DBG2]] = distinct !DIGlobalVariable(name: "g_22", {{.*}} +; CHECK: ![[G3:[0-9]+]] = !DIGlobalVariableExpression(var: ![[DBG3:[0-9]+]], expr: !DIExpression(DW_OP_constu, 98, DW_OP_stack_value)) +; CHECK-DAG: ![[DBG3]] = distin
[libunwind] [IPSCCP] Variable not visible at Og. (PR #66745)
https://github.com/jryans edited https://github.com/llvm/llvm-project/pull/66745 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [IPSCCP] Variable not visible at Og. (PR #66745)
https://github.com/jryans edited https://github.com/llvm/llvm-project/pull/66745 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [IPSCCP] Variable not visible at Og. (PR #66745)
https://github.com/jryans edited https://github.com/llvm/llvm-project/pull/66745 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][dataflow] Various formatting tweaks to HTMLLogger. (PR #68392)
llvmbot wrote: @llvm/pr-subscribers-clang-analysis Changes * Ensure timeline entries don't have linebreaks by setting `min-width: max-content`. * Give the timeline header some padding on the right so it doesn't run into the "Function" header. * Put some padding around the iteration choosers so they don't run into each other. * Eliminate the "Iteration" text from the iteration choosers, which took up a lot of space. It should be clear what these are without the "Iteration" text. (This makes the above problem of iteration choosers running into each other less likely, but also add the padding nonetheless.) --- Full diff: https://github.com/llvm/llvm-project/pull/68392.diff 2 Files Affected: - (modified) clang/lib/Analysis/FlowSensitive/HTMLLogger.css (+6-1) - (modified) clang/lib/Analysis/FlowSensitive/HTMLLogger.html (+1-1) ``diff diff --git a/clang/lib/Analysis/FlowSensitive/HTMLLogger.css b/clang/lib/Analysis/FlowSensitive/HTMLLogger.css index 4de1d1ccc2b08ee..5da8db8fa87bf2f 100644 --- a/clang/lib/Analysis/FlowSensitive/HTMLLogger.css +++ b/clang/lib/Analysis/FlowSensitive/HTMLLogger.css @@ -19,6 +19,7 @@ section header { color: white; font-weight: bold; font-size: large; + padding-right: 0.5em; } section h2 { font-size: medium; @@ -27,7 +28,7 @@ section h2 { border-top: 1px solid #aaa; } #timeline { - min-width: 0; + min-width: max-content; } #timeline .entry.hover { background-color: #aaa; @@ -62,6 +63,10 @@ section h2 { #iterations .chooser { flex-grow: 1; text-align: center; + padding-left: 0.2em; +} +#iterations .chooser :last-child { + padding-right: 0.2em; } #iterations .chooser:not(.iter-select).hover { background-color: #ddd; diff --git a/clang/lib/Analysis/FlowSensitive/HTMLLogger.html b/clang/lib/Analysis/FlowSensitive/HTMLLogger.html index ec9d74c71d35d98..b9f76c5074c7539 100644 --- a/clang/lib/Analysis/FlowSensitive/HTMLLogger.html +++ b/clang/lib/Analysis/FlowSensitive/HTMLLogger.html @@ -62,7 +62,7 @@ Post-visit - Iteration {{iter.iter}} + {{iter.iter}} →| `` https://github.com/llvm/llvm-project/pull/68392 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Sema] Add check for bitfield assignments to larger integral types (PR #68276)
vabridgers wrote: Hi @AaronBallman and @erichkeane , any improvements you could suggest? I could expand the testing for sure. Before I invest time in that, I'd like to be sure the general approach is ok in Sema. Thanks. https://github.com/llvm/llvm-project/pull/68276 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Improve `ExceptionSpecAnalyzer`s handling of conditional noexcept expressions (PR #68359)
https://github.com/AMS21 updated https://github.com/llvm/llvm-project/pull/68359 >From e82ff98aaf7b40fd5d598b486243adc54009bffc Mon Sep 17 00:00:00 2001 From: AMS21 Date: Thu, 5 Oct 2023 23:39:42 +0200 Subject: [PATCH] [clang-tidy] Improve `ExceptionSpecAnalyzer`s handling of conditional noexcept expressions The previous code was pretty messy and treated value dependant expressions which could not be evaluated the same as if they evaluted to `false`. Which was obviously not correct. We now check if we can evaluate the dependant expressions and if not we truthfully return that we don't know if the function is declared as `noexcept` or not. This fixes #68101 --- .../utils/ExceptionSpecAnalyzer.cpp | 21 ++ clang-tools-extra/docs/ReleaseNotes.rst | 7 - .../performance/noexcept-move-constructor.cpp | 18 .../checkers/performance/noexcept-swap.cpp| 28 ++- 4 files changed, 60 insertions(+), 14 deletions(-) diff --git a/clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp b/clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp index 4dd4a95f880aca0..1dde0490517852d 100644 --- a/clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp +++ b/clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp @@ -142,13 +142,22 @@ ExceptionSpecAnalyzer::analyzeFunctionEST(const FunctionDecl *FuncDecl, return State::NotThrowing; case CT_Dependent: { const Expr *NoexceptExpr = FuncProto->getNoexceptExpr(); +if (!NoexceptExpr) + return State::NotThrowing; + +// We can't resolve value dependence so just return unknown +if (NoexceptExpr->isValueDependent()) + return State::Unknown; + +// Try to evaluate the expression to a boolean value bool Result = false; -return (NoexceptExpr && !NoexceptExpr->isValueDependent() && -NoexceptExpr->EvaluateAsBooleanCondition( -Result, FuncDecl->getASTContext(), true) && -Result) - ? State::NotThrowing - : State::Throwing; +if (NoexceptExpr->EvaluateAsBooleanCondition( +Result, FuncDecl->getASTContext(), true)) + return Result ? State::NotThrowing : State::Throwing; + +// The noexcept expression is not value dependent but we can't evaluate it +// as a boolean condition so we have no idea if its throwing or not +return State::Unknown; } default: return State::Throwing; diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 0ecf786e73bc413..8ca816bfc2d6021 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -284,9 +284,14 @@ Changes in existing checks ` check to properly escape single quotes. +- Improved :doc:`performance-noexcept-move-constructor + ` to better handle + conditional noexcept expressions, eliminating false-positives. + - Improved :doc:`performance-noexcept-swap ` check to enforce a stricter - match with the swap function signature, eliminating false-positives. + match with the swap function signature and better handling of condition + noexcept expressions, eliminating false-positives. - Improved :doc:`readability-braces-around-statements ` check to diff --git a/clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-move-constructor.cpp b/clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-move-constructor.cpp index 60596c2876c0a34..347a1e3220061af 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-move-constructor.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-move-constructor.cpp @@ -1,5 +1,14 @@ // RUN: %check_clang_tidy %s performance-noexcept-move-constructor %t -- -- -fexceptions +namespace std +{ + template + struct is_nothrow_move_constructible + { +static constexpr bool value = __is_nothrow_constructible(T, __add_rvalue_reference(T)); + }; +} // namespace std + struct Empty {}; @@ -379,3 +388,12 @@ struct OK31 { OK31(OK31 &&) noexcept(TrueT::value) = default; OK31& operator=(OK31 &&) noexcept(TrueT::value) = default; }; + +namespace gh68101 +{ + template + class Container { + public: + Container(Container&&) noexcept(std::is_nothrow_move_constructible::value); + }; +} // namespace gh68101 diff --git a/clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-swap.cpp b/clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-swap.cpp index 392b5d17d456e71..dfc71a2bb9ab370 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-swap.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-swap.cpp @@ -1,5 +1,14 @@ // RUN: %check_clang_tidy %s performance-noexcept-swap %t -- -- -fexceptions +namespace std +{ + template + struct is_nothrow_move_constructible + { +static constexpr bool value = __is_nothrow_constructible(T, __ad
[clang] Reapply "[clang analysis][thread-safety] Handle return-by-reference..… (PR #68394)
https://github.com/legrosbuffle created https://github.com/llvm/llvm-project/pull/68394 …. (#67776)" Now that `scudo` issues have been fixed (#68273). This reverts commit 462bdd5bf0861a27f451f7917802a954e2046bc7. >From 6bf1af81adef93f20f25db4023810fe7be750410 Mon Sep 17 00:00:00 2001 From: Clement Courbet Date: Fri, 29 Sep 2023 14:14:29 +0200 Subject: [PATCH] Reapply "[clang analysis][thread-safety] Handle return-by-reference... (#67776)" Now that `scudo` issues have been fixed (#68273). This reverts commit 462bdd5bf0861a27f451f7917802a954e2046bc7. --- .../clang/Analysis/Analyses/ThreadSafety.h| 8 +- .../clang/Basic/DiagnosticSemaKinds.td| 10 ++- clang/lib/Analysis/ThreadSafety.cpp | 80 +-- clang/lib/Sema/AnalysisBasedWarnings.cpp | 12 +++ .../SemaCXX/warn-thread-safety-analysis.cpp | 79 ++ 5 files changed, 161 insertions(+), 28 deletions(-) diff --git a/clang/include/clang/Analysis/Analyses/ThreadSafety.h b/clang/include/clang/Analysis/Analyses/ThreadSafety.h index 1808d1d71e05d2c..0866b09bab2995e 100644 --- a/clang/include/clang/Analysis/Analyses/ThreadSafety.h +++ b/clang/include/clang/Analysis/Analyses/ThreadSafety.h @@ -47,7 +47,13 @@ enum ProtectedOperationKind { POK_PassByRef, /// Passing a pt-guarded variable by reference. - POK_PtPassByRef + POK_PtPassByRef, + + /// Returning a guarded variable by reference. + POK_ReturnByRef, + + /// Returning a pt-guarded variable by reference. + POK_PtReturnByRef, }; /// This enum distinguishes between different kinds of lock actions. For diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 28f1db29e62fa91..e3cd49bcc9ecc6a 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3864,7 +3864,7 @@ def warn_fun_requires_negative_cap : Warning< "calling function %0 requires negative capability '%1'">, InGroup, DefaultIgnore; -// Thread safety warnings on pass by reference +// Thread safety warnings on pass/return by reference def warn_guarded_pass_by_reference : Warning< "passing variable %1 by reference requires holding %0 " "%select{'%2'|'%2' exclusively}3">, @@ -3873,6 +3873,14 @@ def warn_pt_guarded_pass_by_reference : Warning< "passing the value that %1 points to by reference requires holding %0 " "%select{'%2'|'%2' exclusively}3">, InGroup, DefaultIgnore; +def warn_guarded_return_by_reference : Warning< + "returning variable %1 by reference requires holding %0 " + "%select{'%2'|'%2' exclusively}3">, + InGroup, DefaultIgnore; +def warn_pt_guarded_return_by_reference : Warning< + "returning the value that %1 points to by reference requires holding %0 " + "%select{'%2'|'%2' exclusively}3">, + InGroup, DefaultIgnore; // Imprecise thread safety warnings def warn_variable_requires_lock : Warning< diff --git a/clang/lib/Analysis/ThreadSafety.cpp b/clang/lib/Analysis/ThreadSafety.cpp index 58dd7113665b132..54d0e95c6bd79a2 100644 --- a/clang/lib/Analysis/ThreadSafety.cpp +++ b/clang/lib/Analysis/ThreadSafety.cpp @@ -1008,7 +1008,7 @@ class ThreadSafetyAnalyzer { threadSafety::SExprBuilder SxBuilder; ThreadSafetyHandler &Handler; - const CXXMethodDecl *CurrentMethod = nullptr; + const FunctionDecl *CurrentFunction; LocalVariableMap LocalVarMap; FactManager FactMan; std::vector BlockInfo; @@ -1243,10 +1243,10 @@ bool ThreadSafetyAnalyzer::inCurrentScope(const CapabilityExpr &CapE) { // Members are in scope from methods of the same class. if (const auto *P = dyn_cast(SExp)) { -if (!CurrentMethod) +if (!isa_and_nonnull(CurrentFunction)) return false; const ValueDecl *VD = P->clangDecl(); -return VD->getDeclContext() == CurrentMethod->getDeclContext(); +return VD->getDeclContext() == CurrentFunction->getDeclContext(); } return false; @@ -1541,6 +1541,8 @@ class BuildLockset : public ConstStmtVisitor { ThreadSafetyAnalyzer *Analyzer; FactSet FSet; + // The fact set for the function on exit. + const FactSet &FunctionExitFSet; /// Maps constructed objects to `this` placeholder prior to initialization. llvm::SmallDenseMap ConstructedObjects; LocalVariableMap::Context LVarCtx; @@ -1566,9 +1568,11 @@ class BuildLockset : public ConstStmtVisitor { bool SkipFirstParam = false); public: - BuildLockset(ThreadSafetyAnalyzer *Anlzr, CFGBlockInfo &Info) + BuildLockset(ThreadSafetyAnalyzer *Anlzr, CFGBlockInfo &Info, + const FactSet &FunctionExitFSet) : ConstStmtVisitor(), Analyzer(Anlzr), FSet(Info.EntrySet), -LVarCtx(Info.EntryContext), CtxIndex(Info.EntryIndex) {} +FunctionExitFSet(FunctionExitFSet), LVarCtx(Info.EntryContext), +CtxIndex(Info.EntryIndex) {} void VisitUnaryOperator(const UnaryOperator *UO); void VisitBinaryOperator(const BinaryOperator *BO); @
[clang] Reapply "[clang analysis][thread-safety] Handle return-by-reference..… (PR #68394)
llvmbot wrote: @llvm/pr-subscribers-clang-analysis Changes …. (#67776)" Now that `scudo` issues have been fixed (#68273). This reverts commit 462bdd5bf0861a27f451f7917802a954e2046bc7. --- Full diff: https://github.com/llvm/llvm-project/pull/68394.diff 5 Files Affected: - (modified) clang/include/clang/Analysis/Analyses/ThreadSafety.h (+7-1) - (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+9-1) - (modified) clang/lib/Analysis/ThreadSafety.cpp (+54-26) - (modified) clang/lib/Sema/AnalysisBasedWarnings.cpp (+12) - (modified) clang/test/SemaCXX/warn-thread-safety-analysis.cpp (+79) ``diff diff --git a/clang/include/clang/Analysis/Analyses/ThreadSafety.h b/clang/include/clang/Analysis/Analyses/ThreadSafety.h index 1808d1d71e05d2c..0866b09bab2995e 100644 --- a/clang/include/clang/Analysis/Analyses/ThreadSafety.h +++ b/clang/include/clang/Analysis/Analyses/ThreadSafety.h @@ -47,7 +47,13 @@ enum ProtectedOperationKind { POK_PassByRef, /// Passing a pt-guarded variable by reference. - POK_PtPassByRef + POK_PtPassByRef, + + /// Returning a guarded variable by reference. + POK_ReturnByRef, + + /// Returning a pt-guarded variable by reference. + POK_PtReturnByRef, }; /// This enum distinguishes between different kinds of lock actions. For diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 28f1db29e62fa91..e3cd49bcc9ecc6a 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3864,7 +3864,7 @@ def warn_fun_requires_negative_cap : Warning< "calling function %0 requires negative capability '%1'">, InGroup, DefaultIgnore; -// Thread safety warnings on pass by reference +// Thread safety warnings on pass/return by reference def warn_guarded_pass_by_reference : Warning< "passing variable %1 by reference requires holding %0 " "%select{'%2'|'%2' exclusively}3">, @@ -3873,6 +3873,14 @@ def warn_pt_guarded_pass_by_reference : Warning< "passing the value that %1 points to by reference requires holding %0 " "%select{'%2'|'%2' exclusively}3">, InGroup, DefaultIgnore; +def warn_guarded_return_by_reference : Warning< + "returning variable %1 by reference requires holding %0 " + "%select{'%2'|'%2' exclusively}3">, + InGroup, DefaultIgnore; +def warn_pt_guarded_return_by_reference : Warning< + "returning the value that %1 points to by reference requires holding %0 " + "%select{'%2'|'%2' exclusively}3">, + InGroup, DefaultIgnore; // Imprecise thread safety warnings def warn_variable_requires_lock : Warning< diff --git a/clang/lib/Analysis/ThreadSafety.cpp b/clang/lib/Analysis/ThreadSafety.cpp index 58dd7113665b132..54d0e95c6bd79a2 100644 --- a/clang/lib/Analysis/ThreadSafety.cpp +++ b/clang/lib/Analysis/ThreadSafety.cpp @@ -1008,7 +1008,7 @@ class ThreadSafetyAnalyzer { threadSafety::SExprBuilder SxBuilder; ThreadSafetyHandler &Handler; - const CXXMethodDecl *CurrentMethod = nullptr; + const FunctionDecl *CurrentFunction; LocalVariableMap LocalVarMap; FactManager FactMan; std::vector BlockInfo; @@ -1243,10 +1243,10 @@ bool ThreadSafetyAnalyzer::inCurrentScope(const CapabilityExpr &CapE) { // Members are in scope from methods of the same class. if (const auto *P = dyn_cast(SExp)) { -if (!CurrentMethod) +if (!isa_and_nonnull(CurrentFunction)) return false; const ValueDecl *VD = P->clangDecl(); -return VD->getDeclContext() == CurrentMethod->getDeclContext(); +return VD->getDeclContext() == CurrentFunction->getDeclContext(); } return false; @@ -1541,6 +1541,8 @@ class BuildLockset : public ConstStmtVisitor { ThreadSafetyAnalyzer *Analyzer; FactSet FSet; + // The fact set for the function on exit. + const FactSet &FunctionExitFSet; /// Maps constructed objects to `this` placeholder prior to initialization. llvm::SmallDenseMap ConstructedObjects; LocalVariableMap::Context LVarCtx; @@ -1566,9 +1568,11 @@ class BuildLockset : public ConstStmtVisitor { bool SkipFirstParam = false); public: - BuildLockset(ThreadSafetyAnalyzer *Anlzr, CFGBlockInfo &Info) + BuildLockset(ThreadSafetyAnalyzer *Anlzr, CFGBlockInfo &Info, + const FactSet &FunctionExitFSet) : ConstStmtVisitor(), Analyzer(Anlzr), FSet(Info.EntrySet), -LVarCtx(Info.EntryContext), CtxIndex(Info.EntryIndex) {} +FunctionExitFSet(FunctionExitFSet), LVarCtx(Info.EntryContext), +CtxIndex(Info.EntryIndex) {} void VisitUnaryOperator(const UnaryOperator *UO); void VisitBinaryOperator(const BinaryOperator *BO); @@ -1577,6 +1581,7 @@ class BuildLockset : public ConstStmtVisitor { void VisitCXXConstructExpr(const CXXConstructExpr *Exp); void VisitDeclStmt(const DeclStmt *S); void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Exp); + void VisitReturnStmt(const ReturnStmt *S); };
[clang-tools-extra] [clang-tidy] Improve `ExceptionSpecAnalyzer`s handling of conditional noexcept expressions (PR #68359)
https://github.com/PiotrZSL approved this pull request. https://github.com/llvm/llvm-project/pull/68359 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Sema] Only check RVV types if we have them (PR #67669)
https://github.com/cor3ntin approved this pull request. https://github.com/llvm/llvm-project/pull/67669 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 3717147 - [clang][Sema] Only check RVV types if we have them (#67669)
Author: Timm Baeder Date: 2023-10-06T09:56:05+02:00 New Revision: 3717147ee6e41f7fa3225c318104982499c5c505 URL: https://github.com/llvm/llvm-project/commit/3717147ee6e41f7fa3225c318104982499c5c505 DIFF: https://github.com/llvm/llvm-project/commit/3717147ee6e41f7fa3225c318104982499c5c505.diff LOG: [clang][Sema] Only check RVV types if we have them (#67669) isRVVType() is suprisingly expensive, so do the checks only if the target has rvv types. Added: Modified: clang/lib/Sema/Sema.cpp Removed: diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index db81fa645a27ffd..67533ccbdf347c7 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -2071,7 +2071,7 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D) { targetDiag(D->getLocation(), diag::note_defined_here, FD) << D; } -if (Ty->isRVVType()) +if (TI.hasRISCVVTypes() && Ty->isRVVType()) checkRVVTypeSupport(Ty, Loc, D); // Don't allow SVE types in functions without a SVE target. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Sema] Only check RVV types if we have them (PR #67669)
https://github.com/tbaederr closed https://github.com/llvm/llvm-project/pull/67669 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] cd184c8 - Reapply "[clang analysis][thread-safety] Handle return-by-reference..… (#68394)
Author: Clement Courbet Date: 2023-10-06T10:50:08+02:00 New Revision: cd184c866e0aad1f957910b8c7a94f98a2b21ceb URL: https://github.com/llvm/llvm-project/commit/cd184c866e0aad1f957910b8c7a94f98a2b21ceb DIFF: https://github.com/llvm/llvm-project/commit/cd184c866e0aad1f957910b8c7a94f98a2b21ceb.diff LOG: Reapply "[clang analysis][thread-safety] Handle return-by-reference..… (#68394) …. (#67776)" Now that `scudo` issues have been fixed (#68273). This reverts commit 462bdd5bf0861a27f451f7917802a954e2046bc7. Added: Modified: clang/include/clang/Analysis/Analyses/ThreadSafety.h clang/include/clang/Basic/DiagnosticSemaKinds.td clang/lib/Analysis/ThreadSafety.cpp clang/lib/Sema/AnalysisBasedWarnings.cpp clang/test/SemaCXX/warn-thread-safety-analysis.cpp Removed: diff --git a/clang/include/clang/Analysis/Analyses/ThreadSafety.h b/clang/include/clang/Analysis/Analyses/ThreadSafety.h index 1808d1d71e05d2c..0866b09bab2995e 100644 --- a/clang/include/clang/Analysis/Analyses/ThreadSafety.h +++ b/clang/include/clang/Analysis/Analyses/ThreadSafety.h @@ -47,7 +47,13 @@ enum ProtectedOperationKind { POK_PassByRef, /// Passing a pt-guarded variable by reference. - POK_PtPassByRef + POK_PtPassByRef, + + /// Returning a guarded variable by reference. + POK_ReturnByRef, + + /// Returning a pt-guarded variable by reference. + POK_PtReturnByRef, }; /// This enum distinguishes between diff erent kinds of lock actions. For diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 28f1db29e62fa91..e3cd49bcc9ecc6a 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3864,7 +3864,7 @@ def warn_fun_requires_negative_cap : Warning< "calling function %0 requires negative capability '%1'">, InGroup, DefaultIgnore; -// Thread safety warnings on pass by reference +// Thread safety warnings on pass/return by reference def warn_guarded_pass_by_reference : Warning< "passing variable %1 by reference requires holding %0 " "%select{'%2'|'%2' exclusively}3">, @@ -3873,6 +3873,14 @@ def warn_pt_guarded_pass_by_reference : Warning< "passing the value that %1 points to by reference requires holding %0 " "%select{'%2'|'%2' exclusively}3">, InGroup, DefaultIgnore; +def warn_guarded_return_by_reference : Warning< + "returning variable %1 by reference requires holding %0 " + "%select{'%2'|'%2' exclusively}3">, + InGroup, DefaultIgnore; +def warn_pt_guarded_return_by_reference : Warning< + "returning the value that %1 points to by reference requires holding %0 " + "%select{'%2'|'%2' exclusively}3">, + InGroup, DefaultIgnore; // Imprecise thread safety warnings def warn_variable_requires_lock : Warning< diff --git a/clang/lib/Analysis/ThreadSafety.cpp b/clang/lib/Analysis/ThreadSafety.cpp index 58dd7113665b132..54d0e95c6bd79a2 100644 --- a/clang/lib/Analysis/ThreadSafety.cpp +++ b/clang/lib/Analysis/ThreadSafety.cpp @@ -1008,7 +1008,7 @@ class ThreadSafetyAnalyzer { threadSafety::SExprBuilder SxBuilder; ThreadSafetyHandler &Handler; - const CXXMethodDecl *CurrentMethod = nullptr; + const FunctionDecl *CurrentFunction; LocalVariableMap LocalVarMap; FactManager FactMan; std::vector BlockInfo; @@ -1243,10 +1243,10 @@ bool ThreadSafetyAnalyzer::inCurrentScope(const CapabilityExpr &CapE) { // Members are in scope from methods of the same class. if (const auto *P = dyn_cast(SExp)) { -if (!CurrentMethod) +if (!isa_and_nonnull(CurrentFunction)) return false; const ValueDecl *VD = P->clangDecl(); -return VD->getDeclContext() == CurrentMethod->getDeclContext(); +return VD->getDeclContext() == CurrentFunction->getDeclContext(); } return false; @@ -1541,6 +1541,8 @@ class BuildLockset : public ConstStmtVisitor { ThreadSafetyAnalyzer *Analyzer; FactSet FSet; + // The fact set for the function on exit. + const FactSet &FunctionExitFSet; /// Maps constructed objects to `this` placeholder prior to initialization. llvm::SmallDenseMap ConstructedObjects; LocalVariableMap::Context LVarCtx; @@ -1566,9 +1568,11 @@ class BuildLockset : public ConstStmtVisitor { bool SkipFirstParam = false); public: - BuildLockset(ThreadSafetyAnalyzer *Anlzr, CFGBlockInfo &Info) + BuildLockset(ThreadSafetyAnalyzer *Anlzr, CFGBlockInfo &Info, + const FactSet &FunctionExitFSet) : ConstStmtVisitor(), Analyzer(Anlzr), FSet(Info.EntrySet), -LVarCtx(Info.EntryContext), CtxIndex(Info.EntryIndex) {} +FunctionExitFSet(FunctionExitFSet), LVarCtx(Info.EntryContext), +CtxIndex(Info.EntryIndex) {} void VisitUnaryOperator(const UnaryOperator *UO); void VisitBinaryOperator(const BinaryOperator *BO); @@ -1577,6 +1581,7 @@ class BuildLoc
[clang] Reapply "[clang analysis][thread-safety] Handle return-by-reference..… (PR #68394)
https://github.com/legrosbuffle closed https://github.com/llvm/llvm-project/pull/68394 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [InstCombine] Canonicalize `(X +/- Y) & Y` into `~X & Y` when Y is a power of 2 (PR #67915)
https://github.com/nikic commented: Seems like some test coverage is missing here? * Commuted add * Commuted sub (negative test) * Commuted and * Multi-use add (negative test) https://github.com/llvm/llvm-project/pull/67915 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [AMDGPU] Add encoding/decoding support for non-result-returning ATOMIC_CSUB instructions (PR #68197)
https://github.com/stepthomas updated https://github.com/llvm/llvm-project/pull/68197 >From ed42bb63a3fe4a840071b74a3f9613dda815aa29 Mon Sep 17 00:00:00 2001 From: Stephen Thomas Date: Wed, 4 Oct 2023 10:16:49 +0100 Subject: [PATCH] [AMDGPU] Add encoding/decoding support for non-result-returning ATOMIC_CSUB instructions The BUFFER_ATOMIC_CSUB and GLOBAL_ATOMIC_CSUB instructions have encodings for non-value-returning forms, although actually using them isn't supported by hardware. However, these encodings aren't supported by the backend, meaning that they can't even be assembled or disassembled. Add support for the non-returning encodings, but gate actually using them in instruction selection behind a new feature FeatureAtomicCsubNoRtnInsts, which no target uses. This does allow the non-returning instructions to be tested manually and llvm.amdgcn.atomic.csub.ll is extended to cover them. The feature does not gate assembling or disassembling them, this is now not an error. --- llvm/lib/Target/AMDGPU/AMDGPU.td | 9 llvm/lib/Target/AMDGPU/AMDGPUInstructions.td | 1 + llvm/lib/Target/AMDGPU/BUFInstructions.td | 19 +-- llvm/lib/Target/AMDGPU/FLATInstructions.td| 18 +-- llvm/lib/Target/AMDGPU/GCNSubtarget.h | 4 ++ llvm/lib/Target/AMDGPU/SIInstrInfo.td | 1 + .../CodeGen/AMDGPU/llvm.amdgcn.atomic.csub.ll | 51 --- llvm/test/MC/AMDGPU/gfx1030_err.s | 6 --- 8 files changed, 85 insertions(+), 24 deletions(-) diff --git a/llvm/lib/Target/AMDGPU/AMDGPU.td b/llvm/lib/Target/AMDGPU/AMDGPU.td index bf5a7b0a96977c7..9ec062d45ba9f48 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPU.td +++ b/llvm/lib/Target/AMDGPU/AMDGPU.td @@ -693,6 +693,13 @@ def FeatureAtomicGlobalPkAddBF16Inst : SubtargetFeature<"atomic-global-pk-add-bf [FeatureFlatGlobalInsts] >; +def FeatureAtomicCsubNoRtnInsts : SubtargetFeature<"atomic-csub-no-rtn-insts", + "HasAtomicCsubNoRtnInsts", + "true", + "Has buffer_atomic_csub and global_atomic_csub instructions that don't " + "return original value" +>; + def FeatureFlatAtomicFaddF32Inst : SubtargetFeature<"flat-atomic-fadd-f32-inst", "HasFlatAtomicFaddF32Inst", @@ -1927,6 +1934,8 @@ def HasGWS : Predicate<"Subtarget->hasGWS()">; def HasCvtFP8VOP1Bug : Predicate<"Subtarget->hasCvtFP8VOP1Bug()">; def HasNoCvtFP8VOP1Bug : Predicate<"!Subtarget->hasCvtFP8VOP1Bug()">; +def HasAtomicCsubNoRtnInsts : Predicate<"Subtarget->hasAtomicCsubNoRtnInsts()">; + // Include AMDGPU TD files include "SISchedule.td" include "GCNProcessors.td" diff --git a/llvm/lib/Target/AMDGPU/AMDGPUInstructions.td b/llvm/lib/Target/AMDGPU/AMDGPUInstructions.td index 12ccfd29f26c030..81fc28d293021ab 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUInstructions.td +++ b/llvm/lib/Target/AMDGPU/AMDGPUInstructions.td @@ -621,6 +621,7 @@ defm int_amdgcn_flat_atomic_fadd : global_addr_space_atomic_op; defm int_amdgcn_global_atomic_fadd_v2bf16 : noret_op; defm int_amdgcn_global_atomic_fmin : noret_op; defm int_amdgcn_global_atomic_fmax : noret_op; +defm int_amdgcn_global_atomic_csub : noret_op; defm int_amdgcn_flat_atomic_fadd : local_addr_space_atomic_op; defm int_amdgcn_ds_fadd_v2bf16 : noret_op; diff --git a/llvm/lib/Target/AMDGPU/BUFInstructions.td b/llvm/lib/Target/AMDGPU/BUFInstructions.td index cec35d1147bb0ae..3e71141431d7dc9 100644 --- a/llvm/lib/Target/AMDGPU/BUFInstructions.td +++ b/llvm/lib/Target/AMDGPU/BUFInstructions.td @@ -1022,10 +1022,16 @@ defm BUFFER_ATOMIC_DEC_X2 : MUBUF_Pseudo_Atomics < "buffer_atomic_dec_x2", VReg_64, i64 >; -let SubtargetPredicate = HasGFX10_BEncoding in -defm BUFFER_ATOMIC_CSUB : MUBUF_Pseudo_Atomics_RTN < - "buffer_atomic_csub", VGPR_32, i32, int_amdgcn_global_atomic_csub ->; +let SubtargetPredicate = HasGFX10_BEncoding in { + defm BUFFER_ATOMIC_CSUB : MUBUF_Pseudo_Atomics_RTN < +"buffer_atomic_csub", VGPR_32, i32, int_amdgcn_global_atomic_csub + >; + + let OtherPredicates = [HasAtomicCsubNoRtnInsts] in +defm BUFFER_ATOMIC_CSUB : MUBUF_Pseudo_Atomics_NO_RTN < + "buffer_atomic_csub", VGPR_32, i32 +>; +} let SubtargetPredicate = isGFX8GFX9 in { def BUFFER_STORE_LDS_DWORD : MUBUF_Pseudo_Store_Lds <"buffer_store_lds_dword">; @@ -1561,6 +1567,9 @@ defm : SIBufferAtomicPat<"SIbuffer_atomic_xor", i64, "BUFFER_ATOMIC_XOR_X2">; defm : SIBufferAtomicPat<"SIbuffer_atomic_inc", i64, "BUFFER_ATOMIC_INC_X2">; defm : SIBufferAtomicPat<"SIbuffer_atomic_dec", i64, "BUFFER_ATOMIC_DEC_X2">; +let SubtargetPredicate = HasAtomicCsubNoRtnInsts in +defm : SIBufferAtomicPat<"SIbuffer_atomic_csub", i32, "BUFFER_ATOMIC_CSUB", ["noret"]>; + let SubtargetPredicate = isGFX6GFX7GFX10Plus in { defm : SIBufferAtomicPat<"SIbuffer_atomic_fmin", f32, "BUFFER_ATOMIC_FMIN">; defm : SIBufferAtomicPat<"SIbuffer_atomic_fmax", f32, "BUFFER_ATOMIC_FMAX">; @@ -2491,7 +2500,7 @@ defm BUFFER_ATOMIC_FCMPSWAP_X2 : MUBUF_Real_Atomics_gfx6_gfx7_gfx10<0x05e>; defm BUFFER_ATOMIC_FMIN_X2 : MUBU
[libunwind] [AMDGPU] Add encoding/decoding support for non-result-returning ATOMIC_CSUB instructions (PR #68197)
https://github.com/stepthomas updated https://github.com/llvm/llvm-project/pull/68197 >From ed42bb63a3fe4a840071b74a3f9613dda815aa29 Mon Sep 17 00:00:00 2001 From: Stephen Thomas Date: Wed, 4 Oct 2023 10:16:49 +0100 Subject: [PATCH] [AMDGPU] Add encoding/decoding support for non-result-returning ATOMIC_CSUB instructions The BUFFER_ATOMIC_CSUB and GLOBAL_ATOMIC_CSUB instructions have encodings for non-value-returning forms, although actually using them isn't supported by hardware. However, these encodings aren't supported by the backend, meaning that they can't even be assembled or disassembled. Add support for the non-returning encodings, but gate actually using them in instruction selection behind a new feature FeatureAtomicCsubNoRtnInsts, which no target uses. This does allow the non-returning instructions to be tested manually and llvm.amdgcn.atomic.csub.ll is extended to cover them. The feature does not gate assembling or disassembling them, this is now not an error. --- llvm/lib/Target/AMDGPU/AMDGPU.td | 9 llvm/lib/Target/AMDGPU/AMDGPUInstructions.td | 1 + llvm/lib/Target/AMDGPU/BUFInstructions.td | 19 +-- llvm/lib/Target/AMDGPU/FLATInstructions.td| 18 +-- llvm/lib/Target/AMDGPU/GCNSubtarget.h | 4 ++ llvm/lib/Target/AMDGPU/SIInstrInfo.td | 1 + .../CodeGen/AMDGPU/llvm.amdgcn.atomic.csub.ll | 51 --- llvm/test/MC/AMDGPU/gfx1030_err.s | 6 --- 8 files changed, 85 insertions(+), 24 deletions(-) diff --git a/llvm/lib/Target/AMDGPU/AMDGPU.td b/llvm/lib/Target/AMDGPU/AMDGPU.td index bf5a7b0a96977c7..9ec062d45ba9f48 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPU.td +++ b/llvm/lib/Target/AMDGPU/AMDGPU.td @@ -693,6 +693,13 @@ def FeatureAtomicGlobalPkAddBF16Inst : SubtargetFeature<"atomic-global-pk-add-bf [FeatureFlatGlobalInsts] >; +def FeatureAtomicCsubNoRtnInsts : SubtargetFeature<"atomic-csub-no-rtn-insts", + "HasAtomicCsubNoRtnInsts", + "true", + "Has buffer_atomic_csub and global_atomic_csub instructions that don't " + "return original value" +>; + def FeatureFlatAtomicFaddF32Inst : SubtargetFeature<"flat-atomic-fadd-f32-inst", "HasFlatAtomicFaddF32Inst", @@ -1927,6 +1934,8 @@ def HasGWS : Predicate<"Subtarget->hasGWS()">; def HasCvtFP8VOP1Bug : Predicate<"Subtarget->hasCvtFP8VOP1Bug()">; def HasNoCvtFP8VOP1Bug : Predicate<"!Subtarget->hasCvtFP8VOP1Bug()">; +def HasAtomicCsubNoRtnInsts : Predicate<"Subtarget->hasAtomicCsubNoRtnInsts()">; + // Include AMDGPU TD files include "SISchedule.td" include "GCNProcessors.td" diff --git a/llvm/lib/Target/AMDGPU/AMDGPUInstructions.td b/llvm/lib/Target/AMDGPU/AMDGPUInstructions.td index 12ccfd29f26c030..81fc28d293021ab 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUInstructions.td +++ b/llvm/lib/Target/AMDGPU/AMDGPUInstructions.td @@ -621,6 +621,7 @@ defm int_amdgcn_flat_atomic_fadd : global_addr_space_atomic_op; defm int_amdgcn_global_atomic_fadd_v2bf16 : noret_op; defm int_amdgcn_global_atomic_fmin : noret_op; defm int_amdgcn_global_atomic_fmax : noret_op; +defm int_amdgcn_global_atomic_csub : noret_op; defm int_amdgcn_flat_atomic_fadd : local_addr_space_atomic_op; defm int_amdgcn_ds_fadd_v2bf16 : noret_op; diff --git a/llvm/lib/Target/AMDGPU/BUFInstructions.td b/llvm/lib/Target/AMDGPU/BUFInstructions.td index cec35d1147bb0ae..3e71141431d7dc9 100644 --- a/llvm/lib/Target/AMDGPU/BUFInstructions.td +++ b/llvm/lib/Target/AMDGPU/BUFInstructions.td @@ -1022,10 +1022,16 @@ defm BUFFER_ATOMIC_DEC_X2 : MUBUF_Pseudo_Atomics < "buffer_atomic_dec_x2", VReg_64, i64 >; -let SubtargetPredicate = HasGFX10_BEncoding in -defm BUFFER_ATOMIC_CSUB : MUBUF_Pseudo_Atomics_RTN < - "buffer_atomic_csub", VGPR_32, i32, int_amdgcn_global_atomic_csub ->; +let SubtargetPredicate = HasGFX10_BEncoding in { + defm BUFFER_ATOMIC_CSUB : MUBUF_Pseudo_Atomics_RTN < +"buffer_atomic_csub", VGPR_32, i32, int_amdgcn_global_atomic_csub + >; + + let OtherPredicates = [HasAtomicCsubNoRtnInsts] in +defm BUFFER_ATOMIC_CSUB : MUBUF_Pseudo_Atomics_NO_RTN < + "buffer_atomic_csub", VGPR_32, i32 +>; +} let SubtargetPredicate = isGFX8GFX9 in { def BUFFER_STORE_LDS_DWORD : MUBUF_Pseudo_Store_Lds <"buffer_store_lds_dword">; @@ -1561,6 +1567,9 @@ defm : SIBufferAtomicPat<"SIbuffer_atomic_xor", i64, "BUFFER_ATOMIC_XOR_X2">; defm : SIBufferAtomicPat<"SIbuffer_atomic_inc", i64, "BUFFER_ATOMIC_INC_X2">; defm : SIBufferAtomicPat<"SIbuffer_atomic_dec", i64, "BUFFER_ATOMIC_DEC_X2">; +let SubtargetPredicate = HasAtomicCsubNoRtnInsts in +defm : SIBufferAtomicPat<"SIbuffer_atomic_csub", i32, "BUFFER_ATOMIC_CSUB", ["noret"]>; + let SubtargetPredicate = isGFX6GFX7GFX10Plus in { defm : SIBufferAtomicPat<"SIbuffer_atomic_fmin", f32, "BUFFER_ATOMIC_FMIN">; defm : SIBufferAtomicPat<"SIbuffer_atomic_fmax", f32, "BUFFER_ATOMIC_FMAX">; @@ -2491,7 +2500,7 @@ defm BUFFER_ATOMIC_FCMPSWAP_X2 : MUBUF_Real_Atomics_gfx6_gfx7_gfx10<0x05e>; defm BUFFER_ATOMIC_FMIN_X2 : MUBU
[clang] [InstCombine] Simplify the pattern `a ne/eq (zext/sext (a ne/eq c))` (PR #65852)
https://github.com/dtcxzyw updated https://github.com/llvm/llvm-project/pull/65852 >From d9d8bcbb98e8f5aecb9733329389d61a489bd731 Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Sat, 9 Sep 2023 23:07:29 +0800 Subject: [PATCH 01/10] [InstCombine] Simplify the pattern `a ne/eq (zext (a ne/eq c))` --- .../InstCombine/InstCombineCompares.cpp | 62 ++ .../test/Transforms/InstCombine/icmp-range.ll | 181 ++ 2 files changed, 243 insertions(+) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 9fdc46fec631679..837b8e6d2619989 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -6309,7 +6309,69 @@ Instruction *InstCombinerImpl::foldICmpUsingBoolRange(ICmpInst &I) { Y->getType()->isIntOrIntVectorTy(1) && Pred == ICmpInst::ICMP_ULE) return BinaryOperator::CreateOr(Builder.CreateIsNull(X), Y); + ICmpInst::Predicate Pred1, Pred2; const APInt *C; + // icmp eq/ne X, (zext (icmp eq/ne X, C)) + if (match(&I, m_c_ICmp(Pred1, m_Value(X), + m_ZExt(m_ICmp(Pred2, m_Deferred(X), m_APInt(C) && + ICmpInst::isEquality(Pred1) && ICmpInst::isEquality(Pred2)) { +if (C->isZero()) { + if (Pred2 == ICmpInst::ICMP_EQ) { +// icmp eq X, (zext (icmp eq X, 0)) --> false +// icmp ne X, (zext (icmp eq X, 0)) --> true +return replaceInstUsesWith( +I, +Constant::getIntegerValue( +I.getType(), +APInt(1U, static_cast(Pred1 == ICmpInst::ICMP_NE; + } else { +// icmp eq X, (zext (icmp ne X, 0)) --> icmp ult X, 2 +// icmp ne X, (zext (icmp ne X, 0)) --> icmp ugt X, 1 +return ICmpInst::Create( +Instruction::ICmp, +Pred1 == ICmpInst::ICMP_NE ? ICmpInst::ICMP_UGT + : ICmpInst::ICMP_ULT, +X, +Constant::getIntegerValue( +X->getType(), APInt(X->getType()->getScalarSizeInBits(), +Pred1 == ICmpInst::ICMP_NE ? 1 : 2))); + } +} else if (C->isOne()) { + if (Pred2 == ICmpInst::ICMP_NE) { +// icmp eq X, (zext (icmp ne X, 1)) --> false +// icmp ne X, (zext (icmp ne X, 1)) --> true +return replaceInstUsesWith( +I, +Constant::getIntegerValue( +I.getType(), +APInt(1U, static_cast(Pred1 == ICmpInst::ICMP_NE; + } else { +// icmp eq X, (zext (icmp eq X, 1)) --> icmp ult X, 2 +// icmp ne X, (zext (icmp eq X, 1)) --> icmp ugt X, 1 +return ICmpInst::Create( +Instruction::ICmp, +Pred1 == ICmpInst::ICMP_NE ? ICmpInst::ICMP_UGT + : ICmpInst::ICMP_ULT, +X, +Constant::getIntegerValue( +X->getType(), APInt(X->getType()->getScalarSizeInBits(), +Pred1 == ICmpInst::ICMP_NE ? 1 : 2))); + } +} else { + // C != 0 && C != 1 + // icmp eq X, (zext (icmp eq X, C)) --> icmp eq X, 0 + // icmp eq X, (zext (icmp ne X, C)) --> icmp eq X, 1 + // icmp ne X, (zext (icmp eq X, C)) --> icmp ne X, 0 + // icmp ne X, (zext (icmp ne X, C)) --> icmp ne X, 1 + return ICmpInst::Create( + Instruction::ICmp, Pred1, X, + Constant::getIntegerValue( + X->getType(), + APInt(X->getType()->getScalarSizeInBits(), +static_cast(Pred2 == ICmpInst::ICMP_NE; +} + } + if (match(I.getOperand(0), m_c_Add(m_ZExt(m_Value(X)), m_SExt(m_Value(Y && match(I.getOperand(1), m_APInt(C)) && X->getType()->isIntOrIntVectorTy(1) && diff --git a/llvm/test/Transforms/InstCombine/icmp-range.ll b/llvm/test/Transforms/InstCombine/icmp-range.ll index 4281e09cb0309c8..15424fce33fdeea 100644 --- a/llvm/test/Transforms/InstCombine/icmp-range.ll +++ b/llvm/test/Transforms/InstCombine/icmp-range.ll @@ -1034,6 +1034,187 @@ define i1 @icmp_ne_bool_1(ptr %ptr) { ret i1 %cmp } +define i1 @icmp_ne_zext_eq_zero(i32 %a) { +; CHECK-LABEL: @icmp_ne_zext_eq_zero( +; CHECK-NEXT:ret i1 true +; + %cmp = icmp eq i32 %a, 0 + %conv = zext i1 %cmp to i32 + %cmp1 = icmp ne i32 %conv, %a + ret i1 %cmp1 +} + +define i1 @icmp_ne_zext_ne_zero(i32 %a) { +; CHECK-LABEL: @icmp_ne_zext_ne_zero( +; CHECK-NEXT:[[CMP1:%.*]] = icmp ugt i32 [[A:%.*]], 1 +; CHECK-NEXT:ret i1 [[CMP1]] +; + %cmp = icmp ne i32 %a, 0 + %conv = zext i1 %cmp to i32 + %cmp1 = icmp ne i32 %conv, %a + ret i1 %cmp1 +} + +define i1 @icmp_eq_zext_eq_zero(i32 %a) { +; CHECK-LABEL: @icmp_eq_zext_eq_zero( +; CHECK-NEXT:ret i1 false +; + %cmp = icmp eq i32 %a, 0 + %conv = zext i1 %cmp to i32 + %cmp1 = icmp eq i32 %conv, %a + ret i1 %cmp1 +} + +define i1 @icmp_eq_zext_ne_zero(i32
[clang-tools-extra] [InstCombine] Simplify the pattern `a ne/eq (zext/sext (a ne/eq c))` (PR #65852)
https://github.com/dtcxzyw updated https://github.com/llvm/llvm-project/pull/65852 >From d9d8bcbb98e8f5aecb9733329389d61a489bd731 Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Sat, 9 Sep 2023 23:07:29 +0800 Subject: [PATCH 01/10] [InstCombine] Simplify the pattern `a ne/eq (zext (a ne/eq c))` --- .../InstCombine/InstCombineCompares.cpp | 62 ++ .../test/Transforms/InstCombine/icmp-range.ll | 181 ++ 2 files changed, 243 insertions(+) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 9fdc46fec631679..837b8e6d2619989 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -6309,7 +6309,69 @@ Instruction *InstCombinerImpl::foldICmpUsingBoolRange(ICmpInst &I) { Y->getType()->isIntOrIntVectorTy(1) && Pred == ICmpInst::ICMP_ULE) return BinaryOperator::CreateOr(Builder.CreateIsNull(X), Y); + ICmpInst::Predicate Pred1, Pred2; const APInt *C; + // icmp eq/ne X, (zext (icmp eq/ne X, C)) + if (match(&I, m_c_ICmp(Pred1, m_Value(X), + m_ZExt(m_ICmp(Pred2, m_Deferred(X), m_APInt(C) && + ICmpInst::isEquality(Pred1) && ICmpInst::isEquality(Pred2)) { +if (C->isZero()) { + if (Pred2 == ICmpInst::ICMP_EQ) { +// icmp eq X, (zext (icmp eq X, 0)) --> false +// icmp ne X, (zext (icmp eq X, 0)) --> true +return replaceInstUsesWith( +I, +Constant::getIntegerValue( +I.getType(), +APInt(1U, static_cast(Pred1 == ICmpInst::ICMP_NE; + } else { +// icmp eq X, (zext (icmp ne X, 0)) --> icmp ult X, 2 +// icmp ne X, (zext (icmp ne X, 0)) --> icmp ugt X, 1 +return ICmpInst::Create( +Instruction::ICmp, +Pred1 == ICmpInst::ICMP_NE ? ICmpInst::ICMP_UGT + : ICmpInst::ICMP_ULT, +X, +Constant::getIntegerValue( +X->getType(), APInt(X->getType()->getScalarSizeInBits(), +Pred1 == ICmpInst::ICMP_NE ? 1 : 2))); + } +} else if (C->isOne()) { + if (Pred2 == ICmpInst::ICMP_NE) { +// icmp eq X, (zext (icmp ne X, 1)) --> false +// icmp ne X, (zext (icmp ne X, 1)) --> true +return replaceInstUsesWith( +I, +Constant::getIntegerValue( +I.getType(), +APInt(1U, static_cast(Pred1 == ICmpInst::ICMP_NE; + } else { +// icmp eq X, (zext (icmp eq X, 1)) --> icmp ult X, 2 +// icmp ne X, (zext (icmp eq X, 1)) --> icmp ugt X, 1 +return ICmpInst::Create( +Instruction::ICmp, +Pred1 == ICmpInst::ICMP_NE ? ICmpInst::ICMP_UGT + : ICmpInst::ICMP_ULT, +X, +Constant::getIntegerValue( +X->getType(), APInt(X->getType()->getScalarSizeInBits(), +Pred1 == ICmpInst::ICMP_NE ? 1 : 2))); + } +} else { + // C != 0 && C != 1 + // icmp eq X, (zext (icmp eq X, C)) --> icmp eq X, 0 + // icmp eq X, (zext (icmp ne X, C)) --> icmp eq X, 1 + // icmp ne X, (zext (icmp eq X, C)) --> icmp ne X, 0 + // icmp ne X, (zext (icmp ne X, C)) --> icmp ne X, 1 + return ICmpInst::Create( + Instruction::ICmp, Pred1, X, + Constant::getIntegerValue( + X->getType(), + APInt(X->getType()->getScalarSizeInBits(), +static_cast(Pred2 == ICmpInst::ICMP_NE; +} + } + if (match(I.getOperand(0), m_c_Add(m_ZExt(m_Value(X)), m_SExt(m_Value(Y && match(I.getOperand(1), m_APInt(C)) && X->getType()->isIntOrIntVectorTy(1) && diff --git a/llvm/test/Transforms/InstCombine/icmp-range.ll b/llvm/test/Transforms/InstCombine/icmp-range.ll index 4281e09cb0309c8..15424fce33fdeea 100644 --- a/llvm/test/Transforms/InstCombine/icmp-range.ll +++ b/llvm/test/Transforms/InstCombine/icmp-range.ll @@ -1034,6 +1034,187 @@ define i1 @icmp_ne_bool_1(ptr %ptr) { ret i1 %cmp } +define i1 @icmp_ne_zext_eq_zero(i32 %a) { +; CHECK-LABEL: @icmp_ne_zext_eq_zero( +; CHECK-NEXT:ret i1 true +; + %cmp = icmp eq i32 %a, 0 + %conv = zext i1 %cmp to i32 + %cmp1 = icmp ne i32 %conv, %a + ret i1 %cmp1 +} + +define i1 @icmp_ne_zext_ne_zero(i32 %a) { +; CHECK-LABEL: @icmp_ne_zext_ne_zero( +; CHECK-NEXT:[[CMP1:%.*]] = icmp ugt i32 [[A:%.*]], 1 +; CHECK-NEXT:ret i1 [[CMP1]] +; + %cmp = icmp ne i32 %a, 0 + %conv = zext i1 %cmp to i32 + %cmp1 = icmp ne i32 %conv, %a + ret i1 %cmp1 +} + +define i1 @icmp_eq_zext_eq_zero(i32 %a) { +; CHECK-LABEL: @icmp_eq_zext_eq_zero( +; CHECK-NEXT:ret i1 false +; + %cmp = icmp eq i32 %a, 0 + %conv = zext i1 %cmp to i32 + %cmp1 = icmp eq i32 %conv, %a + ret i1 %cmp1 +} + +define i1 @icmp_eq_zext_ne_zero(i32
[clang] [InstCombine] Canonicalize `(X +/- Y) & Y` into `~X & Y` when Y is a power of 2 (PR #67915)
https://github.com/dtcxzyw updated https://github.com/llvm/llvm-project/pull/67915 >From c4ce28c942c172e5646b5922f0b02b4169197840 Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Sun, 1 Oct 2023 21:52:47 +0800 Subject: [PATCH 1/2] [InstCombine] Canonicalize `(X +/- Y) & Y` into `~X & Y` when Y is a power of 2 --- .../InstCombine/InstCombineAndOrXor.cpp | 8 llvm/test/Transforms/InstCombine/and.ll | 44 +-- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index cbdab3e9c5fb91d..4322cc96f5a2b6c 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -2250,6 +2250,14 @@ Instruction *InstCombinerImpl::visitAnd(BinaryOperator &I) { return SelectInst::Create(Cmp, ConstantInt::getNullValue(Ty), Y); } + // Canonicalize: + // (X +/- Y) & Y --> ~X & Y when Y is a power of 2. + if (match(&I, m_c_And(m_Value(Y), m_OneUse(m_CombineOr( +m_c_Add(m_Value(X), m_Deferred(Y)), +m_Sub(m_Value(X), m_Deferred(Y)) && + isKnownToBeAPowerOfTwo(Y, /*OrZero*/ true, /*Depth*/ 0, &I)) +return BinaryOperator::CreateAnd(Builder.CreateNot(X), Y); + const APInt *C; if (match(Op1, m_APInt(C))) { const APInt *XorC; diff --git a/llvm/test/Transforms/InstCombine/and.ll b/llvm/test/Transforms/InstCombine/and.ll index 90f027010e2aea6..eb39ff9014ff3a4 100644 --- a/llvm/test/Transforms/InstCombine/and.ll +++ b/llvm/test/Transforms/InstCombine/and.ll @@ -1595,8 +1595,8 @@ define <2 x i8> @flip_masked_bit_uniform(<2 x i8> %A) { define <2 x i8> @flip_masked_bit_undef(<2 x i8> %A) { ; CHECK-LABEL: @flip_masked_bit_undef( -; CHECK-NEXT:[[B:%.*]] = add <2 x i8> [[A:%.*]], -; CHECK-NEXT:[[C:%.*]] = and <2 x i8> [[B]], +; CHECK-NEXT:[[TMP1:%.*]] = xor <2 x i8> [[A:%.*]], +; CHECK-NEXT:[[C:%.*]] = and <2 x i8> [[TMP1]], ; CHECK-NEXT:ret <2 x i8> [[C]] ; %B = add <2 x i8> %A, @@ -1606,8 +1606,8 @@ define <2 x i8> @flip_masked_bit_undef(<2 x i8> %A) { define <2 x i8> @flip_masked_bit_nonuniform(<2 x i8> %A) { ; CHECK-LABEL: @flip_masked_bit_nonuniform( -; CHECK-NEXT:[[B:%.*]] = add <2 x i8> [[A:%.*]], -; CHECK-NEXT:[[C:%.*]] = and <2 x i8> [[B]], +; CHECK-NEXT:[[TMP1:%.*]] = xor <2 x i8> [[A:%.*]], +; CHECK-NEXT:[[C:%.*]] = and <2 x i8> [[TMP1]], ; CHECK-NEXT:ret <2 x i8> [[C]] ; %B = add <2 x i8> %A, @@ -2546,3 +2546,39 @@ define i32 @and_zext_eq_zero(i32 %A, i32 %C) { %5 = and i32 %2, %4 ret i32 %5 } + +define i32 @canonicalize_and_add_power2_or_zero(i32 %x, i32 %y) { +; CHECK-LABEL: @canonicalize_and_add_power2_or_zero( +; CHECK-NEXT:[[NY:%.*]] = sub i32 0, [[Y:%.*]] +; CHECK-NEXT:[[P2:%.*]] = and i32 [[NY]], [[Y]] +; CHECK-NEXT:call void @use32(i32 [[P2]]) +; CHECK-NEXT:[[TMP1:%.*]] = xor i32 [[X:%.*]], -1 +; CHECK-NEXT:[[AND:%.*]] = and i32 [[P2]], [[TMP1]] +; CHECK-NEXT:ret i32 [[AND]] +; + %ny = sub i32 0, %y + %p2 = and i32 %y, %ny + call void @use32(i32 %p2) ; keep p2 + + %val = add i32 %x, %p2 + %and = and i32 %val, %p2 + ret i32 %and +} + +define i32 @canonicalize_and_sub_power2_or_zero(i32 %x, i32 %y) { +; CHECK-LABEL: @canonicalize_and_sub_power2_or_zero( +; CHECK-NEXT:[[NY:%.*]] = sub i32 0, [[Y:%.*]] +; CHECK-NEXT:[[P2:%.*]] = and i32 [[NY]], [[Y]] +; CHECK-NEXT:call void @use32(i32 [[P2]]) +; CHECK-NEXT:[[TMP1:%.*]] = xor i32 [[X:%.*]], -1 +; CHECK-NEXT:[[AND:%.*]] = and i32 [[P2]], [[TMP1]] +; CHECK-NEXT:ret i32 [[AND]] +; + %ny = sub i32 0, %y + %p2 = and i32 %y, %ny + call void @use32(i32 %p2) ; keep p2 + + %val = sub i32 %x, %p2 + %and = and i32 %val, %p2 + ret i32 %and +} >From b64ca5b5f743e6a935f4ea09154c3a08c6e65c47 Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Fri, 6 Oct 2023 17:32:46 +0800 Subject: [PATCH 2/2] fixup! [InstCombine] Canonicalize `(X +/- Y) & Y` into `~X & Y` when Y is a power of 2 Add additional tests. --- llvm/test/Transforms/InstCombine/and.ll | 123 1 file changed, 123 insertions(+) diff --git a/llvm/test/Transforms/InstCombine/and.ll b/llvm/test/Transforms/InstCombine/and.ll index eb39ff9014ff3a4..989640ed41f2d2e 100644 --- a/llvm/test/Transforms/InstCombine/and.ll +++ b/llvm/test/Transforms/InstCombine/and.ll @@ -2582,3 +2582,126 @@ define i32 @canonicalize_and_sub_power2_or_zero(i32 %x, i32 %y) { %and = and i32 %val, %p2 ret i32 %and } + +define i32 @canonicalize_and_add_power2_or_zero_commuted1(i32 %x, i32 %y) { +; CHECK-LABEL: @canonicalize_and_add_power2_or_zero_commuted1( +; CHECK-NEXT:[[NY:%.*]] = sub i32 0, [[Y:%.*]] +; CHECK-NEXT:[[P2:%.*]] = and i32 [[NY]], [[Y]] +; CHECK-NEXT:call void @use32(i32 [[P2]]) +; CHECK-NEXT:[[TMP1:%.*]] = xor i32 [[X:%.
[clang] [clang] Replace uses of CreatePointerBitCastOrAddrSpaceCast (NFC) (PR #68277)
@@ -1123,9 +1123,7 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (!CurFnInfo->getReturnInfo().getIndirectByVal()) { ReturnValuePointer = CreateDefaultAlignTempAlloca(Int8PtrTy, "result.ptr"); - Builder.CreateStore(Builder.CreatePointerBitCastOrAddrSpaceCast( - ReturnValue.getPointer(), Int8PtrTy), - ReturnValuePointer); + Builder.CreateStore(ReturnValue.getPointer(), ReturnValuePointer); bjope wrote: So `ReturnValue.getPointer()` is guaranteed to be an unqualified pointer? I'm just wondering why this hasn't been just a pointer bitcast in the past. But even if it would cast away an address space it seems a bit weird. Not sure if it is worth an assert now when we bypass all the castIsValid checks etc that would have been done in the past. (And maybe the "result.ptr" should be created with `ReturnValue.getPointer().getType()` rather than using Int8PtrTy. Although I consider that as out of scope for this patch.) https://github.com/llvm/llvm-project/pull/68277 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][libc] Fix namespace check with macro (PR #68134)
https://github.com/gchatelet approved this pull request. https://github.com/llvm/llvm-project/pull/68134 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [InstCombine] Canonicalize `(X +/- Y) & Y` into `~X & Y` when Y is a power of 2 (PR #67915)
nikic wrote: Can you please pre-commit the new tests as well (and double-check that there is no unexpected operand order canonicalization while doing that)? https://github.com/llvm/llvm-project/pull/67915 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [InstCombine] Simplify the pattern `a ne/eq (zext/sext (a ne/eq c))` (PR #65852)
https://github.com/matthias-springer updated https://github.com/llvm/llvm-project/pull/65852 >From d9d8bcbb98e8f5aecb9733329389d61a489bd731 Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Sat, 9 Sep 2023 23:07:29 +0800 Subject: [PATCH 01/10] [InstCombine] Simplify the pattern `a ne/eq (zext (a ne/eq c))` --- .../InstCombine/InstCombineCompares.cpp | 62 ++ .../test/Transforms/InstCombine/icmp-range.ll | 181 ++ 2 files changed, 243 insertions(+) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 9fdc46fec631679..837b8e6d2619989 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -6309,7 +6309,69 @@ Instruction *InstCombinerImpl::foldICmpUsingBoolRange(ICmpInst &I) { Y->getType()->isIntOrIntVectorTy(1) && Pred == ICmpInst::ICMP_ULE) return BinaryOperator::CreateOr(Builder.CreateIsNull(X), Y); + ICmpInst::Predicate Pred1, Pred2; const APInt *C; + // icmp eq/ne X, (zext (icmp eq/ne X, C)) + if (match(&I, m_c_ICmp(Pred1, m_Value(X), + m_ZExt(m_ICmp(Pred2, m_Deferred(X), m_APInt(C) && + ICmpInst::isEquality(Pred1) && ICmpInst::isEquality(Pred2)) { +if (C->isZero()) { + if (Pred2 == ICmpInst::ICMP_EQ) { +// icmp eq X, (zext (icmp eq X, 0)) --> false +// icmp ne X, (zext (icmp eq X, 0)) --> true +return replaceInstUsesWith( +I, +Constant::getIntegerValue( +I.getType(), +APInt(1U, static_cast(Pred1 == ICmpInst::ICMP_NE; + } else { +// icmp eq X, (zext (icmp ne X, 0)) --> icmp ult X, 2 +// icmp ne X, (zext (icmp ne X, 0)) --> icmp ugt X, 1 +return ICmpInst::Create( +Instruction::ICmp, +Pred1 == ICmpInst::ICMP_NE ? ICmpInst::ICMP_UGT + : ICmpInst::ICMP_ULT, +X, +Constant::getIntegerValue( +X->getType(), APInt(X->getType()->getScalarSizeInBits(), +Pred1 == ICmpInst::ICMP_NE ? 1 : 2))); + } +} else if (C->isOne()) { + if (Pred2 == ICmpInst::ICMP_NE) { +// icmp eq X, (zext (icmp ne X, 1)) --> false +// icmp ne X, (zext (icmp ne X, 1)) --> true +return replaceInstUsesWith( +I, +Constant::getIntegerValue( +I.getType(), +APInt(1U, static_cast(Pred1 == ICmpInst::ICMP_NE; + } else { +// icmp eq X, (zext (icmp eq X, 1)) --> icmp ult X, 2 +// icmp ne X, (zext (icmp eq X, 1)) --> icmp ugt X, 1 +return ICmpInst::Create( +Instruction::ICmp, +Pred1 == ICmpInst::ICMP_NE ? ICmpInst::ICMP_UGT + : ICmpInst::ICMP_ULT, +X, +Constant::getIntegerValue( +X->getType(), APInt(X->getType()->getScalarSizeInBits(), +Pred1 == ICmpInst::ICMP_NE ? 1 : 2))); + } +} else { + // C != 0 && C != 1 + // icmp eq X, (zext (icmp eq X, C)) --> icmp eq X, 0 + // icmp eq X, (zext (icmp ne X, C)) --> icmp eq X, 1 + // icmp ne X, (zext (icmp eq X, C)) --> icmp ne X, 0 + // icmp ne X, (zext (icmp ne X, C)) --> icmp ne X, 1 + return ICmpInst::Create( + Instruction::ICmp, Pred1, X, + Constant::getIntegerValue( + X->getType(), + APInt(X->getType()->getScalarSizeInBits(), +static_cast(Pred2 == ICmpInst::ICMP_NE; +} + } + if (match(I.getOperand(0), m_c_Add(m_ZExt(m_Value(X)), m_SExt(m_Value(Y && match(I.getOperand(1), m_APInt(C)) && X->getType()->isIntOrIntVectorTy(1) && diff --git a/llvm/test/Transforms/InstCombine/icmp-range.ll b/llvm/test/Transforms/InstCombine/icmp-range.ll index 4281e09cb0309c8..15424fce33fdeea 100644 --- a/llvm/test/Transforms/InstCombine/icmp-range.ll +++ b/llvm/test/Transforms/InstCombine/icmp-range.ll @@ -1034,6 +1034,187 @@ define i1 @icmp_ne_bool_1(ptr %ptr) { ret i1 %cmp } +define i1 @icmp_ne_zext_eq_zero(i32 %a) { +; CHECK-LABEL: @icmp_ne_zext_eq_zero( +; CHECK-NEXT:ret i1 true +; + %cmp = icmp eq i32 %a, 0 + %conv = zext i1 %cmp to i32 + %cmp1 = icmp ne i32 %conv, %a + ret i1 %cmp1 +} + +define i1 @icmp_ne_zext_ne_zero(i32 %a) { +; CHECK-LABEL: @icmp_ne_zext_ne_zero( +; CHECK-NEXT:[[CMP1:%.*]] = icmp ugt i32 [[A:%.*]], 1 +; CHECK-NEXT:ret i1 [[CMP1]] +; + %cmp = icmp ne i32 %a, 0 + %conv = zext i1 %cmp to i32 + %cmp1 = icmp ne i32 %conv, %a + ret i1 %cmp1 +} + +define i1 @icmp_eq_zext_eq_zero(i32 %a) { +; CHECK-LABEL: @icmp_eq_zext_eq_zero( +; CHECK-NEXT:ret i1 false +; + %cmp = icmp eq i32 %a, 0 + %conv = zext i1 %cmp to i32 + %cmp1 = icmp eq i32 %conv, %a + ret i1 %cmp1 +} + +define i1 @icmp_eq_zext_n
[clang] [InstCombine] Simplify the pattern `a ne/eq (zext/sext (a ne/eq c))` (PR #65852)
https://github.com/dtcxzyw updated https://github.com/llvm/llvm-project/pull/65852 >From d9d8bcbb98e8f5aecb9733329389d61a489bd731 Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Sat, 9 Sep 2023 23:07:29 +0800 Subject: [PATCH 01/10] [InstCombine] Simplify the pattern `a ne/eq (zext (a ne/eq c))` --- .../InstCombine/InstCombineCompares.cpp | 62 ++ .../test/Transforms/InstCombine/icmp-range.ll | 181 ++ 2 files changed, 243 insertions(+) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 9fdc46fec631679..837b8e6d2619989 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -6309,7 +6309,69 @@ Instruction *InstCombinerImpl::foldICmpUsingBoolRange(ICmpInst &I) { Y->getType()->isIntOrIntVectorTy(1) && Pred == ICmpInst::ICMP_ULE) return BinaryOperator::CreateOr(Builder.CreateIsNull(X), Y); + ICmpInst::Predicate Pred1, Pred2; const APInt *C; + // icmp eq/ne X, (zext (icmp eq/ne X, C)) + if (match(&I, m_c_ICmp(Pred1, m_Value(X), + m_ZExt(m_ICmp(Pred2, m_Deferred(X), m_APInt(C) && + ICmpInst::isEquality(Pred1) && ICmpInst::isEquality(Pred2)) { +if (C->isZero()) { + if (Pred2 == ICmpInst::ICMP_EQ) { +// icmp eq X, (zext (icmp eq X, 0)) --> false +// icmp ne X, (zext (icmp eq X, 0)) --> true +return replaceInstUsesWith( +I, +Constant::getIntegerValue( +I.getType(), +APInt(1U, static_cast(Pred1 == ICmpInst::ICMP_NE; + } else { +// icmp eq X, (zext (icmp ne X, 0)) --> icmp ult X, 2 +// icmp ne X, (zext (icmp ne X, 0)) --> icmp ugt X, 1 +return ICmpInst::Create( +Instruction::ICmp, +Pred1 == ICmpInst::ICMP_NE ? ICmpInst::ICMP_UGT + : ICmpInst::ICMP_ULT, +X, +Constant::getIntegerValue( +X->getType(), APInt(X->getType()->getScalarSizeInBits(), +Pred1 == ICmpInst::ICMP_NE ? 1 : 2))); + } +} else if (C->isOne()) { + if (Pred2 == ICmpInst::ICMP_NE) { +// icmp eq X, (zext (icmp ne X, 1)) --> false +// icmp ne X, (zext (icmp ne X, 1)) --> true +return replaceInstUsesWith( +I, +Constant::getIntegerValue( +I.getType(), +APInt(1U, static_cast(Pred1 == ICmpInst::ICMP_NE; + } else { +// icmp eq X, (zext (icmp eq X, 1)) --> icmp ult X, 2 +// icmp ne X, (zext (icmp eq X, 1)) --> icmp ugt X, 1 +return ICmpInst::Create( +Instruction::ICmp, +Pred1 == ICmpInst::ICMP_NE ? ICmpInst::ICMP_UGT + : ICmpInst::ICMP_ULT, +X, +Constant::getIntegerValue( +X->getType(), APInt(X->getType()->getScalarSizeInBits(), +Pred1 == ICmpInst::ICMP_NE ? 1 : 2))); + } +} else { + // C != 0 && C != 1 + // icmp eq X, (zext (icmp eq X, C)) --> icmp eq X, 0 + // icmp eq X, (zext (icmp ne X, C)) --> icmp eq X, 1 + // icmp ne X, (zext (icmp eq X, C)) --> icmp ne X, 0 + // icmp ne X, (zext (icmp ne X, C)) --> icmp ne X, 1 + return ICmpInst::Create( + Instruction::ICmp, Pred1, X, + Constant::getIntegerValue( + X->getType(), + APInt(X->getType()->getScalarSizeInBits(), +static_cast(Pred2 == ICmpInst::ICMP_NE; +} + } + if (match(I.getOperand(0), m_c_Add(m_ZExt(m_Value(X)), m_SExt(m_Value(Y && match(I.getOperand(1), m_APInt(C)) && X->getType()->isIntOrIntVectorTy(1) && diff --git a/llvm/test/Transforms/InstCombine/icmp-range.ll b/llvm/test/Transforms/InstCombine/icmp-range.ll index 4281e09cb0309c8..15424fce33fdeea 100644 --- a/llvm/test/Transforms/InstCombine/icmp-range.ll +++ b/llvm/test/Transforms/InstCombine/icmp-range.ll @@ -1034,6 +1034,187 @@ define i1 @icmp_ne_bool_1(ptr %ptr) { ret i1 %cmp } +define i1 @icmp_ne_zext_eq_zero(i32 %a) { +; CHECK-LABEL: @icmp_ne_zext_eq_zero( +; CHECK-NEXT:ret i1 true +; + %cmp = icmp eq i32 %a, 0 + %conv = zext i1 %cmp to i32 + %cmp1 = icmp ne i32 %conv, %a + ret i1 %cmp1 +} + +define i1 @icmp_ne_zext_ne_zero(i32 %a) { +; CHECK-LABEL: @icmp_ne_zext_ne_zero( +; CHECK-NEXT:[[CMP1:%.*]] = icmp ugt i32 [[A:%.*]], 1 +; CHECK-NEXT:ret i1 [[CMP1]] +; + %cmp = icmp ne i32 %a, 0 + %conv = zext i1 %cmp to i32 + %cmp1 = icmp ne i32 %conv, %a + ret i1 %cmp1 +} + +define i1 @icmp_eq_zext_eq_zero(i32 %a) { +; CHECK-LABEL: @icmp_eq_zext_eq_zero( +; CHECK-NEXT:ret i1 false +; + %cmp = icmp eq i32 %a, 0 + %conv = zext i1 %cmp to i32 + %cmp1 = icmp eq i32 %conv, %a + ret i1 %cmp1 +} + +define i1 @icmp_eq_zext_ne_zero(i32
[clang-tools-extra] [InstCombine] Simplify the pattern `a ne/eq (zext/sext (a ne/eq c))` (PR #65852)
https://github.com/matthias-springer updated https://github.com/llvm/llvm-project/pull/65852 >From d9d8bcbb98e8f5aecb9733329389d61a489bd731 Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Sat, 9 Sep 2023 23:07:29 +0800 Subject: [PATCH 01/10] [InstCombine] Simplify the pattern `a ne/eq (zext (a ne/eq c))` --- .../InstCombine/InstCombineCompares.cpp | 62 ++ .../test/Transforms/InstCombine/icmp-range.ll | 181 ++ 2 files changed, 243 insertions(+) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 9fdc46fec631679..837b8e6d2619989 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -6309,7 +6309,69 @@ Instruction *InstCombinerImpl::foldICmpUsingBoolRange(ICmpInst &I) { Y->getType()->isIntOrIntVectorTy(1) && Pred == ICmpInst::ICMP_ULE) return BinaryOperator::CreateOr(Builder.CreateIsNull(X), Y); + ICmpInst::Predicate Pred1, Pred2; const APInt *C; + // icmp eq/ne X, (zext (icmp eq/ne X, C)) + if (match(&I, m_c_ICmp(Pred1, m_Value(X), + m_ZExt(m_ICmp(Pred2, m_Deferred(X), m_APInt(C) && + ICmpInst::isEquality(Pred1) && ICmpInst::isEquality(Pred2)) { +if (C->isZero()) { + if (Pred2 == ICmpInst::ICMP_EQ) { +// icmp eq X, (zext (icmp eq X, 0)) --> false +// icmp ne X, (zext (icmp eq X, 0)) --> true +return replaceInstUsesWith( +I, +Constant::getIntegerValue( +I.getType(), +APInt(1U, static_cast(Pred1 == ICmpInst::ICMP_NE; + } else { +// icmp eq X, (zext (icmp ne X, 0)) --> icmp ult X, 2 +// icmp ne X, (zext (icmp ne X, 0)) --> icmp ugt X, 1 +return ICmpInst::Create( +Instruction::ICmp, +Pred1 == ICmpInst::ICMP_NE ? ICmpInst::ICMP_UGT + : ICmpInst::ICMP_ULT, +X, +Constant::getIntegerValue( +X->getType(), APInt(X->getType()->getScalarSizeInBits(), +Pred1 == ICmpInst::ICMP_NE ? 1 : 2))); + } +} else if (C->isOne()) { + if (Pred2 == ICmpInst::ICMP_NE) { +// icmp eq X, (zext (icmp ne X, 1)) --> false +// icmp ne X, (zext (icmp ne X, 1)) --> true +return replaceInstUsesWith( +I, +Constant::getIntegerValue( +I.getType(), +APInt(1U, static_cast(Pred1 == ICmpInst::ICMP_NE; + } else { +// icmp eq X, (zext (icmp eq X, 1)) --> icmp ult X, 2 +// icmp ne X, (zext (icmp eq X, 1)) --> icmp ugt X, 1 +return ICmpInst::Create( +Instruction::ICmp, +Pred1 == ICmpInst::ICMP_NE ? ICmpInst::ICMP_UGT + : ICmpInst::ICMP_ULT, +X, +Constant::getIntegerValue( +X->getType(), APInt(X->getType()->getScalarSizeInBits(), +Pred1 == ICmpInst::ICMP_NE ? 1 : 2))); + } +} else { + // C != 0 && C != 1 + // icmp eq X, (zext (icmp eq X, C)) --> icmp eq X, 0 + // icmp eq X, (zext (icmp ne X, C)) --> icmp eq X, 1 + // icmp ne X, (zext (icmp eq X, C)) --> icmp ne X, 0 + // icmp ne X, (zext (icmp ne X, C)) --> icmp ne X, 1 + return ICmpInst::Create( + Instruction::ICmp, Pred1, X, + Constant::getIntegerValue( + X->getType(), + APInt(X->getType()->getScalarSizeInBits(), +static_cast(Pred2 == ICmpInst::ICMP_NE; +} + } + if (match(I.getOperand(0), m_c_Add(m_ZExt(m_Value(X)), m_SExt(m_Value(Y && match(I.getOperand(1), m_APInt(C)) && X->getType()->isIntOrIntVectorTy(1) && diff --git a/llvm/test/Transforms/InstCombine/icmp-range.ll b/llvm/test/Transforms/InstCombine/icmp-range.ll index 4281e09cb0309c8..15424fce33fdeea 100644 --- a/llvm/test/Transforms/InstCombine/icmp-range.ll +++ b/llvm/test/Transforms/InstCombine/icmp-range.ll @@ -1034,6 +1034,187 @@ define i1 @icmp_ne_bool_1(ptr %ptr) { ret i1 %cmp } +define i1 @icmp_ne_zext_eq_zero(i32 %a) { +; CHECK-LABEL: @icmp_ne_zext_eq_zero( +; CHECK-NEXT:ret i1 true +; + %cmp = icmp eq i32 %a, 0 + %conv = zext i1 %cmp to i32 + %cmp1 = icmp ne i32 %conv, %a + ret i1 %cmp1 +} + +define i1 @icmp_ne_zext_ne_zero(i32 %a) { +; CHECK-LABEL: @icmp_ne_zext_ne_zero( +; CHECK-NEXT:[[CMP1:%.*]] = icmp ugt i32 [[A:%.*]], 1 +; CHECK-NEXT:ret i1 [[CMP1]] +; + %cmp = icmp ne i32 %a, 0 + %conv = zext i1 %cmp to i32 + %cmp1 = icmp ne i32 %conv, %a + ret i1 %cmp1 +} + +define i1 @icmp_eq_zext_eq_zero(i32 %a) { +; CHECK-LABEL: @icmp_eq_zext_eq_zero( +; CHECK-NEXT:ret i1 false +; + %cmp = icmp eq i32 %a, 0 + %conv = zext i1 %cmp to i32 + %cmp1 = icmp eq i32 %conv, %a + ret i1 %cmp1 +} + +define i1 @icmp_eq_zext_n
[clang-tools-extra] [InstCombine] Simplify the pattern `a ne/eq (zext/sext (a ne/eq c))` (PR #65852)
https://github.com/dtcxzyw updated https://github.com/llvm/llvm-project/pull/65852 >From d9d8bcbb98e8f5aecb9733329389d61a489bd731 Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Sat, 9 Sep 2023 23:07:29 +0800 Subject: [PATCH 01/10] [InstCombine] Simplify the pattern `a ne/eq (zext (a ne/eq c))` --- .../InstCombine/InstCombineCompares.cpp | 62 ++ .../test/Transforms/InstCombine/icmp-range.ll | 181 ++ 2 files changed, 243 insertions(+) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 9fdc46fec631679..837b8e6d2619989 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -6309,7 +6309,69 @@ Instruction *InstCombinerImpl::foldICmpUsingBoolRange(ICmpInst &I) { Y->getType()->isIntOrIntVectorTy(1) && Pred == ICmpInst::ICMP_ULE) return BinaryOperator::CreateOr(Builder.CreateIsNull(X), Y); + ICmpInst::Predicate Pred1, Pred2; const APInt *C; + // icmp eq/ne X, (zext (icmp eq/ne X, C)) + if (match(&I, m_c_ICmp(Pred1, m_Value(X), + m_ZExt(m_ICmp(Pred2, m_Deferred(X), m_APInt(C) && + ICmpInst::isEquality(Pred1) && ICmpInst::isEquality(Pred2)) { +if (C->isZero()) { + if (Pred2 == ICmpInst::ICMP_EQ) { +// icmp eq X, (zext (icmp eq X, 0)) --> false +// icmp ne X, (zext (icmp eq X, 0)) --> true +return replaceInstUsesWith( +I, +Constant::getIntegerValue( +I.getType(), +APInt(1U, static_cast(Pred1 == ICmpInst::ICMP_NE; + } else { +// icmp eq X, (zext (icmp ne X, 0)) --> icmp ult X, 2 +// icmp ne X, (zext (icmp ne X, 0)) --> icmp ugt X, 1 +return ICmpInst::Create( +Instruction::ICmp, +Pred1 == ICmpInst::ICMP_NE ? ICmpInst::ICMP_UGT + : ICmpInst::ICMP_ULT, +X, +Constant::getIntegerValue( +X->getType(), APInt(X->getType()->getScalarSizeInBits(), +Pred1 == ICmpInst::ICMP_NE ? 1 : 2))); + } +} else if (C->isOne()) { + if (Pred2 == ICmpInst::ICMP_NE) { +// icmp eq X, (zext (icmp ne X, 1)) --> false +// icmp ne X, (zext (icmp ne X, 1)) --> true +return replaceInstUsesWith( +I, +Constant::getIntegerValue( +I.getType(), +APInt(1U, static_cast(Pred1 == ICmpInst::ICMP_NE; + } else { +// icmp eq X, (zext (icmp eq X, 1)) --> icmp ult X, 2 +// icmp ne X, (zext (icmp eq X, 1)) --> icmp ugt X, 1 +return ICmpInst::Create( +Instruction::ICmp, +Pred1 == ICmpInst::ICMP_NE ? ICmpInst::ICMP_UGT + : ICmpInst::ICMP_ULT, +X, +Constant::getIntegerValue( +X->getType(), APInt(X->getType()->getScalarSizeInBits(), +Pred1 == ICmpInst::ICMP_NE ? 1 : 2))); + } +} else { + // C != 0 && C != 1 + // icmp eq X, (zext (icmp eq X, C)) --> icmp eq X, 0 + // icmp eq X, (zext (icmp ne X, C)) --> icmp eq X, 1 + // icmp ne X, (zext (icmp eq X, C)) --> icmp ne X, 0 + // icmp ne X, (zext (icmp ne X, C)) --> icmp ne X, 1 + return ICmpInst::Create( + Instruction::ICmp, Pred1, X, + Constant::getIntegerValue( + X->getType(), + APInt(X->getType()->getScalarSizeInBits(), +static_cast(Pred2 == ICmpInst::ICMP_NE; +} + } + if (match(I.getOperand(0), m_c_Add(m_ZExt(m_Value(X)), m_SExt(m_Value(Y && match(I.getOperand(1), m_APInt(C)) && X->getType()->isIntOrIntVectorTy(1) && diff --git a/llvm/test/Transforms/InstCombine/icmp-range.ll b/llvm/test/Transforms/InstCombine/icmp-range.ll index 4281e09cb0309c8..15424fce33fdeea 100644 --- a/llvm/test/Transforms/InstCombine/icmp-range.ll +++ b/llvm/test/Transforms/InstCombine/icmp-range.ll @@ -1034,6 +1034,187 @@ define i1 @icmp_ne_bool_1(ptr %ptr) { ret i1 %cmp } +define i1 @icmp_ne_zext_eq_zero(i32 %a) { +; CHECK-LABEL: @icmp_ne_zext_eq_zero( +; CHECK-NEXT:ret i1 true +; + %cmp = icmp eq i32 %a, 0 + %conv = zext i1 %cmp to i32 + %cmp1 = icmp ne i32 %conv, %a + ret i1 %cmp1 +} + +define i1 @icmp_ne_zext_ne_zero(i32 %a) { +; CHECK-LABEL: @icmp_ne_zext_ne_zero( +; CHECK-NEXT:[[CMP1:%.*]] = icmp ugt i32 [[A:%.*]], 1 +; CHECK-NEXT:ret i1 [[CMP1]] +; + %cmp = icmp ne i32 %a, 0 + %conv = zext i1 %cmp to i32 + %cmp1 = icmp ne i32 %conv, %a + ret i1 %cmp1 +} + +define i1 @icmp_eq_zext_eq_zero(i32 %a) { +; CHECK-LABEL: @icmp_eq_zext_eq_zero( +; CHECK-NEXT:ret i1 false +; + %cmp = icmp eq i32 %a, 0 + %conv = zext i1 %cmp to i32 + %cmp1 = icmp eq i32 %conv, %a + ret i1 %cmp1 +} + +define i1 @icmp_eq_zext_ne_zero(i32
[clang] [InstCombine] Simplify the pattern `a ne/eq (zext/sext (a ne/eq c))` (PR #65852)
nikic wrote: Looks like incorrect conflict resolution in the last merge. https://github.com/llvm/llvm-project/pull/65852 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [InstCombine] Simplify the pattern `a ne/eq (zext/sext (a ne/eq c))` (PR #65852)
nikic wrote: Looks like incorrect conflict resolution in the last merge. https://github.com/llvm/llvm-project/pull/65852 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [MLIR][Presburger] Fix reduce bug in Fraction class and add tests (PR #68298)
https://github.com/Abhinav271828 updated https://github.com/llvm/llvm-project/pull/68298 >From 8b09dcb29a66c3c88bdf1acac2df65091ab60183 Mon Sep 17 00:00:00 2001 From: Abhinav271828 Date: Wed, 6 Sep 2023 14:11:26 +0100 Subject: [PATCH 1/5] Update upstream branch --- libcxx/modules/std/mdspan.cppm | 33 + libcxx/modules/std/print.cppm | 25 + 2 files changed, 58 insertions(+) create mode 100644 libcxx/modules/std/mdspan.cppm create mode 100644 libcxx/modules/std/print.cppm diff --git a/libcxx/modules/std/mdspan.cppm b/libcxx/modules/std/mdspan.cppm new file mode 100644 index 000..40426cce3fce8c2 --- /dev/null +++ b/libcxx/modules/std/mdspan.cppm @@ -0,0 +1,33 @@ +// -*- 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 +// +//===--===// + +module; +#include + +export module std:mdspan; +export namespace std { +#if _LIBCPP_STD_VER >= 23 + // [mdspan.extents], class template extents + using std::extents; + + // [mdspan.extents.dextents], alias template dextents + using std::dextents; + + // [mdspan.layout], layout mapping + using std::layout_left; + using std::layout_right; + // using std::layout_stride; + + // [mdspan.accessor.default], class template default_accessor + using std::default_accessor; + + // [mdspan.mdspan], class template mdspan + using std::mdspan; +#endif // _LIBCPP_STD_VER >= 23 +} // namespace std diff --git a/libcxx/modules/std/print.cppm b/libcxx/modules/std/print.cppm new file mode 100644 index 000..02362633c6d9fbb --- /dev/null +++ b/libcxx/modules/std/print.cppm @@ -0,0 +1,25 @@ +// -*- 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 +// +//===--===// + +module; +#include + +export module std:print; +export namespace std { +#if _LIBCPP_STD_VER >= 23 + // [print.fun], print functions + using std::print; + using std::println; + + using std::vprint_nonunicode; +# ifndef _LIBCPP_HAS_NO_UNICODE + using std::vprint_unicode; +# endif // _LIBCPP_HAS_NO_UNICODE +#endif // _LIBCPP_STD_VER >= 23 +} // namespace std >From eebcd402bd1a9266f11bc6739b82fe7b84fc8695 Mon Sep 17 00:00:00 2001 From: Abhinav271828 Date: Mon, 2 Oct 2023 13:40:41 +0100 Subject: [PATCH 2/5] Fix reduce and add Fraction tests --- .../mlir/Analysis/Presburger/Fraction.h | 2 +- .../Analysis/Presburger/CMakeLists.txt| 1 + .../Analysis/Presburger/FractionTest.cpp | 51 +++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 mlir/unittests/Analysis/Presburger/FractionTest.cpp diff --git a/mlir/include/mlir/Analysis/Presburger/Fraction.h b/mlir/include/mlir/Analysis/Presburger/Fraction.h index 74127a900d53ed2..f633192a870c8d4 100644 --- a/mlir/include/mlir/Analysis/Presburger/Fraction.h +++ b/mlir/include/mlir/Analysis/Presburger/Fraction.h @@ -102,7 +102,7 @@ inline bool operator>=(const Fraction &x, const Fraction &y) { inline Fraction reduce(const Fraction &f) { if (f == Fraction(0)) return Fraction(0, 1); - MPInt g = gcd(f.num, f.den); + MPInt g = gcd(abs(f.num), abs(f.den)); return Fraction(f.num / g, f.den / g); } diff --git a/mlir/unittests/Analysis/Presburger/CMakeLists.txt b/mlir/unittests/Analysis/Presburger/CMakeLists.txt index 7b0124ee24c352e..b6ce273e35a0ee7 100644 --- a/mlir/unittests/Analysis/Presburger/CMakeLists.txt +++ b/mlir/unittests/Analysis/Presburger/CMakeLists.txt @@ -1,4 +1,5 @@ add_mlir_unittest(MLIRPresburgerTests + FractionTest.cpp IntegerPolyhedronTest.cpp IntegerRelationTest.cpp LinearTransformTest.cpp diff --git a/mlir/unittests/Analysis/Presburger/FractionTest.cpp b/mlir/unittests/Analysis/Presburger/FractionTest.cpp new file mode 100644 index 000..38b97c48969642e --- /dev/null +++ b/mlir/unittests/Analysis/Presburger/FractionTest.cpp @@ -0,0 +1,51 @@ +#include "mlir/Analysis/Presburger/Fraction.h" +#include "./Utils.h" +#include +#include + +using namespace mlir; +using namespace presburger; + +TEST(FractionTest, getAsInteger) { +Fraction f(3, 1); +EXPECT_EQ(f.getAsInteger(), MPInt(3)); +} + +TEST(FractionTest, nearIntegers) { +Fraction f(52, 14); + +EXPECT_EQ(floor(f), 3); +EXPECT_EQ(ceil(f), 4); +} + +TEST(FractionTest, reduce) { +Fraction f(20, 35), g(-56, 63); +EXPECT_EQ(f, Fraction(4, 7)); +EXPECT_EQ(g, Fraction(-8, 9)); +}
[clang-tools-extra] [MLIR][Presburger] Fix reduce bug in Fraction class and add tests (PR #68298)
https://github.com/Abhinav271828 updated https://github.com/llvm/llvm-project/pull/68298 >From 8b09dcb29a66c3c88bdf1acac2df65091ab60183 Mon Sep 17 00:00:00 2001 From: Abhinav271828 Date: Wed, 6 Sep 2023 14:11:26 +0100 Subject: [PATCH 1/5] Update upstream branch --- libcxx/modules/std/mdspan.cppm | 33 + libcxx/modules/std/print.cppm | 25 + 2 files changed, 58 insertions(+) create mode 100644 libcxx/modules/std/mdspan.cppm create mode 100644 libcxx/modules/std/print.cppm diff --git a/libcxx/modules/std/mdspan.cppm b/libcxx/modules/std/mdspan.cppm new file mode 100644 index 000..40426cce3fce8c2 --- /dev/null +++ b/libcxx/modules/std/mdspan.cppm @@ -0,0 +1,33 @@ +// -*- 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 +// +//===--===// + +module; +#include + +export module std:mdspan; +export namespace std { +#if _LIBCPP_STD_VER >= 23 + // [mdspan.extents], class template extents + using std::extents; + + // [mdspan.extents.dextents], alias template dextents + using std::dextents; + + // [mdspan.layout], layout mapping + using std::layout_left; + using std::layout_right; + // using std::layout_stride; + + // [mdspan.accessor.default], class template default_accessor + using std::default_accessor; + + // [mdspan.mdspan], class template mdspan + using std::mdspan; +#endif // _LIBCPP_STD_VER >= 23 +} // namespace std diff --git a/libcxx/modules/std/print.cppm b/libcxx/modules/std/print.cppm new file mode 100644 index 000..02362633c6d9fbb --- /dev/null +++ b/libcxx/modules/std/print.cppm @@ -0,0 +1,25 @@ +// -*- 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 +// +//===--===// + +module; +#include + +export module std:print; +export namespace std { +#if _LIBCPP_STD_VER >= 23 + // [print.fun], print functions + using std::print; + using std::println; + + using std::vprint_nonunicode; +# ifndef _LIBCPP_HAS_NO_UNICODE + using std::vprint_unicode; +# endif // _LIBCPP_HAS_NO_UNICODE +#endif // _LIBCPP_STD_VER >= 23 +} // namespace std >From eebcd402bd1a9266f11bc6739b82fe7b84fc8695 Mon Sep 17 00:00:00 2001 From: Abhinav271828 Date: Mon, 2 Oct 2023 13:40:41 +0100 Subject: [PATCH 2/5] Fix reduce and add Fraction tests --- .../mlir/Analysis/Presburger/Fraction.h | 2 +- .../Analysis/Presburger/CMakeLists.txt| 1 + .../Analysis/Presburger/FractionTest.cpp | 51 +++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 mlir/unittests/Analysis/Presburger/FractionTest.cpp diff --git a/mlir/include/mlir/Analysis/Presburger/Fraction.h b/mlir/include/mlir/Analysis/Presburger/Fraction.h index 74127a900d53ed2..f633192a870c8d4 100644 --- a/mlir/include/mlir/Analysis/Presburger/Fraction.h +++ b/mlir/include/mlir/Analysis/Presburger/Fraction.h @@ -102,7 +102,7 @@ inline bool operator>=(const Fraction &x, const Fraction &y) { inline Fraction reduce(const Fraction &f) { if (f == Fraction(0)) return Fraction(0, 1); - MPInt g = gcd(f.num, f.den); + MPInt g = gcd(abs(f.num), abs(f.den)); return Fraction(f.num / g, f.den / g); } diff --git a/mlir/unittests/Analysis/Presburger/CMakeLists.txt b/mlir/unittests/Analysis/Presburger/CMakeLists.txt index 7b0124ee24c352e..b6ce273e35a0ee7 100644 --- a/mlir/unittests/Analysis/Presburger/CMakeLists.txt +++ b/mlir/unittests/Analysis/Presburger/CMakeLists.txt @@ -1,4 +1,5 @@ add_mlir_unittest(MLIRPresburgerTests + FractionTest.cpp IntegerPolyhedronTest.cpp IntegerRelationTest.cpp LinearTransformTest.cpp diff --git a/mlir/unittests/Analysis/Presburger/FractionTest.cpp b/mlir/unittests/Analysis/Presburger/FractionTest.cpp new file mode 100644 index 000..38b97c48969642e --- /dev/null +++ b/mlir/unittests/Analysis/Presburger/FractionTest.cpp @@ -0,0 +1,51 @@ +#include "mlir/Analysis/Presburger/Fraction.h" +#include "./Utils.h" +#include +#include + +using namespace mlir; +using namespace presburger; + +TEST(FractionTest, getAsInteger) { +Fraction f(3, 1); +EXPECT_EQ(f.getAsInteger(), MPInt(3)); +} + +TEST(FractionTest, nearIntegers) { +Fraction f(52, 14); + +EXPECT_EQ(floor(f), 3); +EXPECT_EQ(ceil(f), 4); +} + +TEST(FractionTest, reduce) { +Fraction f(20, 35), g(-56, 63); +EXPECT_EQ(f, Fraction(4, 7)); +EXPECT_EQ(g, Fraction(-8, 9)); +}
[clang-tools-extra] [MLIR][Presburger] Fix reduce bug in Fraction class and add tests (PR #68298)
https://github.com/Abhinav271828 edited https://github.com/llvm/llvm-project/pull/68298 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [MLIR][Presburger] Fix reduce bug in Fraction class and add tests (PR #68298)
https://github.com/Abhinav271828 edited https://github.com/llvm/llvm-project/pull/68298 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [InstCombine] Simplify the pattern `a ne/eq (zext/sext (a ne/eq c))` (PR #65852)
https://github.com/dtcxzyw updated https://github.com/llvm/llvm-project/pull/65852 >From d9d8bcbb98e8f5aecb9733329389d61a489bd731 Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Sat, 9 Sep 2023 23:07:29 +0800 Subject: [PATCH 01/10] [InstCombine] Simplify the pattern `a ne/eq (zext (a ne/eq c))` --- .../InstCombine/InstCombineCompares.cpp | 62 ++ .../test/Transforms/InstCombine/icmp-range.ll | 181 ++ 2 files changed, 243 insertions(+) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 9fdc46fec631679..837b8e6d2619989 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -6309,7 +6309,69 @@ Instruction *InstCombinerImpl::foldICmpUsingBoolRange(ICmpInst &I) { Y->getType()->isIntOrIntVectorTy(1) && Pred == ICmpInst::ICMP_ULE) return BinaryOperator::CreateOr(Builder.CreateIsNull(X), Y); + ICmpInst::Predicate Pred1, Pred2; const APInt *C; + // icmp eq/ne X, (zext (icmp eq/ne X, C)) + if (match(&I, m_c_ICmp(Pred1, m_Value(X), + m_ZExt(m_ICmp(Pred2, m_Deferred(X), m_APInt(C) && + ICmpInst::isEquality(Pred1) && ICmpInst::isEquality(Pred2)) { +if (C->isZero()) { + if (Pred2 == ICmpInst::ICMP_EQ) { +// icmp eq X, (zext (icmp eq X, 0)) --> false +// icmp ne X, (zext (icmp eq X, 0)) --> true +return replaceInstUsesWith( +I, +Constant::getIntegerValue( +I.getType(), +APInt(1U, static_cast(Pred1 == ICmpInst::ICMP_NE; + } else { +// icmp eq X, (zext (icmp ne X, 0)) --> icmp ult X, 2 +// icmp ne X, (zext (icmp ne X, 0)) --> icmp ugt X, 1 +return ICmpInst::Create( +Instruction::ICmp, +Pred1 == ICmpInst::ICMP_NE ? ICmpInst::ICMP_UGT + : ICmpInst::ICMP_ULT, +X, +Constant::getIntegerValue( +X->getType(), APInt(X->getType()->getScalarSizeInBits(), +Pred1 == ICmpInst::ICMP_NE ? 1 : 2))); + } +} else if (C->isOne()) { + if (Pred2 == ICmpInst::ICMP_NE) { +// icmp eq X, (zext (icmp ne X, 1)) --> false +// icmp ne X, (zext (icmp ne X, 1)) --> true +return replaceInstUsesWith( +I, +Constant::getIntegerValue( +I.getType(), +APInt(1U, static_cast(Pred1 == ICmpInst::ICMP_NE; + } else { +// icmp eq X, (zext (icmp eq X, 1)) --> icmp ult X, 2 +// icmp ne X, (zext (icmp eq X, 1)) --> icmp ugt X, 1 +return ICmpInst::Create( +Instruction::ICmp, +Pred1 == ICmpInst::ICMP_NE ? ICmpInst::ICMP_UGT + : ICmpInst::ICMP_ULT, +X, +Constant::getIntegerValue( +X->getType(), APInt(X->getType()->getScalarSizeInBits(), +Pred1 == ICmpInst::ICMP_NE ? 1 : 2))); + } +} else { + // C != 0 && C != 1 + // icmp eq X, (zext (icmp eq X, C)) --> icmp eq X, 0 + // icmp eq X, (zext (icmp ne X, C)) --> icmp eq X, 1 + // icmp ne X, (zext (icmp eq X, C)) --> icmp ne X, 0 + // icmp ne X, (zext (icmp ne X, C)) --> icmp ne X, 1 + return ICmpInst::Create( + Instruction::ICmp, Pred1, X, + Constant::getIntegerValue( + X->getType(), + APInt(X->getType()->getScalarSizeInBits(), +static_cast(Pred2 == ICmpInst::ICMP_NE; +} + } + if (match(I.getOperand(0), m_c_Add(m_ZExt(m_Value(X)), m_SExt(m_Value(Y && match(I.getOperand(1), m_APInt(C)) && X->getType()->isIntOrIntVectorTy(1) && diff --git a/llvm/test/Transforms/InstCombine/icmp-range.ll b/llvm/test/Transforms/InstCombine/icmp-range.ll index 4281e09cb0309c8..15424fce33fdeea 100644 --- a/llvm/test/Transforms/InstCombine/icmp-range.ll +++ b/llvm/test/Transforms/InstCombine/icmp-range.ll @@ -1034,6 +1034,187 @@ define i1 @icmp_ne_bool_1(ptr %ptr) { ret i1 %cmp } +define i1 @icmp_ne_zext_eq_zero(i32 %a) { +; CHECK-LABEL: @icmp_ne_zext_eq_zero( +; CHECK-NEXT:ret i1 true +; + %cmp = icmp eq i32 %a, 0 + %conv = zext i1 %cmp to i32 + %cmp1 = icmp ne i32 %conv, %a + ret i1 %cmp1 +} + +define i1 @icmp_ne_zext_ne_zero(i32 %a) { +; CHECK-LABEL: @icmp_ne_zext_ne_zero( +; CHECK-NEXT:[[CMP1:%.*]] = icmp ugt i32 [[A:%.*]], 1 +; CHECK-NEXT:ret i1 [[CMP1]] +; + %cmp = icmp ne i32 %a, 0 + %conv = zext i1 %cmp to i32 + %cmp1 = icmp ne i32 %conv, %a + ret i1 %cmp1 +} + +define i1 @icmp_eq_zext_eq_zero(i32 %a) { +; CHECK-LABEL: @icmp_eq_zext_eq_zero( +; CHECK-NEXT:ret i1 false +; + %cmp = icmp eq i32 %a, 0 + %conv = zext i1 %cmp to i32 + %cmp1 = icmp eq i32 %conv, %a + ret i1 %cmp1 +} + +define i1 @icmp_eq_zext_ne_zero(i32
[clang] [InstCombine] Simplify the pattern `a ne/eq (zext/sext (a ne/eq c))` (PR #65852)
https://github.com/dtcxzyw updated https://github.com/llvm/llvm-project/pull/65852 >From d9d8bcbb98e8f5aecb9733329389d61a489bd731 Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Sat, 9 Sep 2023 23:07:29 +0800 Subject: [PATCH 01/10] [InstCombine] Simplify the pattern `a ne/eq (zext (a ne/eq c))` --- .../InstCombine/InstCombineCompares.cpp | 62 ++ .../test/Transforms/InstCombine/icmp-range.ll | 181 ++ 2 files changed, 243 insertions(+) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 9fdc46fec631679..837b8e6d2619989 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -6309,7 +6309,69 @@ Instruction *InstCombinerImpl::foldICmpUsingBoolRange(ICmpInst &I) { Y->getType()->isIntOrIntVectorTy(1) && Pred == ICmpInst::ICMP_ULE) return BinaryOperator::CreateOr(Builder.CreateIsNull(X), Y); + ICmpInst::Predicate Pred1, Pred2; const APInt *C; + // icmp eq/ne X, (zext (icmp eq/ne X, C)) + if (match(&I, m_c_ICmp(Pred1, m_Value(X), + m_ZExt(m_ICmp(Pred2, m_Deferred(X), m_APInt(C) && + ICmpInst::isEquality(Pred1) && ICmpInst::isEquality(Pred2)) { +if (C->isZero()) { + if (Pred2 == ICmpInst::ICMP_EQ) { +// icmp eq X, (zext (icmp eq X, 0)) --> false +// icmp ne X, (zext (icmp eq X, 0)) --> true +return replaceInstUsesWith( +I, +Constant::getIntegerValue( +I.getType(), +APInt(1U, static_cast(Pred1 == ICmpInst::ICMP_NE; + } else { +// icmp eq X, (zext (icmp ne X, 0)) --> icmp ult X, 2 +// icmp ne X, (zext (icmp ne X, 0)) --> icmp ugt X, 1 +return ICmpInst::Create( +Instruction::ICmp, +Pred1 == ICmpInst::ICMP_NE ? ICmpInst::ICMP_UGT + : ICmpInst::ICMP_ULT, +X, +Constant::getIntegerValue( +X->getType(), APInt(X->getType()->getScalarSizeInBits(), +Pred1 == ICmpInst::ICMP_NE ? 1 : 2))); + } +} else if (C->isOne()) { + if (Pred2 == ICmpInst::ICMP_NE) { +// icmp eq X, (zext (icmp ne X, 1)) --> false +// icmp ne X, (zext (icmp ne X, 1)) --> true +return replaceInstUsesWith( +I, +Constant::getIntegerValue( +I.getType(), +APInt(1U, static_cast(Pred1 == ICmpInst::ICMP_NE; + } else { +// icmp eq X, (zext (icmp eq X, 1)) --> icmp ult X, 2 +// icmp ne X, (zext (icmp eq X, 1)) --> icmp ugt X, 1 +return ICmpInst::Create( +Instruction::ICmp, +Pred1 == ICmpInst::ICMP_NE ? ICmpInst::ICMP_UGT + : ICmpInst::ICMP_ULT, +X, +Constant::getIntegerValue( +X->getType(), APInt(X->getType()->getScalarSizeInBits(), +Pred1 == ICmpInst::ICMP_NE ? 1 : 2))); + } +} else { + // C != 0 && C != 1 + // icmp eq X, (zext (icmp eq X, C)) --> icmp eq X, 0 + // icmp eq X, (zext (icmp ne X, C)) --> icmp eq X, 1 + // icmp ne X, (zext (icmp eq X, C)) --> icmp ne X, 0 + // icmp ne X, (zext (icmp ne X, C)) --> icmp ne X, 1 + return ICmpInst::Create( + Instruction::ICmp, Pred1, X, + Constant::getIntegerValue( + X->getType(), + APInt(X->getType()->getScalarSizeInBits(), +static_cast(Pred2 == ICmpInst::ICMP_NE; +} + } + if (match(I.getOperand(0), m_c_Add(m_ZExt(m_Value(X)), m_SExt(m_Value(Y && match(I.getOperand(1), m_APInt(C)) && X->getType()->isIntOrIntVectorTy(1) && diff --git a/llvm/test/Transforms/InstCombine/icmp-range.ll b/llvm/test/Transforms/InstCombine/icmp-range.ll index 4281e09cb0309c8..15424fce33fdeea 100644 --- a/llvm/test/Transforms/InstCombine/icmp-range.ll +++ b/llvm/test/Transforms/InstCombine/icmp-range.ll @@ -1034,6 +1034,187 @@ define i1 @icmp_ne_bool_1(ptr %ptr) { ret i1 %cmp } +define i1 @icmp_ne_zext_eq_zero(i32 %a) { +; CHECK-LABEL: @icmp_ne_zext_eq_zero( +; CHECK-NEXT:ret i1 true +; + %cmp = icmp eq i32 %a, 0 + %conv = zext i1 %cmp to i32 + %cmp1 = icmp ne i32 %conv, %a + ret i1 %cmp1 +} + +define i1 @icmp_ne_zext_ne_zero(i32 %a) { +; CHECK-LABEL: @icmp_ne_zext_ne_zero( +; CHECK-NEXT:[[CMP1:%.*]] = icmp ugt i32 [[A:%.*]], 1 +; CHECK-NEXT:ret i1 [[CMP1]] +; + %cmp = icmp ne i32 %a, 0 + %conv = zext i1 %cmp to i32 + %cmp1 = icmp ne i32 %conv, %a + ret i1 %cmp1 +} + +define i1 @icmp_eq_zext_eq_zero(i32 %a) { +; CHECK-LABEL: @icmp_eq_zext_eq_zero( +; CHECK-NEXT:ret i1 false +; + %cmp = icmp eq i32 %a, 0 + %conv = zext i1 %cmp to i32 + %cmp1 = icmp eq i32 %conv, %a + ret i1 %cmp1 +} + +define i1 @icmp_eq_zext_ne_zero(i32
[clang] [InstCombine] Simplify the pattern `a ne/eq (zext/sext (a ne/eq c))` (PR #65852)
dtcxzyw wrote: The conflict resolution should be correct now. https://github.com/llvm/llvm-project/pull/65852 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [InstCombine] Simplify the pattern `a ne/eq (zext/sext (a ne/eq c))` (PR #65852)
dtcxzyw wrote: The conflict resolution should be correct now. https://github.com/llvm/llvm-project/pull/65852 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D155688: [PATCH] [llvm] [InstCombine] Canonicalise ADD+GEP
This revision was automatically updated to reflect the committed changes. Closed by commit rGe13bed4c5f35: [PATCH] [llvm] [InstCombine] Canonicalise ADD+GEP (authored by d-smirnov, committed by MatsPetersson). Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D155688/new/ https://reviews.llvm.org/D155688 Files: clang/test/CodeGenCXX/microsoft-abi-dynamic-cast.cpp llvm/lib/Transforms/InstCombine/InstructionCombining.cpp llvm/test/CodeGen/Hexagon/autohvx/vector-align-tbaa.ll llvm/test/Transforms/InstCombine/align-addr.ll llvm/test/Transforms/InstCombine/mem-par-metadata-memcpy.ll llvm/test/Transforms/InstCombine/memrchr-4.ll llvm/test/Transforms/InstCombine/shift.ll llvm/test/Transforms/LoopVectorize/AArch64/sve-interleaved-accesses.ll llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-phi.ll llvm/test/Transforms/LoopVectorize/induction.ll llvm/test/Transforms/LoopVectorize/interleaved-accesses.ll llvm/test/Transforms/LoopVectorize/invariant-store-vectorization.ll llvm/test/Transforms/LoopVectorize/runtime-check.ll llvm/test/Transforms/LowerMatrixIntrinsics/multiply-fused-loops.ll Index: llvm/test/Transforms/LowerMatrixIntrinsics/multiply-fused-loops.ll === --- llvm/test/Transforms/LowerMatrixIntrinsics/multiply-fused-loops.ll +++ llvm/test/Transforms/LowerMatrixIntrinsics/multiply-fused-loops.ll @@ -27,14 +27,14 @@ ; CHECK-NEXT:br label [[INNER_BODY:%.*]] ; CHECK: inner.body: ; CHECK-NEXT:[[TMP0:%.*]] = shl i64 [[INNER_IV]], 2 -; CHECK-NEXT:[[TMP1:%.*]] = add i64 [[TMP0]], [[ROWS_IV]] -; CHECK-NEXT:[[TMP2:%.*]] = getelementptr double, ptr [[A:%.*]], i64 [[TMP1]] +; CHECK-NEXT:[[TMP1:%.*]] = getelementptr double, ptr [[A:%.*]], i64 [[TMP0]] +; CHECK-NEXT:[[TMP2:%.*]] = getelementptr double, ptr [[TMP1]], i64 [[ROWS_IV]] ; CHECK-NEXT:[[COL_LOAD:%.*]] = load <2 x double>, ptr [[TMP2]], align 8 ; CHECK-NEXT:[[VEC_GEP:%.*]] = getelementptr double, ptr [[TMP2]], i64 4 ; CHECK-NEXT:[[COL_LOAD1:%.*]] = load <2 x double>, ptr [[VEC_GEP]], align 8 ; CHECK-NEXT:[[TMP3:%.*]] = shl i64 [[COLS_IV]], 2 -; CHECK-NEXT:[[TMP4:%.*]] = add i64 [[TMP3]], [[INNER_IV]] -; CHECK-NEXT:[[TMP5:%.*]] = getelementptr double, ptr [[B:%.*]], i64 [[TMP4]] +; CHECK-NEXT:[[TMP4:%.*]] = getelementptr double, ptr [[B:%.*]], i64 [[TMP3]] +; CHECK-NEXT:[[TMP5:%.*]] = getelementptr double, ptr [[TMP4]], i64 [[INNER_IV]] ; CHECK-NEXT:[[COL_LOAD2:%.*]] = load <2 x double>, ptr [[TMP5]], align 8 ; CHECK-NEXT:[[VEC_GEP3:%.*]] = getelementptr double, ptr [[TMP5]], i64 4 ; CHECK-NEXT:[[COL_LOAD4:%.*]] = load <2 x double>, ptr [[VEC_GEP3]], align 8 @@ -55,8 +55,8 @@ ; CHECK-NEXT:[[ROWS_STEP]] = add i64 [[ROWS_IV]], 2 ; CHECK-NEXT:[[ROWS_COND_NOT:%.*]] = icmp eq i64 [[ROWS_STEP]], 4 ; CHECK-NEXT:[[TMP10:%.*]] = shl i64 [[COLS_IV]], 2 -; CHECK-NEXT:[[TMP11:%.*]] = add i64 [[TMP10]], [[ROWS_IV]] -; CHECK-NEXT:[[TMP12:%.*]] = getelementptr double, ptr [[C:%.*]], i64 [[TMP11]] +; CHECK-NEXT:[[TMP11:%.*]] = getelementptr double, ptr [[C:%.*]], i64 [[TMP10]] +; CHECK-NEXT:[[TMP12:%.*]] = getelementptr double, ptr [[TMP11]], i64 [[ROWS_IV]] ; CHECK-NEXT:store <2 x double> [[TMP7]], ptr [[TMP12]], align 8 ; CHECK-NEXT:[[VEC_GEP16:%.*]] = getelementptr double, ptr [[TMP12]], i64 4 ; CHECK-NEXT:store <2 x double> [[TMP9]], ptr [[VEC_GEP16]], align 8 @@ -103,14 +103,14 @@ ; CHECK-NEXT:br label [[INNER_BODY:%.*]] ; CHECK: inner.body: ; CHECK-NEXT:[[TMP0:%.*]] = shl i64 [[INNER_IV]], 1 -; CHECK-NEXT:[[TMP1:%.*]] = add i64 [[TMP0]], [[ROWS_IV]] -; CHECK-NEXT:[[TMP2:%.*]] = getelementptr i64, ptr [[A:%.*]], i64 [[TMP1]] +; CHECK-NEXT:[[TMP1:%.*]] = getelementptr i64, ptr [[A:%.*]], i64 [[TMP0]] +; CHECK-NEXT:[[TMP2:%.*]] = getelementptr i64, ptr [[TMP1]], i64 [[ROWS_IV]] ; CHECK-NEXT:[[COL_LOAD:%.*]] = load <2 x i64>, ptr [[TMP2]], align 8 ; CHECK-NEXT:[[VEC_GEP:%.*]] = getelementptr i64, ptr [[TMP2]], i64 2 ; CHECK-NEXT:[[COL_LOAD1:%.*]] = load <2 x i64>, ptr [[VEC_GEP]], align 8 ; CHECK-NEXT:[[TMP3:%.*]] = shl i64 [[COLS_IV]], 2 -; CHECK-NEXT:[[TMP4:%.*]] = add i64 [[TMP3]], [[INNER_IV]] -; CHECK-NEXT:[[TMP5:%.*]] = getelementptr i64, ptr [[B:%.*]], i64 [[TMP4]] +; CHECK-NEXT:[[TMP4:%.*]] = getelementptr i64, ptr [[B:%.*]], i64 [[TMP3]] +; CHECK-NEXT:[[TMP5:%.*]] = getelementptr i64, ptr [[TMP4]], i64 [[INNER_IV]] ; CHECK-NEXT:[[COL_LOAD2:%.*]] = load <2 x i64>, ptr [[TMP5]], align 8 ; CHECK-NEXT:[[VEC_GEP3:%.*]] = getelementptr i64, ptr [[TMP5]], i64 4 ; CHECK-NEXT:[[COL_LOAD4:%.*]] = load <2 x i64>, ptr [[VEC_GEP3]], align 8 @@ -135,8 +135,8 @@ ; CHECK-NEXT:[[ROWS_STEP]] = add i64 [[ROWS_IV]], 2 ; CHECK-NEXT:[[ROWS_COND_NOT:%.*]] = icmp eq i64 [[ROWS_IV]], 0 ; CHECK-NEXT:[[TMP14:%.*]] = shl i64 [[COLS
[clang] e13bed4 - [PATCH] [llvm] [InstCombine] Canonicalise ADD+GEP
Author: Dmitriy Smirnov Date: 2023-10-06T12:29:06+01:00 New Revision: e13bed4c5f3544c076ce57e36d9a11eefa5a7815 URL: https://github.com/llvm/llvm-project/commit/e13bed4c5f3544c076ce57e36d9a11eefa5a7815 DIFF: https://github.com/llvm/llvm-project/commit/e13bed4c5f3544c076ce57e36d9a11eefa5a7815.diff LOG: [PATCH] [llvm] [InstCombine] Canonicalise ADD+GEP This patch tries to canonicalise add + gep to gep + gep. Co-authored-by: Paul Walker Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D155688 Added: Modified: clang/test/CodeGenCXX/microsoft-abi-dynamic-cast.cpp llvm/lib/Transforms/InstCombine/InstructionCombining.cpp llvm/test/CodeGen/Hexagon/autohvx/vector-align-tbaa.ll llvm/test/Transforms/InstCombine/align-addr.ll llvm/test/Transforms/InstCombine/mem-par-metadata-memcpy.ll llvm/test/Transforms/InstCombine/memrchr-4.ll llvm/test/Transforms/InstCombine/shift.ll llvm/test/Transforms/LoopVectorize/AArch64/sve-interleaved-accesses.ll llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-phi.ll llvm/test/Transforms/LoopVectorize/induction.ll llvm/test/Transforms/LoopVectorize/interleaved-accesses.ll llvm/test/Transforms/LoopVectorize/invariant-store-vectorization.ll llvm/test/Transforms/LoopVectorize/runtime-check.ll llvm/test/Transforms/LowerMatrixIntrinsics/multiply-fused-loops.ll Removed: diff --git a/clang/test/CodeGenCXX/microsoft-abi-dynamic-cast.cpp b/clang/test/CodeGenCXX/microsoft-abi-dynamic-cast.cpp index 2ec620eb19d223b..5c4b86744287ec3 100644 --- a/clang/test/CodeGenCXX/microsoft-abi-dynamic-cast.cpp +++ b/clang/test/CodeGenCXX/microsoft-abi-dynamic-cast.cpp @@ -94,9 +94,9 @@ void* test9(B* x) { return dynamic_cast(x); } // CHECK-NEXT: [[VBTBL:%.*]] = load ptr, ptr [[VBPTR]], align 4 // CHECK-NEXT: [[VBOFFP:%.*]] = getelementptr inbounds i32, ptr [[VBTBL]], i32 1 // CHECK-NEXT: [[VBOFFS:%.*]] = load i32, ptr [[VBOFFP]], align 4 -// CHECK-NEXT: [[DELTA:%.*]] = add nsw i32 [[VBOFFS]], 4 -// CHECK-NEXT: [[ADJ:%.*]] = getelementptr inbounds i8, ptr %x, i32 [[DELTA]] -// CHECK-NEXT: [[CALL:%.*]] = tail call ptr @__RTCastToVoid(ptr nonnull [[ADJ]]) +// CHECK-NEXT: [[BASE:%.*]] = getelementptr i8, ptr %x, i32 [[VBOFFS]] +// CHECK-NEXT: [[ADJ:%.*]] = getelementptr i8, ptr [[BASE]], i32 4 +// CHECK-NEXT: [[CALL:%.*]] = tail call ptr @__RTCastToVoid(ptr [[ADJ]]) // CHECK-NEXT: br label // CHECK:[[RET:%.*]] = phi ptr // CHECK-NEXT: ret ptr [[RET]] diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index 0ee29149a1aeef2..4736df40951af38 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -2316,11 +2316,27 @@ Instruction *InstCombinerImpl::visitGetElementPtrInst(GetElementPtrInst &GEP) { return CastInst::CreatePointerBitCastOrAddrSpaceCast(Y, GEPType); } } - // We do not handle pointer-vector geps here. if (GEPType->isVectorTy()) return nullptr; + if (GEP.getNumIndices() == 1) { +// Try to replace ADD + GEP with GEP + GEP. +Value *Idx1, *Idx2; +if (match(GEP.getOperand(1), + m_OneUse(m_Add(m_Value(Idx1), m_Value(Idx2) { + // %idx = add i64 %idx1, %idx2 + // %gep = getelementptr i32, i32* %ptr, i64 %idx + // as: + // %newptr = getelementptr i32, i32* %ptr, i64 %idx1 + // %newgep = getelementptr i32, i32* %newptr, i64 %idx2 + auto *NewPtr = Builder.CreateGEP(GEP.getResultElementType(), + GEP.getPointerOperand(), Idx1); + return GetElementPtrInst::Create(GEP.getResultElementType(), NewPtr, + Idx2); +} + } + if (!GEP.isInBounds()) { unsigned IdxWidth = DL.getIndexSizeInBits(PtrOp->getType()->getPointerAddressSpace()); diff --git a/llvm/test/CodeGen/Hexagon/autohvx/vector-align-tbaa.ll b/llvm/test/CodeGen/Hexagon/autohvx/vector-align-tbaa.ll index 333ecc14e473b6b..24c5e1c2f789a57 100644 --- a/llvm/test/CodeGen/Hexagon/autohvx/vector-align-tbaa.ll +++ b/llvm/test/CodeGen/Hexagon/autohvx/vector-align-tbaa.ll @@ -12,26 +12,26 @@ target triple = "hexagon" define <64 x i16> @f0(ptr %a0, i32 %a1) #0 { ; CHECK-LABEL: @f0( ; CHECK-NEXT: b0: -; CHECK-NEXT:[[V0:%.*]] = add i32 [[A1:%.*]], 64 -; CHECK-NEXT:[[V1:%.*]] = getelementptr i16, ptr [[A0:%.*]], i32 [[V0]] +; CHECK-NEXT:[[TMP0:%.*]] = getelementptr i16, ptr [[A0:%.*]], i32 [[A1:%.*]] +; CHECK-NEXT:[[V1:%.*]] = getelementptr i16, ptr [[TMP0]], i32 64 ; CHECK-NEXT:[[PTI:%.*]] = ptrtoint ptr [[V1]] to i32 -; CHECK-NEXT:[[ADD:%.*]] = and i32 [[PTI]], -128 -; CHECK-NEXT:[[ITP:%.*]] = inttoptr i32 [[ADD]] to ptr +; CHECK-NEXT:[[AND:%.*]] = and i32 [[PTI]], -1
Re: [clang] a6acf3f - Revert "Fixes and closes #53952. Setting the ASTHasCompilerErrors member variable correctly based on the PP diagnostics. (#68127)"
Hmm. No, I was using a clean tree. I tried a50e63b38b931d945f97eac882278068221eca17 and the commit immediately before, and the build problem showed up at a50e63b38b931d945f97eac882278068221eca17. Let me re-apply the patch locally and try both gcc and clang (as the host compilers). Kazu Hirata On Thu, Oct 5, 2023 at 1:26 PM Aaron Ballman wrote: > On Thu, Oct 5, 2023 at 4:19 PM Aaron Ballman > wrote: > > > > On Thu, Oct 5, 2023 at 4:18 PM Aaron Ballman > wrote: > > > > > > On Thu, Oct 5, 2023 at 4:08 PM Kazu Hirata via cfe-commits > > > wrote: > > > > > > > > > > > > Author: Kazu Hirata > > > > Date: 2023-10-05T13:08:24-07:00 > > > > New Revision: a6acf3fd49a20c570a390af2a3c84e10b9545b68 > > > > > > > > URL: > https://github.com/llvm/llvm-project/commit/a6acf3fd49a20c570a390af2a3c84e10b9545b68 > > > > DIFF: > https://github.com/llvm/llvm-project/commit/a6acf3fd49a20c570a390af2a3c84e10b9545b68.diff > > > > > > > > LOG: Revert "Fixes and closes #53952. Setting the > ASTHasCompilerErrors member variable correctly based on the PP diagnostics. > (#68127)" > > > > > > > > This reverts commit a50e63b38b931d945f97eac882278068221eca17. > > > > > > > > With clang-14.0.6 as the host compiler, I'm getting: > > > > > > > > ld.lld: error: undefined symbol: > clang::ASTWriter::WriteAST(clang::Sema&, llvm::StringRef, clang::Module*, > llvm::StringRef, bool, bool) > > > > >>> referenced by ASTUnit.cpp > > > > >>> > ASTUnit.cpp.o:(clang::ASTUnit::serialize(llvm::raw_ostream&)) in archive > lib/libclangFrontend.a > > > > > > That's expected; we removed a parameter that appeared to be unused and > > > was causing problems. Is lld using the parameter that was removed? If > > > so, what was the intent of overriding the diagnostics engine? > > > > Oh. I see, it wasn't lld using it, it comes from a missed usage in > > ASTUnit.cpp that should have been updated. > > Nope, I'm back to being baffled. That code was updated in the PR and > no bots went red with the change. We may need more details in order to > address this; alternatively, did you have local changes to ASTUnit.cpp > so that the file didn't get updated for you? > > ~Aaron > ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [clang] a6acf3f - Revert "Fixes and closes #53952. Setting the ASTHasCompilerErrors member variable correctly based on the PP diagnostics. (#68127)"
I went back to a50e63b38b931d945f97eac882278068221eca17. There, my release+asserts build failed, but my release-without-asserts build was OK. I used clang-14.0.6 as the host compiler for both of these builds. I reapplied a50e63b38b931d945f97eac882278068221eca17 at the tip (5e159972917fb7d02347f98d7431f1d02bee33b6 to be exact). Now both release+asserts and release-without-asserts builds are OK. I don't know what happened in between. In any event, I'm sorry for the noise. Would you mind re-applying the patch? (Or maybe I should?) Thanks, Kazu Hirata On Thu, Oct 5, 2023 at 3:33 PM Kazu Hirata wrote: > Hmm. No, I was using a clean tree. I tried > a50e63b38b931d945f97eac882278068221eca17 and the commit immediately before, > and the build problem showed up at a50e63b38b931d945f97eac882278068221eca17. > > Let me re-apply the patch locally and try both gcc and clang (as the host > compilers). > > Kazu Hirata > > > On Thu, Oct 5, 2023 at 1:26 PM Aaron Ballman > wrote: > >> On Thu, Oct 5, 2023 at 4:19 PM Aaron Ballman >> wrote: >> > >> > On Thu, Oct 5, 2023 at 4:18 PM Aaron Ballman >> wrote: >> > > >> > > On Thu, Oct 5, 2023 at 4:08 PM Kazu Hirata via cfe-commits >> > > wrote: >> > > > >> > > > >> > > > Author: Kazu Hirata >> > > > Date: 2023-10-05T13:08:24-07:00 >> > > > New Revision: a6acf3fd49a20c570a390af2a3c84e10b9545b68 >> > > > >> > > > URL: >> https://github.com/llvm/llvm-project/commit/a6acf3fd49a20c570a390af2a3c84e10b9545b68 >> > > > DIFF: >> https://github.com/llvm/llvm-project/commit/a6acf3fd49a20c570a390af2a3c84e10b9545b68.diff >> > > > >> > > > LOG: Revert "Fixes and closes #53952. Setting the >> ASTHasCompilerErrors member variable correctly based on the PP diagnostics. >> (#68127)" >> > > > >> > > > This reverts commit a50e63b38b931d945f97eac882278068221eca17. >> > > > >> > > > With clang-14.0.6 as the host compiler, I'm getting: >> > > > >> > > > ld.lld: error: undefined symbol: >> clang::ASTWriter::WriteAST(clang::Sema&, llvm::StringRef, clang::Module*, >> llvm::StringRef, bool, bool) >> > > > >>> referenced by ASTUnit.cpp >> > > > >>> >> ASTUnit.cpp.o:(clang::ASTUnit::serialize(llvm::raw_ostream&)) in archive >> lib/libclangFrontend.a >> > > >> > > That's expected; we removed a parameter that appeared to be unused and >> > > was causing problems. Is lld using the parameter that was removed? If >> > > so, what was the intent of overriding the diagnostics engine? >> > >> > Oh. I see, it wasn't lld using it, it comes from a missed usage in >> > ASTUnit.cpp that should have been updated. >> >> Nope, I'm back to being baffled. That code was updated in the PR and >> no bots went red with the change. We may need more details in order to >> address this; alternatively, did you have local changes to ASTUnit.cpp >> so that the file didn't get updated for you? >> >> ~Aaron >> > ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 46518a1 - Revert "Revert "Fixes and closes #53952. Setting the ASTHasCompilerErrors member variable correctly based on the PP diagnostics. (#68127)""
Author: Aaron Ballman Date: 2023-10-06T07:43:19-04:00 New Revision: 46518a14f1ab594c0fc7091bc55c10872b64075d URL: https://github.com/llvm/llvm-project/commit/46518a14f1ab594c0fc7091bc55c10872b64075d DIFF: https://github.com/llvm/llvm-project/commit/46518a14f1ab594c0fc7091bc55c10872b64075d.diff LOG: Revert "Revert "Fixes and closes #53952. Setting the ASTHasCompilerErrors member variable correctly based on the PP diagnostics. (#68127)"" This reverts commit a6acf3fd49a20c570a390af2a3c84e10b9545b68 and relands a50e63b38b931d945f97eac882278068221eca17. The original revert was done by mistake. Added: Modified: clang/include/clang/Serialization/ASTWriter.h clang/lib/Frontend/ASTUnit.cpp clang/lib/Serialization/ASTWriter.cpp clang/lib/Serialization/GeneratePCH.cpp Removed: diff --git a/clang/include/clang/Serialization/ASTWriter.h b/clang/include/clang/Serialization/ASTWriter.h index f2c7c03ff093607..98445d40ebd82c3 100644 --- a/clang/include/clang/Serialization/ASTWriter.h +++ b/clang/include/clang/Serialization/ASTWriter.h @@ -613,7 +613,6 @@ class ASTWriter : public ASTDeserializationListener, /// the module but currently is merely a random 32-bit number. ASTFileSignature WriteAST(Sema &SemaRef, StringRef OutputFile, Module *WritingModule, StringRef isysroot, -bool hasErrors = false, bool ShouldCacheASTInMemory = false); /// Emit a token. diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index 016f88a43a56ddd..85157c3b21b6648 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -2341,12 +2341,9 @@ bool ASTUnit::Save(StringRef File) { return false; } -static bool serializeUnit(ASTWriter &Writer, - SmallVectorImpl &Buffer, - Sema &S, - bool hasErrors, - raw_ostream &OS) { - Writer.WriteAST(S, std::string(), nullptr, "", hasErrors); +static bool serializeUnit(ASTWriter &Writer, SmallVectorImpl &Buffer, + Sema &S, raw_ostream &OS) { + Writer.WriteAST(S, std::string(), nullptr, ""); // Write the generated bitstream to "Out". if (!Buffer.empty()) @@ -2356,18 +2353,14 @@ static bool serializeUnit(ASTWriter &Writer, } bool ASTUnit::serialize(raw_ostream &OS) { - // For serialization we are lenient if the errors were only warn-as-error kind. - bool hasErrors = getDiagnostics().hasUncompilableErrorOccurred(); - if (WriterData) -return serializeUnit(WriterData->Writer, WriterData->Buffer, - getSema(), hasErrors, OS); +return serializeUnit(WriterData->Writer, WriterData->Buffer, getSema(), OS); SmallString<128> Buffer; llvm::BitstreamWriter Stream(Buffer); InMemoryModuleCache ModuleCache; ASTWriter Writer(Stream, Buffer, ModuleCache, {}); - return serializeUnit(Writer, Buffer, getSema(), hasErrors, OS); + return serializeUnit(Writer, Buffer, getSema(), OS); } using SLocRemap = ContinuousRangeMap; diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index 8d8a10336576d97..12473bf5aace632 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -4622,12 +4622,12 @@ time_t ASTWriter::getTimestampForOutput(const FileEntry *E) const { ASTFileSignature ASTWriter::WriteAST(Sema &SemaRef, StringRef OutputFile, Module *WritingModule, StringRef isysroot, - bool hasErrors, bool ShouldCacheASTInMemory) { llvm::TimeTraceScope scope("WriteAST", OutputFile); WritingAST = true; - ASTHasCompilerErrors = hasErrors; + ASTHasCompilerErrors = + SemaRef.PP.getDiagnostics().hasUncompilableErrorOccurred(); // Emit the file header. Stream.Emit((unsigned)'C', 8); diff --git a/clang/lib/Serialization/GeneratePCH.cpp b/clang/lib/Serialization/GeneratePCH.cpp index 601a24b4aec46ad..cf8084333811f13 100644 --- a/clang/lib/Serialization/GeneratePCH.cpp +++ b/clang/lib/Serialization/GeneratePCH.cpp @@ -65,12 +65,8 @@ void PCHGenerator::HandleTranslationUnit(ASTContext &Ctx) { // Emit the PCH file to the Buffer. assert(SemaPtr && "No Sema?"); - Buffer->Signature = - Writer.WriteAST(*SemaPtr, OutputFile, Module, isysroot, - // For serialization we are lenient if the errors were - // only warn-as-error kind. - PP.getDiagnostics().hasUncompilableErrorOccurred(), - ShouldCacheASTInMemory); + Buffer->Signature = Writer.WriteAST(*SemaPtr, OutputFile, Module, isysroot, + ShouldCacheASTInMemory); Buffer->IsComplete = true; }
Re: [clang] a6acf3f - Revert "Fixes and closes #53952. Setting the ASTHasCompilerErrors member variable correctly based on the PP diagnostics. (#68127)"
On Thu, Oct 5, 2023 at 6:52 PM Kazu Hirata wrote: > > I went back to a50e63b38b931d945f97eac882278068221eca17. There, my > release+asserts build failed, but my release-without-asserts build was OK. I > used clang-14.0.6 as the host compiler for both of these builds. > > I reapplied a50e63b38b931d945f97eac882278068221eca17 at the tip > (5e159972917fb7d02347f98d7431f1d02bee33b6 to be exact). Now both > release+asserts and release-without-asserts builds are OK. > > I don't know what happened in between. In any event, I'm sorry for the > noise. Would you mind re-applying the patch? (Or maybe I should?) No worries, it happens -- I'm glad we're both on the same page that the revert was a mistake. I've re-landed the original changes by reverting your revert in 46518a14f1ab594c0fc7091bc55c10872b64075d ~Aaron > > Thanks, > > Kazu Hirata > > > On Thu, Oct 5, 2023 at 3:33 PM Kazu Hirata wrote: >> >> Hmm. No, I was using a clean tree. I tried >> a50e63b38b931d945f97eac882278068221eca17 and the commit immediately before, >> and the build problem showed up at a50e63b38b931d945f97eac882278068221eca17. >> >> Let me re-apply the patch locally and try both gcc and clang (as the host >> compilers). >> >> Kazu Hirata >> >> >> On Thu, Oct 5, 2023 at 1:26 PM Aaron Ballman wrote: >>> >>> On Thu, Oct 5, 2023 at 4:19 PM Aaron Ballman wrote: >>> > >>> > On Thu, Oct 5, 2023 at 4:18 PM Aaron Ballman >>> > wrote: >>> > > >>> > > On Thu, Oct 5, 2023 at 4:08 PM Kazu Hirata via cfe-commits >>> > > wrote: >>> > > > >>> > > > >>> > > > Author: Kazu Hirata >>> > > > Date: 2023-10-05T13:08:24-07:00 >>> > > > New Revision: a6acf3fd49a20c570a390af2a3c84e10b9545b68 >>> > > > >>> > > > URL: >>> > > > https://github.com/llvm/llvm-project/commit/a6acf3fd49a20c570a390af2a3c84e10b9545b68 >>> > > > DIFF: >>> > > > https://github.com/llvm/llvm-project/commit/a6acf3fd49a20c570a390af2a3c84e10b9545b68.diff >>> > > > >>> > > > LOG: Revert "Fixes and closes #53952. Setting the >>> > > > ASTHasCompilerErrors member variable correctly based on the PP >>> > > > diagnostics. (#68127)" >>> > > > >>> > > > This reverts commit a50e63b38b931d945f97eac882278068221eca17. >>> > > > >>> > > > With clang-14.0.6 as the host compiler, I'm getting: >>> > > > >>> > > > ld.lld: error: undefined symbol: >>> > > > clang::ASTWriter::WriteAST(clang::Sema&, llvm::StringRef, >>> > > > clang::Module*, llvm::StringRef, bool, bool) >>> > > > >>> referenced by ASTUnit.cpp >>> > > > >>> >>> > > > >>> ASTUnit.cpp.o:(clang::ASTUnit::serialize(llvm::raw_ostream&)) in >>> > > > >>> archive lib/libclangFrontend.a >>> > > >>> > > That's expected; we removed a parameter that appeared to be unused and >>> > > was causing problems. Is lld using the parameter that was removed? If >>> > > so, what was the intent of overriding the diagnostics engine? >>> > >>> > Oh. I see, it wasn't lld using it, it comes from a missed usage in >>> > ASTUnit.cpp that should have been updated. >>> >>> Nope, I'm back to being baffled. That code was updated in the PR and >>> no bots went red with the change. We may need more details in order to >>> address this; alternatively, did you have local changes to ASTUnit.cpp >>> so that the file didn't get updated for you? >>> >>> ~Aaron ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Fixes and closes #53952. Setting the ASTHasCompilerErrors member variable correctly based on the PP diagnostics. (PR #68127)
AaronBallman wrote: There was a mix-up. I landed the original changes, @kazutakahirata saw what appeared to be a linker error after pulling those changes down and did a revert, but that turned out to be an issue local to their machine so I've reverted the revert (re-landing the original changes). So the code should be in now and should hopefully stay in,. https://github.com/llvm/llvm-project/pull/68127 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][NFC] Add missing placement-new after Allocate() calls (PR #68382)
https://github.com/AaronBallman approved this pull request. LGTM! Thank you for the cleanup! https://github.com/llvm/llvm-project/pull/68382 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 99e6ef3 - [clang][NFC] Add missing placement-new after Allocate() calls (#68382)
Author: Vlad Serebrennikov Date: 2023-10-06T07:50:07-04:00 New Revision: 99e6ef3e7c6e342beb2ad6b5e64d1e5fd2f24d2b URL: https://github.com/llvm/llvm-project/commit/99e6ef3e7c6e342beb2ad6b5e64d1e5fd2f24d2b DIFF: https://github.com/llvm/llvm-project/commit/99e6ef3e7c6e342beb2ad6b5e64d1e5fd2f24d2b.diff LOG: [clang][NFC] Add missing placement-new after Allocate() calls (#68382) While working on #68377 inspecting `Allocate()` calls, I found out that there are couple of places where we forget to use placement-new to create objects in the allocated memory. Added: Modified: clang/lib/AST/DeclCXX.cpp clang/lib/AST/DeclObjC.cpp clang/lib/Serialization/ASTReaderDecl.cpp Removed: diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp index 42bab4ed51b7290..a92b788366434ce 100644 --- a/clang/lib/AST/DeclCXX.cpp +++ b/clang/lib/AST/DeclCXX.cpp @@ -1484,7 +1484,8 @@ void CXXRecordDecl::setCaptures(ASTContext &Context, if (Captures[I].isExplicit()) ++Data.NumExplicitCaptures; -*ToCapture++ = Captures[I]; +new (ToCapture) LambdaCapture(Captures[I]); +ToCapture++; } if (!lambdaIsDefaultConstructibleAndAssignable()) diff --git a/clang/lib/AST/DeclObjC.cpp b/clang/lib/AST/DeclObjC.cpp index e934a81d086e3c0..e1eef2dbd9c3d28 100644 --- a/clang/lib/AST/DeclObjC.cpp +++ b/clang/lib/AST/DeclObjC.cpp @@ -931,8 +931,8 @@ void ObjCMethodDecl::setParamsAndSelLocs(ASTContext &C, unsigned Size = sizeof(ParmVarDecl *) * NumParams + sizeof(SourceLocation) * SelLocs.size(); ParamsAndSelLocs = C.Allocate(Size); - std::copy(Params.begin(), Params.end(), getParams()); - std::copy(SelLocs.begin(), SelLocs.end(), getStoredSelLocs()); + std::uninitialized_copy(Params.begin(), Params.end(), getParams()); + std::uninitialized_copy(SelLocs.begin(), SelLocs.end(), getStoredSelLocs()); } void ObjCMethodDecl::getSelectorLocs( diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index d553b3c6d78dedc..6a2f607d916c472 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -2002,13 +2002,16 @@ void ASTDeclReader::ReadCXXDefinitionData( case LCK_StarThis: case LCK_This: case LCK_VLAType: -*ToCapture++ = Capture(Loc, IsImplicit, Kind, nullptr,SourceLocation()); +new (ToCapture) +Capture(Loc, IsImplicit, Kind, nullptr, SourceLocation()); +ToCapture++; break; case LCK_ByCopy: case LCK_ByRef: auto *Var = readDeclAs(); SourceLocation EllipsisLoc = readSourceLocation(); -*ToCapture++ = Capture(Loc, IsImplicit, Kind, Var, EllipsisLoc); +new (ToCapture) Capture(Loc, IsImplicit, Kind, Var, EllipsisLoc); +ToCapture++; break; } } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][NFC] Add missing placement-new after Allocate() calls (PR #68382)
https://github.com/AaronBallman closed https://github.com/llvm/llvm-project/pull/68382 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][USR] Encode full decl-context also for anon namespaces (PR #68325)
https://github.com/sam-mccall approved this pull request. https://github.com/llvm/llvm-project/pull/68325 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D157331: [clang] Implement C23
aaron.ballman accepted this revision. aaron.ballman added a comment. This revision is now accepted and ready to land. LGTM! Please wait for @jrtc27 to also sign off before landing. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D157331/new/ https://reviews.llvm.org/D157331 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [InstCombine] Simplify the pattern `a ne/eq (zext/sext (a ne/eq c))` (PR #65852)
https://github.com/nikic approved this pull request. Yeah, it looks correct now. https://github.com/llvm/llvm-project/pull/65852 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [InstCombine] Simplify the pattern `a ne/eq (zext/sext (a ne/eq c))` (PR #65852)
https://github.com/nikic approved this pull request. Yeah, it looks correct now. https://github.com/llvm/llvm-project/pull/65852 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 32a9c09 - [clang][CodeGen] Regenerate tests checks after 94795a37e892cfedb570c70a5101ea88348e60c7
Author: Simon Pilgrim Date: 2023-10-06T13:27:31+01:00 New Revision: 32a9c096091081736480250da66a2702375a6210 URL: https://github.com/llvm/llvm-project/commit/32a9c096091081736480250da66a2702375a6210 DIFF: https://github.com/llvm/llvm-project/commit/32a9c096091081736480250da66a2702375a6210.diff LOG: [clang][CodeGen] Regenerate tests checks after 94795a37e892cfedb570c70a5101ea88348e60c7 These were missed as I didn't expect clang codegen to be updated Added: Modified: clang/test/CodeGen/X86/avx-shuffle-builtins.c clang/test/CodeGen/aarch64-neon-vcmla.c Removed: diff --git a/clang/test/CodeGen/X86/avx-shuffle-builtins.c b/clang/test/CodeGen/X86/avx-shuffle-builtins.c index 9917598f6eb15c2..9109247e534f4f0 100644 --- a/clang/test/CodeGen/X86/avx-shuffle-builtins.c +++ b/clang/test/CodeGen/X86/avx-shuffle-builtins.c @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -ffreestanding %s -O3 -triple=x86_64-apple-darwin -target-feature +avx -emit-llvm -o - | FileCheck %s -// RUN: %clang_cc1 -ffreestanding %s -O3 -triple=i386-apple-darwin -target-feature +avx -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -ffreestanding %s -O3 -triple=x86_64-apple-darwin -target-feature +avx -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,X64 +// RUN: %clang_cc1 -ffreestanding %s -O3 -triple=i386-apple-darwin -target-feature +avx -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,X86 // FIXME: This is testing optimized generation of shuffle instructions and should be fixed. @@ -129,8 +129,11 @@ __m256i test_mm256_insertf128_si256_1(__m256i a, __m128i b) { // Make sure we have the correct mask for each extractf128 case. __m128 test_mm256_extractf128_ps_0(__m256 a) { - // CHECK-LABEL: test_mm256_extractf128_ps_0 - // CHECK: shufflevector{{.*}} + // X64-LABEL: test_mm256_extractf128_ps_0 + // X64: shufflevector{{.*}} + // + // X86-LABEL: test_mm256_extractf128_ps_0 + // X86: shufflevector{{.*}} return _mm256_extractf128_ps(a, 0); } @@ -142,13 +145,16 @@ __m128d test_mm256_extractf128_pd_0(__m256d a) { __m128i test_mm256_extractf128_si256_0(__m256i a) { // CHECK-LABEL: test_mm256_extractf128_si256_0 - // CHECK: shufflevector{{.*}} + // CHECK: shufflevector{{.*}} return _mm256_extractf128_si256(a, 0); } __m128 test_mm256_extractf128_ps_1(__m256 a) { - // CHECK-LABEL: test_mm256_extractf128_ps_1 - // CHECK: shufflevector{{.*}} + // X64-LABEL: test_mm256_extractf128_ps_1 + // X64: shufflevector{{.*}} + // + // X86-LABEL: test_mm256_extractf128_ps_1 + // X86: shufflevector{{.*}} return _mm256_extractf128_ps(a, 1); } @@ -160,7 +166,7 @@ __m128d test_mm256_extractf128_pd_1(__m256d a) { __m128i test_mm256_extractf128_si256_1(__m256i a) { // CHECK-LABEL: test_mm256_extractf128_si256_1 - // CHECK: shufflevector{{.*}} + // CHECK: shufflevector{{.*}} return _mm256_extractf128_si256(a, 1); } diff --git a/clang/test/CodeGen/aarch64-neon-vcmla.c b/clang/test/CodeGen/aarch64-neon-vcmla.c index 59ac17a24cccf75..9cd046d63d1b520 100644 --- a/clang/test/CodeGen/aarch64-neon-vcmla.c +++ b/clang/test/CodeGen/aarch64-neon-vcmla.c @@ -167,10 +167,8 @@ float16x4_t test_vcmla_laneq_f16(float16x4_t acc, float16x4_t lhs, float16x8_t r } // CHECK-LABEL: @test_vcmlaq_lane_f16( -// CHECK: [[CPLX:%.*]] = bitcast <4 x half> %rhs to <2 x i32> -// CHECK: [[DUP:%.*]] = shufflevector <2 x i32> [[CPLX]], <2 x i32> undef, <4 x i32> -// CHECK: [[DUP_FLT:%.*]] = bitcast <4 x i32> [[DUP]] to <8 x half> -// CHECK: [[RES:%.*]] = tail call <8 x half> @llvm.aarch64.neon.vcmla.rot0.v8f16(<8 x half> %acc, <8 x half> %lhs, <8 x half> [[DUP_FLT]]) +// CHECK: [[DUP:%.*]] = shufflevector <4 x half> %rhs, <4 x half> poison, <8 x i32> +// CHECK: [[RES:%.*]] = tail call <8 x half> @llvm.aarch64.neon.vcmla.rot0.v8f16(<8 x half> %acc, <8 x half> %lhs, <8 x half> [[DUP]]) // CHECK: ret <8 x half> [[RES]] float16x8_t test_vcmlaq_lane_f16(float16x8_t acc, float16x8_t lhs, float16x4_t rhs) { return vcmlaq_lane_f16(acc, lhs, rhs, 1); @@ -243,10 +241,8 @@ float16x4_t test_vcmla_rot90_laneq_f16(float16x4_t acc, float16x4_t lhs, float16 } // CHECK-LABEL: @test_vcmlaq_rot90_lane_f16( -// CHECK: [[CPLX:%.*]] = bitcast <4 x half> %rhs to <2 x i32> -// CHECK: [[DUP:%.*]] = shufflevector <2 x i32> [[CPLX]], <2 x i32> undef, <4 x i32> -// CHECK: [[DUP_FLT:%.*]] = bitcast <4 x i32> [[DUP]] to <8 x half> -// CHECK: [[RES:%.*]] = tail call <8 x half> @llvm.aarch64.neon.vcmla.rot90.v8f16(<8 x half> %acc, <8 x half> %lhs, <8 x half> [[DUP_FLT]]) +// CHECK: [[DUP:%.*]] = shufflevector <4 x half> %rhs, <4 x half> poison, <8 x i32> +// CHECK: [[RES:%.*]] = tail call <8 x half> @llvm.aarch64.neon.vcmla.rot90.v8f16(<8 x half> %acc, <8 x half> %lhs, <8 x half> [[DUP]]) // CHECK: ret <8 x half> [[RES]] float16x8_t test_vcmlaq_rot90_lane_f16(float16x8_t acc, float16x8_t lhs, float16x4_t rhs) { retu
[clang] [clang] fix hasAnyBase not binding submatchers (PR #67939)
https://github.com/AaronBallman approved this pull request. LGTM! https://github.com/llvm/llvm-project/pull/67939 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTMatcher] fix hasAnyBase not binding submatchers (PR #67939)
https://github.com/5chmidti edited https://github.com/llvm/llvm-project/pull/67939 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Avoid evaluating the BitWidth expression over and over again (PR #66203)
AaronBallman wrote: > @cor3ntin Looking at this again... while I'd also like to see the general > solution, I'd probably apply this anyway since it makes it clearer that this > function can actually be fast. Its name is terrible for what it does. It > sounds like it's a simply getter but in reality it might be pretty costly to > call. This patch would mitigate this somewhat and make the performance > expectations clearer when reading the code of this function. Once we have the general solution, this code would be redundant, wouldn't it? (I also would prefer the more general solution if reasonable -- playing whack-a-mole on constant evaluation is going to make for maintenance problems and this is an issue that plagues other parts of the compiler as well.) https://github.com/llvm/llvm-project/pull/66203 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][NFC] Specify Type and ExtQuals as having 16-byte alignment (PR #68377)
@@ -1982,9 +1986,9 @@ class alignas(8) Type : public ExtQualsTypeCommonBase { Type(TypeClass tc, QualType canon, TypeDependence Dependence) : ExtQualsTypeCommonBase(this, canon.isNull() ? QualType(this_(), 0) : canon) { -static_assert(sizeof(*this) <= 8 + sizeof(ExtQualsTypeCommonBase), +static_assert(sizeof(*this) <= 16 + sizeof(ExtQualsTypeCommonBase), "changing bitfields changed sizeof(Type)!"); AaronBallman wrote: Would it make sense to change this to use `alignof(decltype(*this))` rather than `16` to make the connection to alignment more obvious? https://github.com/llvm/llvm-project/pull/68377 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Avoid evaluating the BitWidth expression over and over again (PR #66203)
tbaederr wrote: Well, this is not going to make a noticeable difference in runtime. https://reviews.llvm.org/D155548 didn't land because there are no measurements to make where this makes a measurable difference. As for my earlier comment, it would also make sense to rename that function to `computeBitWidth()` or just cache the computed value (we compute it when parsing anyway to diagnose 0 size, etc. right?). https://github.com/llvm/llvm-project/pull/66203 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][NFC] Specify Type and ExtQuals as having 16-byte alignment (PR #68377)
@@ -1507,6 +1508,9 @@ class ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode { : ExtQualsTypeCommonBase(baseType, canon.isNull() ? QualType(this_(), 0) : canon), Quals(quals) { +static_assert(alignof(decltype(*this)) % TypeAlignment == 0, AaronBallman wrote: This feels unnecessary because we've added `alignas(TypeAlignment)` to the class -- it's basically statically asserting that the compiler honored the alignment we requested (which it has to do anyway or else the program is ill-formed), WDYT? https://github.com/llvm/llvm-project/pull/68377 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [InstCombine] Canonicalize `(X +/- Y) & Y` into `~X & Y` when Y is a power of 2 (PR #67915)
https://github.com/dtcxzyw updated https://github.com/llvm/llvm-project/pull/67915 >From c4ce28c942c172e5646b5922f0b02b4169197840 Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Sun, 1 Oct 2023 21:52:47 +0800 Subject: [PATCH 1/2] [InstCombine] Canonicalize `(X +/- Y) & Y` into `~X & Y` when Y is a power of 2 --- .../InstCombine/InstCombineAndOrXor.cpp | 8 llvm/test/Transforms/InstCombine/and.ll | 44 +-- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index cbdab3e9c5fb91d..4322cc96f5a2b6c 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -2250,6 +2250,14 @@ Instruction *InstCombinerImpl::visitAnd(BinaryOperator &I) { return SelectInst::Create(Cmp, ConstantInt::getNullValue(Ty), Y); } + // Canonicalize: + // (X +/- Y) & Y --> ~X & Y when Y is a power of 2. + if (match(&I, m_c_And(m_Value(Y), m_OneUse(m_CombineOr( +m_c_Add(m_Value(X), m_Deferred(Y)), +m_Sub(m_Value(X), m_Deferred(Y)) && + isKnownToBeAPowerOfTwo(Y, /*OrZero*/ true, /*Depth*/ 0, &I)) +return BinaryOperator::CreateAnd(Builder.CreateNot(X), Y); + const APInt *C; if (match(Op1, m_APInt(C))) { const APInt *XorC; diff --git a/llvm/test/Transforms/InstCombine/and.ll b/llvm/test/Transforms/InstCombine/and.ll index 90f027010e2aea6..eb39ff9014ff3a4 100644 --- a/llvm/test/Transforms/InstCombine/and.ll +++ b/llvm/test/Transforms/InstCombine/and.ll @@ -1595,8 +1595,8 @@ define <2 x i8> @flip_masked_bit_uniform(<2 x i8> %A) { define <2 x i8> @flip_masked_bit_undef(<2 x i8> %A) { ; CHECK-LABEL: @flip_masked_bit_undef( -; CHECK-NEXT:[[B:%.*]] = add <2 x i8> [[A:%.*]], -; CHECK-NEXT:[[C:%.*]] = and <2 x i8> [[B]], +; CHECK-NEXT:[[TMP1:%.*]] = xor <2 x i8> [[A:%.*]], +; CHECK-NEXT:[[C:%.*]] = and <2 x i8> [[TMP1]], ; CHECK-NEXT:ret <2 x i8> [[C]] ; %B = add <2 x i8> %A, @@ -1606,8 +1606,8 @@ define <2 x i8> @flip_masked_bit_undef(<2 x i8> %A) { define <2 x i8> @flip_masked_bit_nonuniform(<2 x i8> %A) { ; CHECK-LABEL: @flip_masked_bit_nonuniform( -; CHECK-NEXT:[[B:%.*]] = add <2 x i8> [[A:%.*]], -; CHECK-NEXT:[[C:%.*]] = and <2 x i8> [[B]], +; CHECK-NEXT:[[TMP1:%.*]] = xor <2 x i8> [[A:%.*]], +; CHECK-NEXT:[[C:%.*]] = and <2 x i8> [[TMP1]], ; CHECK-NEXT:ret <2 x i8> [[C]] ; %B = add <2 x i8> %A, @@ -2546,3 +2546,39 @@ define i32 @and_zext_eq_zero(i32 %A, i32 %C) { %5 = and i32 %2, %4 ret i32 %5 } + +define i32 @canonicalize_and_add_power2_or_zero(i32 %x, i32 %y) { +; CHECK-LABEL: @canonicalize_and_add_power2_or_zero( +; CHECK-NEXT:[[NY:%.*]] = sub i32 0, [[Y:%.*]] +; CHECK-NEXT:[[P2:%.*]] = and i32 [[NY]], [[Y]] +; CHECK-NEXT:call void @use32(i32 [[P2]]) +; CHECK-NEXT:[[TMP1:%.*]] = xor i32 [[X:%.*]], -1 +; CHECK-NEXT:[[AND:%.*]] = and i32 [[P2]], [[TMP1]] +; CHECK-NEXT:ret i32 [[AND]] +; + %ny = sub i32 0, %y + %p2 = and i32 %y, %ny + call void @use32(i32 %p2) ; keep p2 + + %val = add i32 %x, %p2 + %and = and i32 %val, %p2 + ret i32 %and +} + +define i32 @canonicalize_and_sub_power2_or_zero(i32 %x, i32 %y) { +; CHECK-LABEL: @canonicalize_and_sub_power2_or_zero( +; CHECK-NEXT:[[NY:%.*]] = sub i32 0, [[Y:%.*]] +; CHECK-NEXT:[[P2:%.*]] = and i32 [[NY]], [[Y]] +; CHECK-NEXT:call void @use32(i32 [[P2]]) +; CHECK-NEXT:[[TMP1:%.*]] = xor i32 [[X:%.*]], -1 +; CHECK-NEXT:[[AND:%.*]] = and i32 [[P2]], [[TMP1]] +; CHECK-NEXT:ret i32 [[AND]] +; + %ny = sub i32 0, %y + %p2 = and i32 %y, %ny + call void @use32(i32 %p2) ; keep p2 + + %val = sub i32 %x, %p2 + %and = and i32 %val, %p2 + ret i32 %and +} >From b64ca5b5f743e6a935f4ea09154c3a08c6e65c47 Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Fri, 6 Oct 2023 17:32:46 +0800 Subject: [PATCH 2/2] fixup! [InstCombine] Canonicalize `(X +/- Y) & Y` into `~X & Y` when Y is a power of 2 Add additional tests. --- llvm/test/Transforms/InstCombine/and.ll | 123 1 file changed, 123 insertions(+) diff --git a/llvm/test/Transforms/InstCombine/and.ll b/llvm/test/Transforms/InstCombine/and.ll index eb39ff9014ff3a4..989640ed41f2d2e 100644 --- a/llvm/test/Transforms/InstCombine/and.ll +++ b/llvm/test/Transforms/InstCombine/and.ll @@ -2582,3 +2582,126 @@ define i32 @canonicalize_and_sub_power2_or_zero(i32 %x, i32 %y) { %and = and i32 %val, %p2 ret i32 %and } + +define i32 @canonicalize_and_add_power2_or_zero_commuted1(i32 %x, i32 %y) { +; CHECK-LABEL: @canonicalize_and_add_power2_or_zero_commuted1( +; CHECK-NEXT:[[NY:%.*]] = sub i32 0, [[Y:%.*]] +; CHECK-NEXT:[[P2:%.*]] = and i32 [[NY]], [[Y]] +; CHECK-NEXT:call void @use32(i32 [[P2]]) +; CHECK-NEXT:[[TMP1:%.*]] = xor i32 [[X:%.
[clang] [InstCombine] Canonicalize `(X +/- Y) & Y` into `~X & Y` when Y is a power of 2 (PR #67915)
https://github.com/dtcxzyw updated https://github.com/llvm/llvm-project/pull/67915 >From c4ce28c942c172e5646b5922f0b02b4169197840 Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Sun, 1 Oct 2023 21:52:47 +0800 Subject: [PATCH 1/2] [InstCombine] Canonicalize `(X +/- Y) & Y` into `~X & Y` when Y is a power of 2 --- .../InstCombine/InstCombineAndOrXor.cpp | 8 llvm/test/Transforms/InstCombine/and.ll | 44 +-- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index cbdab3e9c5fb91d..4322cc96f5a2b6c 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -2250,6 +2250,14 @@ Instruction *InstCombinerImpl::visitAnd(BinaryOperator &I) { return SelectInst::Create(Cmp, ConstantInt::getNullValue(Ty), Y); } + // Canonicalize: + // (X +/- Y) & Y --> ~X & Y when Y is a power of 2. + if (match(&I, m_c_And(m_Value(Y), m_OneUse(m_CombineOr( +m_c_Add(m_Value(X), m_Deferred(Y)), +m_Sub(m_Value(X), m_Deferred(Y)) && + isKnownToBeAPowerOfTwo(Y, /*OrZero*/ true, /*Depth*/ 0, &I)) +return BinaryOperator::CreateAnd(Builder.CreateNot(X), Y); + const APInt *C; if (match(Op1, m_APInt(C))) { const APInt *XorC; diff --git a/llvm/test/Transforms/InstCombine/and.ll b/llvm/test/Transforms/InstCombine/and.ll index 90f027010e2aea6..eb39ff9014ff3a4 100644 --- a/llvm/test/Transforms/InstCombine/and.ll +++ b/llvm/test/Transforms/InstCombine/and.ll @@ -1595,8 +1595,8 @@ define <2 x i8> @flip_masked_bit_uniform(<2 x i8> %A) { define <2 x i8> @flip_masked_bit_undef(<2 x i8> %A) { ; CHECK-LABEL: @flip_masked_bit_undef( -; CHECK-NEXT:[[B:%.*]] = add <2 x i8> [[A:%.*]], -; CHECK-NEXT:[[C:%.*]] = and <2 x i8> [[B]], +; CHECK-NEXT:[[TMP1:%.*]] = xor <2 x i8> [[A:%.*]], +; CHECK-NEXT:[[C:%.*]] = and <2 x i8> [[TMP1]], ; CHECK-NEXT:ret <2 x i8> [[C]] ; %B = add <2 x i8> %A, @@ -1606,8 +1606,8 @@ define <2 x i8> @flip_masked_bit_undef(<2 x i8> %A) { define <2 x i8> @flip_masked_bit_nonuniform(<2 x i8> %A) { ; CHECK-LABEL: @flip_masked_bit_nonuniform( -; CHECK-NEXT:[[B:%.*]] = add <2 x i8> [[A:%.*]], -; CHECK-NEXT:[[C:%.*]] = and <2 x i8> [[B]], +; CHECK-NEXT:[[TMP1:%.*]] = xor <2 x i8> [[A:%.*]], +; CHECK-NEXT:[[C:%.*]] = and <2 x i8> [[TMP1]], ; CHECK-NEXT:ret <2 x i8> [[C]] ; %B = add <2 x i8> %A, @@ -2546,3 +2546,39 @@ define i32 @and_zext_eq_zero(i32 %A, i32 %C) { %5 = and i32 %2, %4 ret i32 %5 } + +define i32 @canonicalize_and_add_power2_or_zero(i32 %x, i32 %y) { +; CHECK-LABEL: @canonicalize_and_add_power2_or_zero( +; CHECK-NEXT:[[NY:%.*]] = sub i32 0, [[Y:%.*]] +; CHECK-NEXT:[[P2:%.*]] = and i32 [[NY]], [[Y]] +; CHECK-NEXT:call void @use32(i32 [[P2]]) +; CHECK-NEXT:[[TMP1:%.*]] = xor i32 [[X:%.*]], -1 +; CHECK-NEXT:[[AND:%.*]] = and i32 [[P2]], [[TMP1]] +; CHECK-NEXT:ret i32 [[AND]] +; + %ny = sub i32 0, %y + %p2 = and i32 %y, %ny + call void @use32(i32 %p2) ; keep p2 + + %val = add i32 %x, %p2 + %and = and i32 %val, %p2 + ret i32 %and +} + +define i32 @canonicalize_and_sub_power2_or_zero(i32 %x, i32 %y) { +; CHECK-LABEL: @canonicalize_and_sub_power2_or_zero( +; CHECK-NEXT:[[NY:%.*]] = sub i32 0, [[Y:%.*]] +; CHECK-NEXT:[[P2:%.*]] = and i32 [[NY]], [[Y]] +; CHECK-NEXT:call void @use32(i32 [[P2]]) +; CHECK-NEXT:[[TMP1:%.*]] = xor i32 [[X:%.*]], -1 +; CHECK-NEXT:[[AND:%.*]] = and i32 [[P2]], [[TMP1]] +; CHECK-NEXT:ret i32 [[AND]] +; + %ny = sub i32 0, %y + %p2 = and i32 %y, %ny + call void @use32(i32 %p2) ; keep p2 + + %val = sub i32 %x, %p2 + %and = and i32 %val, %p2 + ret i32 %and +} >From b64ca5b5f743e6a935f4ea09154c3a08c6e65c47 Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Fri, 6 Oct 2023 17:32:46 +0800 Subject: [PATCH 2/2] fixup! [InstCombine] Canonicalize `(X +/- Y) & Y` into `~X & Y` when Y is a power of 2 Add additional tests. --- llvm/test/Transforms/InstCombine/and.ll | 123 1 file changed, 123 insertions(+) diff --git a/llvm/test/Transforms/InstCombine/and.ll b/llvm/test/Transforms/InstCombine/and.ll index eb39ff9014ff3a4..989640ed41f2d2e 100644 --- a/llvm/test/Transforms/InstCombine/and.ll +++ b/llvm/test/Transforms/InstCombine/and.ll @@ -2582,3 +2582,126 @@ define i32 @canonicalize_and_sub_power2_or_zero(i32 %x, i32 %y) { %and = and i32 %val, %p2 ret i32 %and } + +define i32 @canonicalize_and_add_power2_or_zero_commuted1(i32 %x, i32 %y) { +; CHECK-LABEL: @canonicalize_and_add_power2_or_zero_commuted1( +; CHECK-NEXT:[[NY:%.*]] = sub i32 0, [[Y:%.*]] +; CHECK-NEXT:[[P2:%.*]] = and i32 [[NY]], [[Y]] +; CHECK-NEXT:call void @use32(i32 [[P2]]) +; CHECK-NEXT:[[TMP1:%.*]] = xor i32 [[X:%.
[clang-tools-extra] [InstCombine] Simplify the pattern `a ne/eq (zext/sext (a ne/eq c))` (PR #65852)
https://github.com/dtcxzyw closed https://github.com/llvm/llvm-project/pull/65852 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [InstCombine] Simplify the pattern `a ne/eq (zext/sext (a ne/eq c))` (PR #65852)
https://github.com/dtcxzyw closed https://github.com/llvm/llvm-project/pull/65852 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Avoid evaluating the BitWidth expression over and over again (PR #66203)
AaronBallman wrote: > Well, this is not going to make a noticeable difference in runtime. > https://reviews.llvm.org/D155548 didn't land because there are no > measurements to make where this makes a measurable difference. Those changes didn't land because no measurements were attempted. Putting up a branch at https://llvm-compile-time-tracker.com/ would help get those measurements to at least start to see if there's benefit or harm from the changes. > As for my earlier comment, it would also make sense to rename that function > to `computeBitWidth()` or just cache the computed value (we compute it when > parsing anyway to diagnose 0 size, etc. right?). Caching the computed value would make sense, but that's sort of the goal of D155548, right? That's a generalized caching mechanism that should mean when we compute it to diagnose 0 size, we never need to re-compute it again. https://github.com/llvm/llvm-project/pull/66203 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Avoid evaluating the BitWidth expression over and over again (PR #66203)
tbaederr wrote: > > Well, this is not going to make a noticeable difference in runtime. > > https://reviews.llvm.org/D155548 didn't land because there are no > > measurements to make where this makes a measurable difference. > > Those changes didn't land because no measurements were attempted. Putting up > a branch at https://llvm-compile-time-tracker.com/ would help get those > measurements to at least start to see if there's benefit or harm from the > changes. I did measure it, but only by myself, I can ask Nikita do use the compile-time tracker as well. > > > As for my earlier comment, it would also make sense to rename that function > > to `computeBitWidth()` or just cache the computed value (we compute it when > > parsing anyway to diagnose 0 size, etc. right?). > > Caching the computed value would make sense, but that's sort of the goal of > D155548, right? That's a generalized caching mechanism that should mean when > we compute it to diagnose 0 size, we never need to re-compute it again. Well yes, we would never compute it again, but we still go through quite a few function calls to figure out that we've already computed it before. For a function called `getBitWidthValue()` I basically assume it has exactly one statement: `return BitWidthValue`. I thought the bitwidth expression will always be a `ConstantExpr`, unless it's value-dependent (in which case it will be a `ConstantExpr` when we instantiate it, right?), but I might be wrong. https://github.com/llvm/llvm-project/pull/66203 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Avoid evaluating the BitWidth expression over and over again (PR #66203)
AaronBallman wrote: > > > Well, this is not going to make a noticeable difference in runtime. > > > https://reviews.llvm.org/D155548 didn't land because there are no > > > measurements to make where this makes a measurable difference. > > > > > > Those changes didn't land because no measurements were attempted. Putting > > up a branch at https://llvm-compile-time-tracker.com/ would help get those > > measurements to at least start to see if there's benefit or harm from the > > changes. > > I did measure it, but only by myself, I can ask Nikita do use the > compile-time tracker as well. Ah, I didn't realize you had measured on your own. But yeah, having some concrete numbers to play with would help. > > > As for my earlier comment, it would also make sense to rename that > > > function to `computeBitWidth()` or just cache the computed value (we > > > compute it when parsing anyway to diagnose 0 size, etc. right?). > > > > > > Caching the computed value would make sense, but that's sort of the goal of > > D155548, right? That's a generalized caching mechanism that should mean > > when we compute it to diagnose 0 size, we never need to re-compute it again. > > Well yes, we would never compute it again, but we still go through quite a > few function calls to figure out that we've already computed it before. For a > function called `getBitWidthValue()` I basically assume it has exactly one > statement: `return BitWidthValue`. I'm hopeful the optimizer ends up inlining at least some of those calls, but otherwise, yeah you're right. > I thought the bitwidth expression will always be a `ConstantExpr`, unless > it's value-dependent (in which case it will be a `ConstantExpr` when we > instantiate it, right?), but I might be wrong. Per spec, it needs to be a constant expression. In terms of our implementation, I would also assume it would either be `ConstantExpr` or `IntegerLiteral` (which, strangely is an `Expr` and not a `ConstantExpr`) https://github.com/llvm/llvm-project/pull/66203 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Sema] Use original template pattern when declaring implicit deduction guides for nested template classes (PR #68379)
https://github.com/erichkeane commented: This seems reasonable, however it needs a release note. https://github.com/llvm/llvm-project/pull/68379 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Sema] Add check for bitfield assignments to larger integral types (PR #68276)
https://github.com/erichkeane commented: Also needs a release note. https://github.com/llvm/llvm-project/pull/68276 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Sema] Add check for bitfield assignments to larger integral types (PR #68276)
https://github.com/erichkeane edited https://github.com/llvm/llvm-project/pull/68276 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Sema] Add check for bitfield assignments to larger integral types (PR #68276)
@@ -6171,6 +6171,9 @@ def warn_signed_bitfield_enum_conversion : Warning< "signed bit-field %0 needs an extra bit to represent the largest positive " "enumerators of %1">, InGroup, DefaultIgnore; +def warn_bitfield_too_small_for_integral_type : Warning< + "bit-field %0 (%1 bits) is not wide enough to store type of %2 ">, + InGroup, DefaultIgnore; erichkeane wrote: While I think this SHOULD be in `-Wconversion`, I think it should be a sub-group of it, so that it can be disabled separately. This is a warning that could likely end up with false positives, and should separately be disable-able. https://github.com/llvm/llvm-project/pull/68276 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Sema] Add check for bitfield assignments to larger integral types (PR #68276)
@@ -0,0 +1,36 @@ +// RUN: %clang_cc1 -Wconversion -fsyntax-only -verify %s + +typedef struct _xx { + int bf:9; // expected-note{{widen this field to 32 bits to store all values of 'int'}} + // expected-note@-1{{widen this field to 16 bits to store all values of 'short'}} erichkeane wrote: I'm questioning the usefulness of the usefulness of this note like this. I think it: 1- should point to the RHS expression of the assignment. 2- Should instead refer to the expression itself (particularly since the one online 7 has the different amount of bits). https://github.com/llvm/llvm-project/pull/68276 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Avoid evaluating the BitWidth expression over and over again (PR #66203)
cor3ntin wrote: > Ah, I didn't realize you had measured on your own. But yeah, having some > concrete numbers to play with would help. I'd like to see rough numbers too but I'm really hoping we can progress https://reviews.llvm.org/D155548. I think it's the worse case it's harmless, at best it could have a pretty big positive impact. https://github.com/llvm/llvm-project/pull/66203 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Avoid evaluating the BitWidth expression over and over again (PR #66203)
tbaederr wrote: http://llvm-compile-time-tracker.com/index.php?config=NewPM-O3&stat=instructions%3Au&remote=tbaederr https://github.com/llvm/llvm-project/pull/66203 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [IPSCCP] Variable not visible at Og. (PR #66745)
https://github.com/CarlosAlbertoEnciso updated https://github.com/llvm/llvm-project/pull/66745 >From b24943f63025822a5c5ba90c4a7b47f7123ec4db Mon Sep 17 00:00:00 2001 From: Carlos Alberto Enciso Date: Mon, 18 Sep 2023 12:29:17 +0100 Subject: [PATCH 1/4] [IPSCCP] Variable not visible at Og: https://bugs.llvm.org/show_bug.cgi?id=51559 https://github.com/llvm/llvm-project/issues/50901 IPSCCP pass removes the global variable and does not create a constant expression for the initializer value. --- llvm/lib/Transforms/IPO/SCCP.cpp | 47 +++ llvm/test/Transforms/SCCP/pr50901.ll | 184 +++ 2 files changed, 231 insertions(+) create mode 100644 llvm/test/Transforms/SCCP/pr50901.ll diff --git a/llvm/lib/Transforms/IPO/SCCP.cpp b/llvm/lib/Transforms/IPO/SCCP.cpp index 84f5bbf7039416b..e09769e00148143 100644 --- a/llvm/lib/Transforms/IPO/SCCP.cpp +++ b/llvm/lib/Transforms/IPO/SCCP.cpp @@ -22,6 +22,7 @@ #include "llvm/Analysis/ValueTracking.h" #include "llvm/IR/AttributeMask.h" #include "llvm/IR/Constants.h" +#include "llvm/IR/DIBuilder.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/ModRef.h" @@ -371,6 +372,52 @@ static bool runIPSCCP( StoreInst *SI = cast(GV->user_back()); SI->eraseFromParent(); } + +// Try to create a debug constant expression for the glbal variable +// initializer value. +SmallVector GVEs; +GV->getDebugInfo(GVEs); +if (GVEs.size() == 1) { + DIBuilder DIB(M); + + // Create integer constant expression. + auto createIntExpression = [&DIB](const Constant *CV) -> DIExpression * { +const APInt &API = dyn_cast(CV)->getValue(); +std::optional InitIntOpt; +if (API.isNonNegative()) + InitIntOpt = API.tryZExtValue(); +else if (auto Temp = API.trySExtValue(); Temp.has_value()) + // Transform a signed optional to unsigned optional. + InitIntOpt = (uint64_t)Temp.value(); +return DIB.createConstantValueExpression(InitIntOpt.value()); + }; + + const Constant *CV = GV->getInitializer(); + Type *Ty = GV->getValueType(); + if (Ty->isIntegerTy()) { +GVEs[0]->replaceOperandWith(1, createIntExpression(CV)); + } else if (Ty->isFloatTy() || Ty->isDoubleTy()) { +const APFloat &APF = dyn_cast(CV)->getValueAPF(); +DIExpression *NewExpr = DIB.createConstantValueExpression( +APF.bitcastToAPInt().getZExtValue()); +GVEs[0]->replaceOperandWith(1, NewExpr); + } else if (Ty->isPointerTy()) { +if (isa(CV)) { + GVEs[0]->replaceOperandWith(1, DIB.createConstantValueExpression(0)); +} else { + if (const ConstantExpr *CE = dyn_cast(CV)) { +if (CE->getNumOperands() == 1) { + const Value *V = CE->getOperand(0); + const Constant *CV = dyn_cast(V); + if (CV && !isa(CV)) +if (const ConstantInt *CI = dyn_cast(CV)) + GVEs[0]->replaceOperandWith(1, createIntExpression(CI)); +} + } +} + } +} + MadeChanges = true; M.eraseGlobalVariable(GV); ++NumGlobalConst; diff --git a/llvm/test/Transforms/SCCP/pr50901.ll b/llvm/test/Transforms/SCCP/pr50901.ll new file mode 100644 index 000..56961d2e32db41c --- /dev/null +++ b/llvm/test/Transforms/SCCP/pr50901.ll @@ -0,0 +1,184 @@ +; RUN: opt -passes=ipsccp -S -o - < %s | FileCheck %s + +; Global variables g_11, g_22, g_33, g_44, g_55, g_66 and g_77 +; are not visible in the debugger. + +; 1 int g_1 = -4; +; 2 float g_2 = 4.44; +; 3 char g_3 = 'a'; +; 4 unsigned g_4 = 4; +; 5 bool g_5 = true; +; 6 int *g_6 = nullptr; +; 7 float*g_7 = nullptr; +; 8 +; 9 static int g_11 = -5; +; 10 static float g_22 = 5.55; +; 11 static char g_33 = 'b'; +; 12 static unsigned g_44 = 5; +; 13 static bool g_55 = true; +; 14 static int *g_66 = nullptr; +; 15 static float*g_77 = (float *)(55 + 15); +; 16 +; 17 void bar() { +; 18 g_1 = g_11; +; 19 g_2 = g_22; +; 20 g_3 = g_33; +; 21 g_4 = g_44; +; 22 g_5 = g_55; +; 23 g_6 = g_66; +; 24 g_7 = g_77; +; 25 } +; 26 +; 27 int main() { +; 28 { +; 29 bar(); +; 30 } +; 31 } + +; CHECK: ![[G1:[0-9]+]] = !DIGlobalVariableExpression(var: ![[DBG1:[0-9]+]], expr: !DIExpression(DW_OP_constu, 18446744073709551611, DW_OP_stack_value)) +; CHECK-DAG: ![[DBG1]] = distinct !DIGlobalVariable(name: "g_11", {{.*}} +; CHECK: ![[G2:[0-9]+]] = !DIGlobalVariableExpression(var: ![[DBG2:[0-9]+]], expr: !DIExpression(DW_OP_constu, 1085381018, DW_OP_stack_value)) +; CHECK-DAG: ![[DBG2]] = distinct !DIGlobalVariable(name: "g_22", {{.*}} +; CHECK: ![[G3:[0-9]+]] = !DIGlobalVariableExpression(var: ![[DBG3:[0-9]+]], expr: !DIExpression(DW_OP_constu, 98, DW_OP_stack_value)) +; CHECK-DAG: ![[DBG3]] = distin
[clang] [IPSCCP] Variable not visible at Og. (PR #66745)
https://github.com/jryans edited https://github.com/llvm/llvm-project/pull/66745 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [IPSCCP] Variable not visible at Og. (PR #66745)
https://github.com/jryans edited https://github.com/llvm/llvm-project/pull/66745 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [IPSCCP] Variable not visible at Og. (PR #66745)
https://github.com/jryans edited https://github.com/llvm/llvm-project/pull/66745 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Emit dummy values for unknown C variables (PR #66749)
https://github.com/AaronBallman approved this pull request. LGTM aside from a commenting nit. https://github.com/llvm/llvm-project/pull/66749 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Emit dummy values for unknown C variables (PR #66749)
https://github.com/AaronBallman edited https://github.com/llvm/llvm-project/pull/66749 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Emit dummy values for unknown C variables (PR #66749)
@@ -208,7 +208,7 @@ class Program final { llvm::DenseMap Records; /// Dummy parameter to generate pointers from. AaronBallman wrote: The comment is no longer quite correct. https://github.com/llvm/llvm-project/pull/66749 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Fixes and closes #53952. Setting the ASTHasCompilerErrors member variable correctly based on the PP diagnostics. (PR #68127)
rajkumarananthu wrote: Thanks for taking care of this @AaronBallman https://github.com/llvm/llvm-project/pull/68127 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Fix typo "x84_64" (PR #68419)
https://github.com/CaseyCarter created https://github.com/llvm/llvm-project/pull/68419 Apparently great minds think alike: I noticed these while correcting the same typo in MSVC's sources. >From 2c4ce58cb944774bcfc404ebbeed167c320fbb28 Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Fri, 6 Oct 2023 07:00:21 -0700 Subject: [PATCH] Fix typo "x84_64" --- clang/test/Driver/cuda-detect.cu | 2 +- llvm/lib/Target/X86/X86RegisterInfo.td | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/test/Driver/cuda-detect.cu b/clang/test/Driver/cuda-detect.cu index ad6b90c90c7b756..077d555a3128f27 100644 --- a/clang/test/Driver/cuda-detect.cu +++ b/clang/test/Driver/cuda-detect.cu @@ -29,7 +29,7 @@ // RUN: --sysroot=%S/Inputs/CUDA-nolibdevice --cuda-path-ignore-env 2>&1 | FileCheck %s -check-prefix NOCUDA // RUN: %clang -v --target=x86_64-unknown-linux \ // RUN: --sysroot=%S/Inputs/CUDA-nolibdevice --cuda-path-ignore-env 2>&1 | FileCheck %s -check-prefix NOCUDA -// RUN: %clang -v --target=x84_64-apple-macosx \ +// RUN: %clang -v --target=x86_64-apple-macosx \ // RUN: --sysroot=%S/Inputs/CUDA-nolibdevice --cuda-path-ignore-env 2>&1 | FileCheck %s -check-prefix NOCUDA // ... unless the user doesn't need libdevice diff --git a/llvm/lib/Target/X86/X86RegisterInfo.td b/llvm/lib/Target/X86/X86RegisterInfo.td index 1e6477e658b9d10..81b7597cc8ea5c0 100644 --- a/llvm/lib/Target/X86/X86RegisterInfo.td +++ b/llvm/lib/Target/X86/X86RegisterInfo.td @@ -508,7 +508,7 @@ def GR64_NOREX_NOSP : RegisterClass<"X86", [i64], 64, (and GR64_NOREX, GR64_NOSP)>; // Register classes used for ABIs that use 32-bit address accesses, -// while using the whole x84_64 ISA. +// while using the whole x86_64 ISA. // In such cases, it is fine to use RIP as we are sure the 32 high // bits are not set. We do not need variants for NOSP as RIP is not ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Fix typo "x84_64" (PR #68419)
llvmbot wrote: @llvm/pr-subscribers-backend-x86 Changes Apparently great minds think alike: I noticed these while correcting the same typo in MSVC's sources. --- Full diff: https://github.com/llvm/llvm-project/pull/68419.diff 2 Files Affected: - (modified) clang/test/Driver/cuda-detect.cu (+1-1) - (modified) llvm/lib/Target/X86/X86RegisterInfo.td (+1-1) ``diff diff --git a/clang/test/Driver/cuda-detect.cu b/clang/test/Driver/cuda-detect.cu index ad6b90c90c7b756..077d555a3128f27 100644 --- a/clang/test/Driver/cuda-detect.cu +++ b/clang/test/Driver/cuda-detect.cu @@ -29,7 +29,7 @@ // RUN: --sysroot=%S/Inputs/CUDA-nolibdevice --cuda-path-ignore-env 2>&1 | FileCheck %s -check-prefix NOCUDA // RUN: %clang -v --target=x86_64-unknown-linux \ // RUN: --sysroot=%S/Inputs/CUDA-nolibdevice --cuda-path-ignore-env 2>&1 | FileCheck %s -check-prefix NOCUDA -// RUN: %clang -v --target=x84_64-apple-macosx \ +// RUN: %clang -v --target=x86_64-apple-macosx \ // RUN: --sysroot=%S/Inputs/CUDA-nolibdevice --cuda-path-ignore-env 2>&1 | FileCheck %s -check-prefix NOCUDA // ... unless the user doesn't need libdevice diff --git a/llvm/lib/Target/X86/X86RegisterInfo.td b/llvm/lib/Target/X86/X86RegisterInfo.td index 1e6477e658b9d10..81b7597cc8ea5c0 100644 --- a/llvm/lib/Target/X86/X86RegisterInfo.td +++ b/llvm/lib/Target/X86/X86RegisterInfo.td @@ -508,7 +508,7 @@ def GR64_NOREX_NOSP : RegisterClass<"X86", [i64], 64, (and GR64_NOREX, GR64_NOSP)>; // Register classes used for ABIs that use 32-bit address accesses, -// while using the whole x84_64 ISA. +// while using the whole x86_64 ISA. // In such cases, it is fine to use RIP as we are sure the 32 high // bits are not set. We do not need variants for NOSP as RIP is not `` https://github.com/llvm/llvm-project/pull/68419 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CUDA][HIP] Fix host/device context in concept (PR #67721)
@@ -176,3 +176,34 @@ Predefined Macros * - ``HIP_API_PER_THREAD_DEFAULT_STREAM`` - Alias to ``__HIP_API_PER_THREAD_DEFAULT_STREAM__``. Deprecated. +C++20 Concepts with HIP and CUDA + + +In Clang, when working with HIP or CUDA, it's important to note that all constraints in C++20 concepts are assumed to be for the host side only. This behavior is consistent across both programming models, and developers should be aware of this assumption when writing code that utilizes C++20 concepts. + +Example: +.. code-block:: c++ + + template + concept MyConcept = requires(T& obj) { + my_function(obj); // Assumed to be a host-side requirement yxsamliu wrote: currently, we do not support that. I would suggest adding an extension to the clang that allows `__host__` and `__device__` attributes on call expressions in concept definition to indicate the required callability for the host or device. For example, ``` template concept MyConcept = requires(T& obj) { __device__ my_function(obj); // requires my_function(obj) callable on device side } ``` https://github.com/llvm/llvm-project/pull/67721 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Fix typo "x84_64" (PR #68419)
https://github.com/phoebewang approved this pull request. Good catch, thanks! https://github.com/llvm/llvm-project/pull/68419 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Avoid evaluating the BitWidth expression over and over again (PR #66203)
tbaederr wrote: ^ Removing integer and boolean expressions seems to have some negative impact though. https://github.com/llvm/llvm-project/pull/66203 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Fix typo "x84_64" (PR #68419)
CaseyCarter wrote: The test failure _cannot possibly_ be related to this nearly non-functional change. Shall I merge anyway, or rerun? ``` TEST 'BOLT :: RISCV/reloc-tls.s' FAILED | Exit Code: 1 | | Command Output (stderr): | -- | RUN: at line 1: /var/lib/buildkite-agent/builds/linux-56-7f758798dd-khkmx-1/llvm-project/github-pull-requests/build/bin/llvm-mc -triple riscv64 -filetype obj -o /var/lib/buildkite-agent/builds/linux-56-7f758798dd-khkmx-1/llvm-project/github-pull-requests/build/tools/bolt/test/RISCV/Output/reloc-tls.s.tmp.o /var/lib/buildkite-agent/builds/linux-56-7f758798dd-khkmx-1/llvm-project/github-pull-requests/bolt/test/RISCV/reloc-tls.s | + /var/lib/buildkite-agent/builds/linux-56-7f758798dd-khkmx-1/llvm-project/github-pull-requests/build/bin/llvm-mc -triple riscv64 -filetype obj -o /var/lib/buildkite-agent/builds/linux-56-7f758798dd-khkmx-1/llvm-project/github-pull-requests/build/tools/bolt/test/RISCV/Output/reloc-tls.s.tmp.o /var/lib/buildkite-agent/builds/linux-56-7f758798dd-khkmx-1/llvm-project/github-pull-requests/bolt/test/RISCV/reloc-tls.s | RUN: at line 2: /var/lib/buildkite-agent/builds/linux-56-7f758798dd-khkmx-1/llvm-project/github-pull-requests/build/bin/ld.lld --emit-relocs -o /var/lib/buildkite-agent/builds/linux-56-7f758798dd-khkmx-1/llvm-project/github-pull-requests/build/tools/bolt/test/RISCV/Output/reloc-tls.s.tmp /var/lib/buildkite-agent/builds/linux-56-7f758798dd-khkmx-1/llvm-project/github-pull-requests/build/tools/bolt/test/RISCV/Output/reloc-tls.s.tmp.o | + /var/lib/buildkite-agent/builds/linux-56-7f758798dd-khkmx-1/llvm-project/github-pull-requests/build/bin/ld.lld --emit-relocs -o /var/lib/buildkite-agent/builds/linux-56-7f758798dd-khkmx-1/llvm-project/github-pull-requests/build/tools/bolt/test/RISCV/Output/reloc-tls.s.tmp /var/lib/buildkite-agent/builds/linux-56-7f758798dd-khkmx-1/llvm-project/github-pull-requests/build/tools/bolt/test/RISCV/Output/reloc-tls.s.tmp.o | RUN: at line 3: /var/lib/buildkite-agent/builds/linux-56-7f758798dd-khkmx-1/llvm-project/github-pull-requests/build/bin/llvm-bolt --print-cfg --print-only=tls_le,tls_ie -o /dev/null /var/lib/buildkite-agent/builds/linux-56-7f758798dd-khkmx-1/llvm-project/github-pull-requests/build/tools/bolt/test/RISCV/Output/reloc-tls.s.tmp \| /var/lib/buildkite-agent/builds/linux-56-7f758798dd-khkmx-1/llvm-project/github-pull-requests/build/bin/FileCheck /var/lib/buildkite-agent/builds/linux-56-7f758798dd-khkmx-1/llvm-project/github-pull-requests/bolt/test/RISCV/reloc-tls.s | + /var/lib/buildkite-agent/builds/linux-56-7f758798dd-khkmx-1/llvm-project/github-pull-requests/build/bin/FileCheck /var/lib/buildkite-agent/builds/linux-56-7f758798dd-khkmx-1/llvm-project/github-pull-requests/bolt/test/RISCV/reloc-tls.s | + /var/lib/buildkite-agent/builds/linux-56-7f758798dd-khkmx-1/llvm-project/github-pull-requests/build/bin/llvm-bolt --print-cfg --print-only=tls_le,tls_ie -o /dev/null /var/lib/buildkite-agent/builds/linux-56-7f758798dd-khkmx-1/llvm-project/github-pull-requests/build/tools/bolt/test/RISCV/Output/reloc-tls.s.tmp | /var/lib/buildkite-agent/builds/linux-56-7f758798dd-khkmx-1/llvm-project/github-pull-requests/bolt/test/RISCV/reloc-tls.s:14:11: error: CHECK: expected string not found in input | // CHECK: auipc a0, %pcrel_hi(__BOLT_got_zero+{{[0-9]+}}) | ^ | :63:70: note: scanning from here | 0004: auipc a0, %pcrel_hi(__BOLT_got_zero+74232) # Label: .Ltmp0 | ^ | :64:9: note: possible intended match here | 0008: ld a0, %pcrel_lo(.Ltmp0)(a0) | ^ | | Input file: | Check file: /var/lib/buildkite-agent/builds/linux-56-7f758798dd-khkmx-1/llvm-project/github-pull-requests/bolt/test/RISCV/reloc-tls.s | | -dump-input=help explains the following input dump. | | Input was: | << | . | . | . | 58: } | 59: .LBB01 (4 instructions, align : 1) | 60: Entry Point | 61: CFI State : 0 | 62: : addi zero, zero, 0 # Size: 4 # NOP: 1 | 63: 0004: auipc a0, %pcrel_hi(__BOLT_got_zero+74232) # Label: .Ltmp0 | check:14'0 X error: no match found | 64: 0008: ld a0, %pcrel_lo(.Ltmp0)(a0) | check:14'0 | check:14'1 ?possible intended match | 65: 000c: jalr zero, 0(ra) | check:14'0 | 66: CFI State: 0 | check:14'0 ~~ | 67: | check:14'0 ~ | 68: DWARF CFI Instructions: | check:14'0 | 69: | check:14'0 ~ | . | . | . | >> ``` https://github.com/llvm/llvm-project/pull/68419 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Fix typo "x84_64" (PR #68419)
phoebewang wrote: I think it's ok to merge. https://github.com/llvm/llvm-project/pull/68419 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 07f7f1c - Fix typo "x84_64" (#68419)
Author: Casey Carter Date: 2023-10-06T08:04:35-07:00 New Revision: 07f7f1ce10dd668718a3ad009a284706ef00555c URL: https://github.com/llvm/llvm-project/commit/07f7f1ce10dd668718a3ad009a284706ef00555c DIFF: https://github.com/llvm/llvm-project/commit/07f7f1ce10dd668718a3ad009a284706ef00555c.diff LOG: Fix typo "x84_64" (#68419) Added: Modified: clang/test/Driver/cuda-detect.cu llvm/lib/Target/X86/X86RegisterInfo.td Removed: diff --git a/clang/test/Driver/cuda-detect.cu b/clang/test/Driver/cuda-detect.cu index ad6b90c90c7b756..077d555a3128f27 100644 --- a/clang/test/Driver/cuda-detect.cu +++ b/clang/test/Driver/cuda-detect.cu @@ -29,7 +29,7 @@ // RUN: --sysroot=%S/Inputs/CUDA-nolibdevice --cuda-path-ignore-env 2>&1 | FileCheck %s -check-prefix NOCUDA // RUN: %clang -v --target=x86_64-unknown-linux \ // RUN: --sysroot=%S/Inputs/CUDA-nolibdevice --cuda-path-ignore-env 2>&1 | FileCheck %s -check-prefix NOCUDA -// RUN: %clang -v --target=x84_64-apple-macosx \ +// RUN: %clang -v --target=x86_64-apple-macosx \ // RUN: --sysroot=%S/Inputs/CUDA-nolibdevice --cuda-path-ignore-env 2>&1 | FileCheck %s -check-prefix NOCUDA // ... unless the user doesn't need libdevice diff --git a/llvm/lib/Target/X86/X86RegisterInfo.td b/llvm/lib/Target/X86/X86RegisterInfo.td index 1e6477e658b9d10..81b7597cc8ea5c0 100644 --- a/llvm/lib/Target/X86/X86RegisterInfo.td +++ b/llvm/lib/Target/X86/X86RegisterInfo.td @@ -508,7 +508,7 @@ def GR64_NOREX_NOSP : RegisterClass<"X86", [i64], 64, (and GR64_NOREX, GR64_NOSP)>; // Register classes used for ABIs that use 32-bit address accesses, -// while using the whole x84_64 ISA. +// while using the whole x86_64 ISA. // In such cases, it is fine to use RIP as we are sure the 32 high // bits are not set. We do not need variants for NOSP as RIP is not ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Fix typo "x84_64" (PR #68419)
https://github.com/CaseyCarter closed https://github.com/llvm/llvm-project/pull/68419 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Sema] Add check for bitfield assignments to larger integral types (PR #68276)
@@ -6171,6 +6171,9 @@ def warn_signed_bitfield_enum_conversion : Warning< "signed bit-field %0 needs an extra bit to represent the largest positive " "enumerators of %1">, InGroup, DefaultIgnore; +def warn_bitfield_too_small_for_integral_type : Warning< + "bit-field %0 (%1 bits) is not wide enough to store type of %2 ">, + InGroup, DefaultIgnore; vabridgers wrote: Thanks @erichkeane, understood. I'm thinking this warning should be disabled by default and then explicitly enabled only if the user wants to enable it. Do you agree, or have different ideas about the use cases? https://github.com/llvm/llvm-project/pull/68276 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Sema] Add check for bitfield assignments to larger integral types (PR #68276)
@@ -0,0 +1,36 @@ +// RUN: %clang_cc1 -Wconversion -fsyntax-only -verify %s + +typedef struct _xx { + int bf:9; // expected-note{{widen this field to 32 bits to store all values of 'int'}} + // expected-note@-1{{widen this field to 16 bits to store all values of 'short'}} vabridgers wrote: Thanks @erichkeane, I'll iterate on improving the note. https://github.com/llvm/llvm-project/pull/68276 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Sema] Add check for bitfield assignments to larger integral types (PR #68276)
vabridgers wrote: I'll add a release note also in the next iteration. Thanks https://github.com/llvm/llvm-project/pull/68276 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [InstCombine] Add combines/simplifications for `llvm.ptrmask` (PR #67166)
@@ -6397,6 +6397,41 @@ static Value *simplifyBinaryIntrinsic(Function *F, Value *Op0, Value *Op1, return Constant::getNullValue(ReturnType); break; } + case Intrinsic::ptrmask: { +if (isa(Op0) || isa(Op1)) + return PoisonValue::get(Op0->getType()); + +// NOTE: We can't apply this simplifications based on the value of Op1 +// because we need to preserve provenance. +if (Q.isUndefValue(Op0) || match(Op0, m_Zero())) + return Constant::getNullValue(Op0->getType()); + +if (Op1->getType()->getScalarSizeInBits() == +Q.DL.getPointerTypeSizeInBits(Op0->getType())) { + if (match(Op1, m_PtrToInt(m_Specific(Op0 +return Op0; + + // NOTE: We may have attributes associated with the return value of the + // llvm.ptrmask intrinsic that will be lost when we just return the + // operand. We should try to preserve them. + if (match(Op1, m_AllOnes()) || Q.isUndefValue(Op1)) +return Op0; + + Constant *C; + if (match(Op1, m_ImmConstant(C))) { +KnownBits PtrKnown = +computeKnownBits(Op0, Q.DL, /*Depth*/ 0, Q.AC, Q.CxtI, Q.DT); arsenm wrote: need Depth= to make clang-format happy I think https://github.com/llvm/llvm-project/pull/67166 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HIP] Document func ptr and virtual func (PR #68126)
@@ -176,3 +176,65 @@ Predefined Macros * - ``HIP_API_PER_THREAD_DEFAULT_STREAM`` - Alias to ``__HIP_API_PER_THREAD_DEFAULT_STREAM__``. Deprecated. +Function Pointers Support in Clang with HIP +=== + +Function pointers' support varies with the usage mode in Clang with HIP. The following table provides an overview of the support status across different use-cases and modes. + +.. list-table:: Function Pointers Support Overview + :widths: 25 25 25 + :header-rows: 1 + + * - Use Case + - ``-fno-gpu-rdc`` Mode (default) + - ``-fgpu-rdc`` Mode + * - Defined and used in the same TU + - Supported + - Supported + * - Defined in one TU and used in another TU + - Not Supported + - Supported + +In the ``-fno-gpu-rdc`` mode, the compiler calculates the resource usage of kernels based only on functions present within the same Translation Unit (TU). This mode does not support the use of function pointers defined in a different TU due to the possibility of incorrect resource usage calculations, leading to undefined behavior. yxsamliu wrote: will do https://github.com/llvm/llvm-project/pull/68126 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] Fix crash when import `VarTemplateDecl` in record (PR #67522)
https://github.com/balazske approved this pull request. https://github.com/llvm/llvm-project/pull/67522 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [MLIR][Presburger] Fix reduce bug in Fraction class and add tests (PR #68298)
https://github.com/Superty closed https://github.com/llvm/llvm-project/pull/68298 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits