[llvm-branch-commits] [llvm] [LoongArch][DAGCombiner] Combine vand (vnot ..) to vandn (PR #161037)
ylzsx wrote: ping https://github.com/llvm/llvm-project/pull/161037 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] DAG: Add AssertNoFPClass from call return attributes (PR #167264)
arsenm wrote: > [!WARNING] > This pull request is not mergeable via GitHub because a downstack PR is > open. Once all requirements are satisfied, merge this PR as a stack href="https://app.graphite.com/github/pr/llvm/llvm-project/167264?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#167264** https://app.graphite.com/github/pr/llvm/llvm-project/167264?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> π https://app.graphite.com/github/pr/llvm/llvm-project/167264?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#167263** https://app.graphite.com/github/pr/llvm/llvm-project/167263?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/167264 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] DAG: Add AssertNoFPClass from call return attributes (PR #167264)
https://github.com/arsenm created
https://github.com/llvm/llvm-project/pull/167264
This defends against regressions in future patches. This excludes
the target intrinsic case for now; I'm worried introducing an intermediate
AssertNoFPClass is likely to break combines.
>From 0696fe61de175a41ac8a67c265a97e1611b9c5ab Mon Sep 17 00:00:00 2001
From: Matt Arsenault
Date: Sun, 9 Nov 2025 18:45:32 -0800
Subject: [PATCH] DAG: Add AssertNoFPClass from call return attributes
This defends against regressions in future patches. This excludes
the target intrinsic case for now; I'm worried introducing an intermediate
AssertNoFPClass is likely to break combines.
---
.../SelectionDAG/SelectionDAGBuilder.cpp| 17 +
.../CodeGen/SelectionDAG/SelectionDAGBuilder.h | 4
llvm/test/CodeGen/AMDGPU/nofpclass-call.ll | 16
3 files changed, 25 insertions(+), 12 deletions(-)
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 88b0809b767b5..6a9022dff41ad 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -4638,6 +4638,12 @@ static std::optional getRange(const
Instruction &I) {
return std::nullopt;
}
+static FPClassTest getNoFPClass(const Instruction &I) {
+ if (const auto *CB = dyn_cast(&I))
+return CB->getRetNoFPClass();
+ return fcNone;
+}
+
void SelectionDAGBuilder::visitLoad(const LoadInst &I) {
if (I.isAtomic())
return visitAtomicLoad(I);
@@ -9132,6 +9138,7 @@ void SelectionDAGBuilder::LowerCallTo(const CallBase &CB,
SDValue Callee,
if (Result.first.getNode()) {
Result.first = lowerRangeToAssertZExt(DAG, CB, Result.first);
+Result.first = lowerNoFPClassToAssertNoFPClass(DAG, CB, Result.first);
setValue(&CB, Result.first);
}
@@ -10718,6 +10725,16 @@ SDValue
SelectionDAGBuilder::lowerRangeToAssertZExt(SelectionDAG &DAG,
return DAG.getMergeValues(Ops, SL);
}
+SDValue SelectionDAGBuilder::lowerNoFPClassToAssertNoFPClass(
+SelectionDAG &DAG, const Instruction &I, SDValue Op) {
+ FPClassTest Classes = getNoFPClass(I);
+ if (Classes == fcNone)
+return Op;
+
+ return DAG.getNode(ISD::AssertNoFPClass, SDLoc(Op), Op.getValueType(), Op,
+ DAG.getTargetConstant(Classes, SDLoc(), MVT::i32));
+}
+
/// Populate a CallLowerinInfo (into \p CLI) based on the properties of
/// the call being lowered.
///
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
index ed63bee58c957..13e2daa783147 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
@@ -429,6 +429,10 @@ class SelectionDAGBuilder {
SDValue lowerRangeToAssertZExt(SelectionDAG &DAG, const Instruction &I,
SDValue Op);
+ // Lower nofpclass attributes to AssertNoFPClass
+ SDValue lowerNoFPClassToAssertNoFPClass(SelectionDAG &DAG,
+ const Instruction &I, SDValue Op);
+
void populateCallLoweringInfo(TargetLowering::CallLoweringInfo &CLI,
const CallBase *Call, unsigned ArgIdx,
unsigned NumArgs, SDValue Callee,
diff --git a/llvm/test/CodeGen/AMDGPU/nofpclass-call.ll
b/llvm/test/CodeGen/AMDGPU/nofpclass-call.ll
index 1861f02ec8b1c..5f303cc2a1eef 100644
--- a/llvm/test/CodeGen/AMDGPU/nofpclass-call.ll
+++ b/llvm/test/CodeGen/AMDGPU/nofpclass-call.ll
@@ -35,9 +35,7 @@ define float @call_nofpclass_funcs_f32(ptr addrspace(1) %ptr)
{
; CHECK-NEXT:v_mov_b32_e32 v3, v0
; CHECK-NEXT:v_mov_b32_e32 v0, v2
; CHECK-NEXT:s_swappc_b64 s[30:31], s[16:17]
-; CHECK-NEXT:v_max_f32_e32 v1, v3, v3
-; CHECK-NEXT:v_max_f32_e32 v0, v0, v0
-; CHECK-NEXT:v_min_f32_e32 v0, v1, v0
+; CHECK-NEXT:v_min_f32_e32 v0, v3, v0
; CHECK-NEXT:v_readlane_b32 s31, v4, 1
; CHECK-NEXT:v_readlane_b32 s30, v4, 0
; CHECK-NEXT:s_mov_b32 s32, s33
@@ -87,12 +85,8 @@ define <2 x float> @call_nofpclass_funcs_v2f32(ptr
addrspace(1) %ptr) {
; CHECK-NEXT:v_mov_b32_e32 v0, v3
; CHECK-NEXT:v_mov_b32_e32 v1, v2
; CHECK-NEXT:s_swappc_b64 s[30:31], s[16:17]
-; CHECK-NEXT:v_max_f32_e32 v2, v4, v4
-; CHECK-NEXT:v_max_f32_e32 v0, v0, v0
-; CHECK-NEXT:v_min_f32_e32 v0, v2, v0
-; CHECK-NEXT:v_max_f32_e32 v2, v5, v5
-; CHECK-NEXT:v_max_f32_e32 v1, v1, v1
-; CHECK-NEXT:v_min_f32_e32 v1, v2, v1
+; CHECK-NEXT:v_min_f32_e32 v0, v4, v0
+; CHECK-NEXT:v_min_f32_e32 v1, v5, v1
; CHECK-NEXT:v_readlane_b32 s31, v6, 1
; CHECK-NEXT:v_readlane_b32 s30, v6, 0
; CHECK-NEXT:s_mov_b32 s32, s33
@@ -142,12 +136,10 @@ define double @call_nofpclass_funcs_f64(ptr addrspace(1)
%ptr) {
; CHECK-NEXT:v_mov_b32_e32 v0, v5
; CHECK-NEXT:v_mov_b32_e32 v1, v4
; CHECK-NEXT:s_swappc_b64
[llvm-branch-commits] [llvm] DAG: Add AssertNoFPClass from call return attributes (PR #167264)
llvmbot wrote:
@llvm/pr-subscribers-llvm-selectiondag
Author: Matt Arsenault (arsenm)
Changes
This defends against regressions in future patches. This excludes
the target intrinsic case for now; I'm worried introducing an intermediate
AssertNoFPClass is likely to break combines.
---
Full diff: https://github.com/llvm/llvm-project/pull/167264.diff
3 Files Affected:
- (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (+17)
- (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h (+4)
- (modified) llvm/test/CodeGen/AMDGPU/nofpclass-call.ll (+4-12)
``diff
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 88b0809b767b5..6a9022dff41ad 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -4638,6 +4638,12 @@ static std::optional getRange(const
Instruction &I) {
return std::nullopt;
}
+static FPClassTest getNoFPClass(const Instruction &I) {
+ if (const auto *CB = dyn_cast(&I))
+return CB->getRetNoFPClass();
+ return fcNone;
+}
+
void SelectionDAGBuilder::visitLoad(const LoadInst &I) {
if (I.isAtomic())
return visitAtomicLoad(I);
@@ -9132,6 +9138,7 @@ void SelectionDAGBuilder::LowerCallTo(const CallBase &CB,
SDValue Callee,
if (Result.first.getNode()) {
Result.first = lowerRangeToAssertZExt(DAG, CB, Result.first);
+Result.first = lowerNoFPClassToAssertNoFPClass(DAG, CB, Result.first);
setValue(&CB, Result.first);
}
@@ -10718,6 +10725,16 @@ SDValue
SelectionDAGBuilder::lowerRangeToAssertZExt(SelectionDAG &DAG,
return DAG.getMergeValues(Ops, SL);
}
+SDValue SelectionDAGBuilder::lowerNoFPClassToAssertNoFPClass(
+SelectionDAG &DAG, const Instruction &I, SDValue Op) {
+ FPClassTest Classes = getNoFPClass(I);
+ if (Classes == fcNone)
+return Op;
+
+ return DAG.getNode(ISD::AssertNoFPClass, SDLoc(Op), Op.getValueType(), Op,
+ DAG.getTargetConstant(Classes, SDLoc(), MVT::i32));
+}
+
/// Populate a CallLowerinInfo (into \p CLI) based on the properties of
/// the call being lowered.
///
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
index ed63bee58c957..13e2daa783147 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
@@ -429,6 +429,10 @@ class SelectionDAGBuilder {
SDValue lowerRangeToAssertZExt(SelectionDAG &DAG, const Instruction &I,
SDValue Op);
+ // Lower nofpclass attributes to AssertNoFPClass
+ SDValue lowerNoFPClassToAssertNoFPClass(SelectionDAG &DAG,
+ const Instruction &I, SDValue Op);
+
void populateCallLoweringInfo(TargetLowering::CallLoweringInfo &CLI,
const CallBase *Call, unsigned ArgIdx,
unsigned NumArgs, SDValue Callee,
diff --git a/llvm/test/CodeGen/AMDGPU/nofpclass-call.ll
b/llvm/test/CodeGen/AMDGPU/nofpclass-call.ll
index 1861f02ec8b1c..5f303cc2a1eef 100644
--- a/llvm/test/CodeGen/AMDGPU/nofpclass-call.ll
+++ b/llvm/test/CodeGen/AMDGPU/nofpclass-call.ll
@@ -35,9 +35,7 @@ define float @call_nofpclass_funcs_f32(ptr addrspace(1) %ptr)
{
; CHECK-NEXT:v_mov_b32_e32 v3, v0
; CHECK-NEXT:v_mov_b32_e32 v0, v2
; CHECK-NEXT:s_swappc_b64 s[30:31], s[16:17]
-; CHECK-NEXT:v_max_f32_e32 v1, v3, v3
-; CHECK-NEXT:v_max_f32_e32 v0, v0, v0
-; CHECK-NEXT:v_min_f32_e32 v0, v1, v0
+; CHECK-NEXT:v_min_f32_e32 v0, v3, v0
; CHECK-NEXT:v_readlane_b32 s31, v4, 1
; CHECK-NEXT:v_readlane_b32 s30, v4, 0
; CHECK-NEXT:s_mov_b32 s32, s33
@@ -87,12 +85,8 @@ define <2 x float> @call_nofpclass_funcs_v2f32(ptr
addrspace(1) %ptr) {
; CHECK-NEXT:v_mov_b32_e32 v0, v3
; CHECK-NEXT:v_mov_b32_e32 v1, v2
; CHECK-NEXT:s_swappc_b64 s[30:31], s[16:17]
-; CHECK-NEXT:v_max_f32_e32 v2, v4, v4
-; CHECK-NEXT:v_max_f32_e32 v0, v0, v0
-; CHECK-NEXT:v_min_f32_e32 v0, v2, v0
-; CHECK-NEXT:v_max_f32_e32 v2, v5, v5
-; CHECK-NEXT:v_max_f32_e32 v1, v1, v1
-; CHECK-NEXT:v_min_f32_e32 v1, v2, v1
+; CHECK-NEXT:v_min_f32_e32 v0, v4, v0
+; CHECK-NEXT:v_min_f32_e32 v1, v5, v1
; CHECK-NEXT:v_readlane_b32 s31, v6, 1
; CHECK-NEXT:v_readlane_b32 s30, v6, 0
; CHECK-NEXT:s_mov_b32 s32, s33
@@ -142,12 +136,10 @@ define double @call_nofpclass_funcs_f64(ptr addrspace(1)
%ptr) {
; CHECK-NEXT:v_mov_b32_e32 v0, v5
; CHECK-NEXT:v_mov_b32_e32 v1, v4
; CHECK-NEXT:s_swappc_b64 s[30:31], s[16:17]
-; CHECK-NEXT:v_max_f64 v[2:3], v[2:3], v[2:3]
-; CHECK-NEXT:v_max_f64 v[0:1], v[0:1], v[0:1]
+; CHECK-NEXT:v_min_f64 v[0:1], v[2:3], v[0:1]
; CHECK-NEXT:v_readlane_b32 s31, v6, 1
; CHECK-NEXT:v_readlane_b32 s30, v6, 0
; CHECK-NEXT:s_mov_b32 s32, s33
-; CHECK-NEXT:
[llvm-branch-commits] [NFC][SpecialCaseList] Refactor error handling (PR #167277)
llvmbot wrote:
@llvm/pr-subscribers-llvm-support
Author: Vitaly Buka (vitalybuka)
Changes
Will help in future patches.
---
Full diff: https://github.com/llvm/llvm-project/pull/167277.diff
1 Files Affected:
- (modified) llvm/lib/Support/SpecialCaseList.cpp (+7-5)
``diff
diff --git a/llvm/lib/Support/SpecialCaseList.cpp
b/llvm/lib/Support/SpecialCaseList.cpp
index 395a55d75acd4..beec8b8ef0d5b 100644
--- a/llvm/lib/Support/SpecialCaseList.cpp
+++ b/llvm/lib/Support/SpecialCaseList.cpp
@@ -274,11 +274,12 @@ bool SpecialCaseList::parse(unsigned FileIdx, const
MemoryBuffer *MB,
bool RemoveDotSlash = Version > 2;
- Section *CurrentSection;
- if (auto Err = addSection("*", FileIdx, 1, true).moveInto(CurrentSection)) {
+ auto ErrOrSection = addSection("*", FileIdx, 1, true);
+ if (auto Err = ErrOrSection.takeError()) {
Error = toString(std::move(Err));
return false;
}
+ Section *CurrentSection = ErrOrSection.get();
// This is the current list of prefixes for all existing users matching file
// path. We may need parametrization in constructor in future.
@@ -300,12 +301,13 @@ bool SpecialCaseList::parse(unsigned FileIdx, const
MemoryBuffer *MB,
return false;
}
- if (auto Err = addSection(Line.drop_front().drop_back(), FileIdx, LineNo,
-UseGlobs)
- .moveInto(CurrentSection)) {
+ auto ErrOrSection =
+ addSection(Line.drop_front().drop_back(), FileIdx, LineNo, UseGlobs);
+ if (auto Err = ErrOrSection.takeError()) {
Error = toString(std::move(Err));
return false;
}
+ CurrentSection = ErrOrSection.get();
continue;
}
``
https://github.com/llvm/llvm-project/pull/167277
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] WIP: DotSlash backward compartible (PR #162511)
https://github.com/vitalybuka edited https://github.com/llvm/llvm-project/pull/162511 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] WIP: DotSlash backward compartible (PR #162511)
https://github.com/vitalybuka updated
https://github.com/llvm/llvm-project/pull/162511
>From 8122ad974f18892e829843710958fbd4bac0926e Mon Sep 17 00:00:00 2001
From: Vitaly Buka
Date: Wed, 8 Oct 2025 09:41:04 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20change?=
=?UTF-8?q?s=20to=20main=20this=20commit=20is=20based=20on?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.6
[skip ci]
---
llvm/include/llvm/Support/SpecialCaseList.h | 1 +
llvm/lib/Support/SpecialCaseList.cpp | 9 +++
.../unittests/Support/SpecialCaseListTest.cpp | 62 +++
3 files changed, 60 insertions(+), 12 deletions(-)
diff --git a/llvm/include/llvm/Support/SpecialCaseList.h
b/llvm/include/llvm/Support/SpecialCaseList.h
index 64cad804ad911..d8dd1c4ec4bbc 100644
--- a/llvm/include/llvm/Support/SpecialCaseList.h
+++ b/llvm/include/llvm/Support/SpecialCaseList.h
@@ -156,6 +156,7 @@ class SpecialCaseList {
std::vector> Globs;
std::vector> RegExes;
+bool RemoveDotSlash = false;
};
using SectionEntries = StringMap>;
diff --git a/llvm/lib/Support/SpecialCaseList.cpp
b/llvm/lib/Support/SpecialCaseList.cpp
index 6ad8d7d4e7ffa..636dc5e651f56 100644
--- a/llvm/lib/Support/SpecialCaseList.cpp
+++ b/llvm/lib/Support/SpecialCaseList.cpp
@@ -22,6 +22,7 @@
#include "llvm/Support/VirtualFileSystem.h"
#include
#include
+#include
#include
#include
#include
@@ -72,6 +73,8 @@ Error SpecialCaseList::Matcher::insert(StringRef Pattern,
unsigned LineNumber,
void SpecialCaseList::Matcher::match(
StringRef Query,
llvm::function_ref Cb) const {
+ if (RemoveDotSlash)
+Query = llvm::sys::path::remove_leading_dotslash(Query);
for (const auto &Glob : reverse(Globs))
if (Glob->Pattern.match(Query))
Cb(Glob->Name, Glob->LineNo);
@@ -164,12 +167,16 @@ bool SpecialCaseList::parse(unsigned FileIdx, const
MemoryBuffer *MB,
//
https://discourse.llvm.org/t/use-glob-instead-of-regex-for-specialcaselists/71666
bool UseGlobs = Version > 1;
+ bool RemoveDotSlash = Version > 2;
+
Section *CurrentSection;
if (auto Err = addSection("*", FileIdx, 1).moveInto(CurrentSection)) {
Error = toString(std::move(Err));
return false;
}
+ constexpr StringRef PathPrefixes[] = {"src", "!src", "mainfile", "source"};
+
for (line_iterator LineIt(*MB, /*SkipBlanks=*/true, /*CommentMarker=*/'#');
!LineIt.is_at_eof(); LineIt++) {
unsigned LineNo = LineIt.line_number();
@@ -205,6 +212,8 @@ bool SpecialCaseList::parse(unsigned FileIdx, const
MemoryBuffer *MB,
auto [Pattern, Category] = Postfix.split("=");
auto &Entry = CurrentSection->Entries[Prefix][Category];
+Entry.RemoveDotSlash =
+RemoveDotSlash && llvm::is_contained(PathPrefixes, Prefix);
if (auto Err = Entry.insert(Pattern, LineNo, UseGlobs)) {
Error =
(Twine("malformed ") + (UseGlobs ? "glob" : "regex") + " in line " +
diff --git a/llvm/unittests/Support/SpecialCaseListTest.cpp
b/llvm/unittests/Support/SpecialCaseListTest.cpp
index 5be2b9e3a7a5d..750fedaf0a436 100644
--- a/llvm/unittests/Support/SpecialCaseListTest.cpp
+++ b/llvm/unittests/Support/SpecialCaseListTest.cpp
@@ -22,33 +22,31 @@ namespace {
class SpecialCaseListTest : public ::testing::Test {
protected:
- std::unique_ptr makeSpecialCaseList(StringRef List,
- std::string &Error,
- bool UseGlobs = true) {
+ std::unique_ptr
+ makeSpecialCaseList(StringRef List, std::string &Error, int Version = 0) {
auto S = List.str();
-if (!UseGlobs)
- S = (Twine("#!special-case-list-v1\n") + S).str();
+if (Version)
+ S = (Twine("#!special-case-list-v") + Twine(Version) + "\n" + S).str();
std::unique_ptr MB = MemoryBuffer::getMemBuffer(S);
return SpecialCaseList::create(MB.get(), Error);
}
std::unique_ptr makeSpecialCaseList(StringRef List,
- bool UseGlobs = true) {
+ int Version = 0) {
std::string Error;
-auto SCL = makeSpecialCaseList(List, Error, UseGlobs);
+auto SCL = makeSpecialCaseList(List, Error, Version);
assert(SCL);
assert(Error == "");
return SCL;
}
- std::string makeSpecialCaseListFile(StringRef Contents,
- bool UseGlobs = true) {
+ std::string makeSpecialCaseListFile(StringRef Contents, int Version = 0) {
int FD;
SmallString<64> Path;
sys::fs::createTemporaryFile("SpecialCaseListTest", "temp", FD, Path);
raw_fd_ostream OF(FD, true, true);
-if (!UseGlobs)
- OF << "#!special-case-list-v1\n";
+if (Version)
+ OF << "#!special-case-list-v" << Version << "\n";
OF << Contents;
OF.close();
return std::string(Path.str());
@@ -26
[llvm-branch-commits] [NFC][SpecialCaseList] Rename `Section::SectionStr` to `Name` (PR #167279)
llvmbot wrote:
@llvm/pr-subscribers-llvm-support
Author: Vitaly Buka (vitalybuka)
Changes
---
Full diff: https://github.com/llvm/llvm-project/pull/167279.diff
1 Files Affected:
- (modified) llvm/include/llvm/Support/SpecialCaseList.h (+4-4)
``diff
diff --git a/llvm/include/llvm/Support/SpecialCaseList.h
b/llvm/include/llvm/Support/SpecialCaseList.h
index f904e582b5cee..8c4dc94ae54ce 100644
--- a/llvm/include/llvm/Support/SpecialCaseList.h
+++ b/llvm/include/llvm/Support/SpecialCaseList.h
@@ -197,14 +197,14 @@ class SpecialCaseList {
protected:
class Section {
public:
-Section(StringRef Str, unsigned FileIdx, bool UseGlobs)
-: SectionMatcher(UseGlobs, /*RemoveDotSlash=*/false), SectionStr(Str),
+Section(StringRef Name, unsigned FileIdx, bool UseGlobs)
+: SectionMatcher(UseGlobs, /*RemoveDotSlash=*/false), Name(Name),
FileIdx(FileIdx) {}
Section(Section &&) = default;
// Return name of the section, it's entire string in [].
-StringRef name() const { return SectionStr; }
+StringRef name() const { return Name; }
// Returns true of string 'Name' matches section name interpreted as a
glob.
LLVM_ABI bool matchName(StringRef Name) const;
@@ -232,7 +232,7 @@ class SpecialCaseList {
findMatcher(StringRef Prefix, StringRef Category) const;
Matcher SectionMatcher;
-StringRef SectionStr;
+StringRef Name;
SectionEntries Entries;
unsigned FileIdx;
};
``
https://github.com/llvm/llvm-project/pull/167279
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [NFC][SpecialCaseList] Store SectionStr as StringRef (PR #167278)
llvmbot wrote:
@llvm/pr-subscribers-llvm-support
Author: Vitaly Buka (vitalybuka)
Changes
The SectionStr is already copied in addSection, so
there is no need to copy it again in the Section
constructor.
---
Full diff: https://github.com/llvm/llvm-project/pull/167278.diff
2 Files Affected:
- (modified) llvm/include/llvm/Support/SpecialCaseList.h (+1-1)
- (modified) llvm/lib/Support/SpecialCaseList.cpp (+1-1)
``diff
Rate limit Β· GitHub
body {
background-color: #f6f8fa;
color: rgba(0, 0, 0, 0.5);
font-family: -apple-system,BlinkMacSystemFont,Segoe
UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;
font-size: 14px;
line-height: 1.5;
}
.c { margin: 50px auto; max-width: 600px; text-align: center; padding: 0
24px; }
a { text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { color: #24292e; line-height: 60px; font-size: 48px; font-weight:
300; margin: 0px; }
p { margin: 20px 0 40px; }
#s { margin-top: 35px; }
#s a {
color: #66;
font-weight: 200;
font-size: 14px;
margin: 0 10px;
}
Access has been restricted
You have triggered a rate limit.
Please wait a few minutes before you try again;
in some cases this may take up to an hour.
https://support.github.com";>Contact Support β
https://githubstatus.com";>GitHub Status β
https://twitter.com/githubstatus";>@githubstatus
``
https://github.com/llvm/llvm-project/pull/167278
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [SpecialCaseList] Switch to Version 3. (PR #167283)
https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/167283 The difference from Version 2 is that file path will be matched twice: as is and after removing leading "./". ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [NFC][SpecialCaseList] Move most of implementation in cpp file (PR #167280)
llvmbot wrote:
@llvm/pr-subscribers-llvm-support
Author: Vitaly Buka (vitalybuka)
Changes
This commit moves the `RegexMatcher`, `GlobMatcher`, `Matcher` and
`Section` classes into an anonymous namespace within
`SpecialCaseList.cpp`. These classes are implementation details of
`SpecialCaseList` and do not need to be exposed in the header.
---
Full diff: https://github.com/llvm/llvm-project/pull/167280.diff
2 Files Affected:
- (modified) llvm/include/llvm/Support/SpecialCaseList.h (+7-90)
- (modified) llvm/lib/Support/SpecialCaseList.cpp (+136-34)
``diff
diff --git a/llvm/include/llvm/Support/SpecialCaseList.h
b/llvm/include/llvm/Support/SpecialCaseList.h
index 8c4dc94ae54ce..5785dad7406df 100644
--- a/llvm/include/llvm/Support/SpecialCaseList.h
+++ b/llvm/include/llvm/Support/SpecialCaseList.h
@@ -12,19 +12,11 @@
#ifndef LLVM_SUPPORT_SPECIALCASELIST_H
#define LLVM_SUPPORT_SPECIALCASELIST_H
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/RadixTree.h"
-#include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/StringMap.h"
-#include "llvm/ADT/iterator_range.h"
#include "llvm/Support/Allocator.h"
-#include "llvm/Support/Compiler.h"
-#include "llvm/Support/GlobPattern.h"
-#include "llvm/Support/Regex.h"
+#include "llvm/Support/Error.h"
#include
#include
#include
-#include
#include
namespace llvm {
@@ -125,83 +117,11 @@ class SpecialCaseList {
SpecialCaseList(SpecialCaseList const &) = delete;
SpecialCaseList &operator=(SpecialCaseList const &) = delete;
-private:
- using Match = std::pair;
- static constexpr Match NotMatched = {"", 0};
-
- // Lagacy v1 matcher.
- class RegexMatcher {
- public:
-LLVM_ABI Error insert(StringRef Pattern, unsigned LineNumber);
-LLVM_ABI void preprocess(bool BySize);
-
-LLVM_ABI Match match(StringRef Query) const;
-
-struct Reg {
- Reg(StringRef Name, unsigned LineNo, Regex &&Rg)
- : Name(Name), LineNo(LineNo), Rg(std::move(Rg)) {}
- StringRef Name;
- unsigned LineNo;
- Regex Rg;
-};
-
-std::vector RegExes;
- };
-
- class GlobMatcher {
- public:
-LLVM_ABI Error insert(StringRef Pattern, unsigned LineNumber);
-LLVM_ABI void preprocess(bool BySize);
-
-LLVM_ABI Match match(StringRef Query) const;
-
-struct Glob {
- Glob(StringRef Name, unsigned LineNo, GlobPattern &&Pattern)
- : Name(Name), LineNo(LineNo), Pattern(std::move(Pattern)) {}
- StringRef Name;
- unsigned LineNo;
- GlobPattern Pattern;
-};
-
-std::vector Globs;
-
-RadixTree,
- RadixTree,
-SmallVector>>
-PrefixSuffixToGlob;
-
-RadixTree, SmallVector>
-SubstrToGlob;
- };
-
- /// Represents a set of patterns and their line numbers
- class Matcher {
- public:
-LLVM_ABI Matcher(bool UseGlobs, bool RemoveDotSlash);
-
-LLVM_ABI Error insert(StringRef Pattern, unsigned LineNumber);
-LLVM_ABI void preprocess(bool BySize);
-
-LLVM_ABI Match match(StringRef Query) const;
-
-LLVM_ABI bool matchAny(StringRef Query) const {
- return match(Query) != NotMatched;
-}
-
-std::variant M;
-bool RemoveDotSlash;
- };
-
- using SectionEntries = StringMap>;
-
-protected:
class Section {
public:
-Section(StringRef Name, unsigned FileIdx, bool UseGlobs)
-: SectionMatcher(UseGlobs, /*RemoveDotSlash=*/false), Name(Name),
- FileIdx(FileIdx) {}
-
-Section(Section &&) = default;
+LLVM_ABI Section(StringRef Name, unsigned FileIdx, bool UseGlobs);
+LLVM_ABI Section(Section &&);
+LLVM_ABI ~Section();
// Return name of the section, it's entire string in [].
StringRef name() const { return Name; }
@@ -227,17 +147,14 @@ class SpecialCaseList {
private:
friend class SpecialCaseList;
-LLVM_ABI void preprocess(bool OrderBySize);
-LLVM_ABI const SpecialCaseList::Matcher *
-findMatcher(StringRef Prefix, StringRef Category) const;
+class SectionImpl;
-Matcher SectionMatcher;
StringRef Name;
-SectionEntries Entries;
unsigned FileIdx;
+std::unique_ptr Impl;
};
- ArrayRef sections() const { return Sections; }
+ const std::vector Β§ions() const;
private:
BumpPtrAllocator StrAlloc;
diff --git a/llvm/lib/Support/SpecialCaseList.cpp
b/llvm/lib/Support/SpecialCaseList.cpp
index 42c8933a43399..cf01f59fa37f6 100644
--- a/llvm/lib/Support/SpecialCaseList.cpp
+++ b/llvm/lib/Support/SpecialCaseList.cpp
@@ -14,26 +14,94 @@
//===--===//
#include "llvm/Support/SpecialCaseList.h"
+#include "llvm/ADT/RadixTree.h"
#include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/SetVector.h"
-#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/iterator_range.h"
+#include "llvm/Support/GlobPattern.h"
#include "llvm/Support/LineIterator.h"
#inclu
[llvm-branch-commits] [NFC][SpecialCaseList] Hide Section internal in private section (PR #167276)
llvmbot wrote:
@llvm/pr-subscribers-clang
Author: Vitaly Buka (vitalybuka)
Changes
Preparing to moving most of implementation out of the header file.
---
Full diff: https://github.com/llvm/llvm-project/pull/167276.diff
5 Files Affected:
- (modified) clang/lib/Basic/Diagnostic.cpp (+1-1)
- (modified) clang/lib/Basic/ProfileList.cpp (+1-1)
- (modified) clang/lib/Basic/SanitizerSpecialCaseList.cpp (+2-2)
- (modified) llvm/include/llvm/Support/SpecialCaseList.h (+18-5)
- (modified) llvm/lib/Support/SpecialCaseList.cpp (+8)
``diff
diff --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp
index 2dec26ecacf26..5e9da245e2b43 100644
--- a/clang/lib/Basic/Diagnostic.cpp
+++ b/clang/lib/Basic/Diagnostic.cpp
@@ -534,7 +534,7 @@ WarningsSpecialCaseList::create(const llvm::MemoryBuffer
&Input,
void WarningsSpecialCaseList::processSections(DiagnosticsEngine &Diags) {
static constexpr auto WarningFlavor = clang::diag::Flavor::WarningOrError;
for (const auto &SectionEntry : sections()) {
-StringRef DiagGroup = SectionEntry.SectionStr;
+StringRef DiagGroup = SectionEntry.name();
if (DiagGroup == "*") {
// Drop the default section introduced by special case list, we only
// support exact diagnostic group names.
diff --git a/clang/lib/Basic/ProfileList.cpp b/clang/lib/Basic/ProfileList.cpp
index 9cb118893a0d9..8727057eb78d1 100644
--- a/clang/lib/Basic/ProfileList.cpp
+++ b/clang/lib/Basic/ProfileList.cpp
@@ -36,7 +36,7 @@ class ProfileSpecialCaseList : public llvm::SpecialCaseList {
bool hasPrefix(StringRef Prefix) const {
for (const auto &It : sections())
- if (It.Entries.count(Prefix) > 0)
+ if (It.hasPrefix(Prefix))
return true;
return false;
}
diff --git a/clang/lib/Basic/SanitizerSpecialCaseList.cpp
b/clang/lib/Basic/SanitizerSpecialCaseList.cpp
index 56f551628cf89..928c086898097 100644
--- a/clang/lib/Basic/SanitizerSpecialCaseList.cpp
+++ b/clang/lib/Basic/SanitizerSpecialCaseList.cpp
@@ -42,7 +42,7 @@ void SanitizerSpecialCaseList::createSanitizerSections() {
SanitizerMask Mask;
#define SANITIZER(NAME, ID)
\
- if (S.SectionMatcher.matchAny(NAME))
\
+ if (S.matchName(NAME))
\
Mask |= SanitizerKind::ID;
#define SANITIZER_GROUP(NAME, ID, ALIAS) SANITIZER(NAME, ID)
@@ -68,7 +68,7 @@ SanitizerSpecialCaseList::inSectionBlame(SanitizerMask Mask,
StringRef Prefix,
if (S.Mask & Mask) {
unsigned LineNum = S.S.getLastMatch(Prefix, Query, Category);
if (LineNum > 0)
-return {S.S.FileIdx, LineNum};
+return {S.S.fileIndex(), LineNum};
}
}
return NotFound;
diff --git a/llvm/include/llvm/Support/SpecialCaseList.h
b/llvm/include/llvm/Support/SpecialCaseList.h
index 5ed7adeaf6c92..120d67377c674 100644
--- a/llvm/include/llvm/Support/SpecialCaseList.h
+++ b/llvm/include/llvm/Support/SpecialCaseList.h
@@ -195,17 +195,22 @@ class SpecialCaseList {
using SectionEntries = StringMap>;
protected:
- struct Section {
+ class Section {
+ public:
Section(StringRef Str, unsigned FileIdx, bool UseGlobs)
: SectionMatcher(UseGlobs, /*RemoveDotSlash=*/false), SectionStr(Str),
FileIdx(FileIdx) {}
Section(Section &&) = default;
-Matcher SectionMatcher;
-SectionEntries Entries;
-std::string SectionStr;
-unsigned FileIdx;
+// Return name of the section, it's entire string in [].
+StringRef name() const { return SectionStr; }
+
+// Returns true of string 'Name' matches section name interpreted as a
glob.
+LLVM_ABI bool matchName(StringRef Name) const;
+
+// Return sequence number of the file where this section is defined.
+unsigned fileIndex() const { return FileIdx; }
// Helper method to search by Prefix, Query, and Category. Returns
// 1-based line number on which rule is defined, or 0 if there is no match.
@@ -217,11 +222,19 @@ class SpecialCaseList {
LLVM_ABI StringRef getLongestMatch(StringRef Prefix, StringRef Query,
StringRef Category) const;
+/// Returns true if the section has any entries for the given prefix.
+LLVM_ABI bool hasPrefix(StringRef Prefix) const;
+
private:
friend class SpecialCaseList;
LLVM_ABI void preprocess(bool OrderBySize);
LLVM_ABI const SpecialCaseList::Matcher *
findMatcher(StringRef Prefix, StringRef Category) const;
+
+Matcher SectionMatcher;
+std::string SectionStr;
+SectionEntries Entries;
+unsigned FileIdx;
};
ArrayRef sections() const { return Sections; }
diff --git a/llvm/lib/Support/SpecialCaseList.cpp
b/llvm/lib/Support/SpecialCaseList.cpp
index 8e6e9f34a73f3..395a55d75acd4 100644
--- a/llvm/lib/Support/SpecialCaseList.cpp
+++ b/llvm/lib/Support/SpecialCaseList.cpp
@@ -358,6 +358,10 @@ Specia
[llvm-branch-commits] [NFC][SpecialCaseList] Convert `preprocess` into `LazyInit` (PR #167281)
https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/167281 Currently SpecialCaseList created at least twice, one on by `Driver`, for diagnostics only, and then the real one by the `ASTContext`. Also, deppending on enabled sanitizers, not all sections will be used. In both cases there is unnecessary RadixTree construction. This patch changes `GlobMatcher` to do initialization lazily only when needed. And remove empty one from `RegexMatcher`. This saves saves 0.5% of clang time building large project. ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [NFC][SpecialCaseList] Precommit Version 4 tests (PR #167282)
https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/167282 At the moment the behavior is no different from Version 3. ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [NFC][SpecialCaseList] Store SectionStr as StringRef (PR #167278)
https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/167278 The SectionStr is already copied in addSection, so there is no need to copy it again in the Section constructor. ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [NFC][SpecialCaseList] Rename `Section::SectionStr` to `Name` (PR #167279)
https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/167279 None ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [NFC][SpecialCaseList] Move most of implementation in cpp file (PR #167280)
https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/167280 This commit moves the `RegexMatcher`, `GlobMatcher`, `Matcher` and `Section` classes into an anonymous namespace within `SpecialCaseList.cpp`. These classes are implementation details of `SpecialCaseList` and do not need to be exposed in the header. ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [llvm] [clang] Switch warning suppression multi-match rule to "last match takes precedence" (PR #162237)
https://github.com/vitalybuka edited https://github.com/llvm/llvm-project/pull/162237 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [NFC][Support] Remove unused getLongestMatch from SpecialCaseList (PR #167193)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/167193 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [NFC][SpecialCaseList] Hide Section internal in private section (PR #167276)
https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/167276 Preparing to moving most of implementation out of the header file. ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [NFC][SpecialCaseList] Refactor error handling (PR #167277)
https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/167277 Will help in future patches. ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [SpecialCaseList] Add backward compatible dot-slash handling (PR #162511)
https://github.com/vitalybuka edited https://github.com/llvm/llvm-project/pull/162511 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] WIP: DotSlash backward compartible (PR #162511)
https://github.com/vitalybuka edited https://github.com/llvm/llvm-project/pull/162511 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [NFC][Support] Remove unused getLongestMatch from SpecialCaseList (PR #167193)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/167193 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [llvm] [clang] Switch warning suppression multi-match rule to "last match takes precedence" (PR #162237)
https://github.com/vitalybuka updated
https://github.com/llvm/llvm-project/pull/162237
>From b0aa1c4f6462bba4700a7b72804370bd9fddc453 Mon Sep 17 00:00:00 2001
From: Vitaly Buka
Date: Tue, 7 Oct 2025 00:56:26 -0700
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20ch?=
=?UTF-8?q?anges=20to=20main=20this=20commit=20is=20based=20on?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.6
[skip ci]
---
clang/lib/Basic/Diagnostic.cpp | 35 +---
clang/lib/Basic/SanitizerSpecialCaseList.cpp | 2 +-
llvm/include/llvm/Support/SpecialCaseList.h | 4 ++-
llvm/lib/Support/SpecialCaseList.cpp | 4 +--
4 files changed, 15 insertions(+), 30 deletions(-)
diff --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp
index dc3778bbf339c..2b89370a42d1b 100644
--- a/clang/lib/Basic/Diagnostic.cpp
+++ b/clang/lib/Basic/Diagnostic.cpp
@@ -537,33 +537,16 @@ WarningsSpecialCaseList::create(const llvm::MemoryBuffer
&Input,
}
void WarningsSpecialCaseList::processSections(DiagnosticsEngine &Diags) {
- // Drop the default section introduced by special case list, we only support
- // exact diagnostic group names.
- // FIXME: We should make this configurable in the parser instead.
- // FIXME: C++20 can use std::erase_if(Sections, [](Section &sec) { return
- // sec.SectionStr == "*"; });
- llvm::erase_if(Sections, [](Section &sec) { return sec.SectionStr == "*"; });
- // Make sure we iterate sections by their line numbers.
- std::vector> LineAndSectionEntry;
- LineAndSectionEntry.reserve(Sections.size());
- for (const auto &Entry : Sections) {
-StringRef DiagName = Entry.SectionStr;
-// Each section has a matcher with that section's name, attached to that
-// line.
-const auto &DiagSectionMatcher = Entry.SectionMatcher;
-unsigned DiagLine = 0;
-for (const auto &Glob : DiagSectionMatcher->Globs)
- if (Glob->Name == DiagName) {
-DiagLine = Glob->LineNo;
-break;
- }
-LineAndSectionEntry.emplace_back(DiagLine, &Entry);
- }
- llvm::sort(LineAndSectionEntry);
static constexpr auto WarningFlavor = clang::diag::Flavor::WarningOrError;
- for (const auto &[_, SectionEntry] : LineAndSectionEntry) {
+ for (const auto &SectionEntry : Sections) {
+StringRef DiagGroup = SectionEntry.SectionStr;
+if (DiagGroup == "*") {
+ // Drop the default section introduced by special case list, we only
+ // support exact diagnostic group names.
+ // FIXME: We should make this configurable in the parser instead.
+ continue;
+}
SmallVector GroupDiags;
-StringRef DiagGroup = SectionEntry->SectionStr;
if (Diags.getDiagnosticIDs()->getDiagnosticsInGroup(
WarningFlavor, DiagGroup, GroupDiags)) {
StringRef Suggestion =
@@ -576,7 +559,7 @@ void
WarningsSpecialCaseList::processSections(DiagnosticsEngine &Diags) {
for (diag::kind Diag : GroupDiags)
// We're intentionally overwriting any previous mappings here to make
sure
// latest one takes precedence.
- DiagToSection[Diag] = SectionEntry;
+ DiagToSection[Diag] = &SectionEntry;
}
}
diff --git a/clang/lib/Basic/SanitizerSpecialCaseList.cpp
b/clang/lib/Basic/SanitizerSpecialCaseList.cpp
index f7bc1d5545d75..582c2557d8aa7 100644
--- a/clang/lib/Basic/SanitizerSpecialCaseList.cpp
+++ b/clang/lib/Basic/SanitizerSpecialCaseList.cpp
@@ -42,7 +42,7 @@ void SanitizerSpecialCaseList::createSanitizerSections() {
SanitizerMask Mask;
#define SANITIZER(NAME, ID)
\
- if (S.SectionMatcher->match(NAME))
\
+ if (S.SectionMatcher.match(NAME))
\
Mask |= SanitizerKind::ID;
#define SANITIZER_GROUP(NAME, ID, ALIAS) SANITIZER(NAME, ID)
diff --git a/llvm/include/llvm/Support/SpecialCaseList.h
b/llvm/include/llvm/Support/SpecialCaseList.h
index 22a62eac9e01a..c2c9271b0a37a 100644
--- a/llvm/include/llvm/Support/SpecialCaseList.h
+++ b/llvm/include/llvm/Support/SpecialCaseList.h
@@ -147,7 +147,9 @@ class SpecialCaseList {
Section(StringRef Str, unsigned FileIdx)
: SectionStr(Str), FileIdx(FileIdx) {};
-std::unique_ptr SectionMatcher = std::make_unique();
+Section(Section &&) = default;
+
+Matcher SectionMatcher;
SectionEntries Entries;
std::string SectionStr;
unsigned FileIdx;
diff --git a/llvm/lib/Support/SpecialCaseList.cpp
b/llvm/lib/Support/SpecialCaseList.cpp
index 8d4e043bc1c9f..4b038850b62ca 100644
--- a/llvm/lib/Support/SpecialCaseList.cpp
+++ b/llvm/lib/Support/SpecialCaseList.cpp
@@ -135,7 +135,7 @@ SpecialCaseList::addSection(StringRef SectionStr, unsigned
FileNo,
Sections.emplace_back(SectionStr, FileNo);
auto &Section = Sections.back();
- if (auto Err = Section.SectionMatcher->insert(SectionStr, LineNo, UseGl
[llvm-branch-commits] [NFC][SpecialCaseList] Convert `preprocess` into `LazyInit` (PR #167281)
llvmbot wrote:
@llvm/pr-subscribers-llvm-support
Author: Vitaly Buka (vitalybuka)
Changes
Currently SpecialCaseList created at least twice,
one on by `Driver`, for diagnostics only, and then
the real one by the `ASTContext`.
Also, deppending on enabled sanitizers, not all
sections will be used.
In both cases there is unnecessary RadixTree
construction.
This patch changes `GlobMatcher` to do initialization
lazily only when needed.
And remove empty one from `RegexMatcher`.
This saves saves 0.5% of clang time building large project.
---
Full diff: https://github.com/llvm/llvm-project/pull/167281.diff
1 Files Affected:
- (modified) llvm/lib/Support/SpecialCaseList.cpp (+18-27)
``diff
diff --git a/llvm/lib/Support/SpecialCaseList.cpp
b/llvm/lib/Support/SpecialCaseList.cpp
index 2ba53d63365d2..79032cbb07f3f 100644
--- a/llvm/lib/Support/SpecialCaseList.cpp
+++ b/llvm/lib/Support/SpecialCaseList.cpp
@@ -20,6 +20,7 @@
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/iterator_range.h"
+#include "llvm/Support/Compiler.h"
#include "llvm/Support/GlobPattern.h"
#include "llvm/Support/LineIterator.h"
#include "llvm/Support/MemoryBuffer.h"
@@ -42,10 +43,9 @@ namespace {
class RegexMatcher {
public:
Error insert(StringRef Pattern, unsigned LineNumber);
- void preprocess();
-
unsigned match(StringRef Query) const;
+private:
struct Reg {
Reg(StringRef Name, unsigned LineNo, Regex &&Rg)
: Name(Name), LineNo(LineNo), Rg(std::move(Rg)) {}
@@ -60,10 +60,9 @@ class RegexMatcher {
class GlobMatcher {
public:
Error insert(StringRef Pattern, unsigned LineNumber);
- void preprocess();
-
unsigned match(StringRef Query) const;
+private:
struct Glob {
Glob(StringRef Name, unsigned LineNo, GlobPattern &&Pattern)
: Name(Name), LineNo(LineNo), Pattern(std::move(Pattern)) {}
@@ -72,15 +71,20 @@ class GlobMatcher {
GlobPattern Pattern;
};
+ void LazyInit() const;
+
std::vector Globs;
- RadixTree,
-RadixTree,
- SmallVector>>
+ mutable RadixTree,
+
RadixTree,
+ SmallVector>>
PrefixSuffixToGlob;
- RadixTree, SmallVector>
+ mutable RadixTree,
+SmallVector>
SubstrToGlob;
+
+ mutable bool Initialized = false;
};
/// Represents a set of patterns and their line numbers
@@ -89,7 +93,6 @@ class Matcher {
Matcher(bool UseGlobs, bool RemoveDotSlash);
Error insert(StringRef Pattern, unsigned LineNumber);
- void preprocess();
unsigned match(StringRef Query) const;
bool matchAny(StringRef Query) const { return match(Query); }
@@ -122,8 +125,6 @@ Error RegexMatcher::insert(StringRef Pattern, unsigned
LineNumber) {
return Error::success();
}
-void RegexMatcher::preprocess() {}
-
unsigned RegexMatcher::match(StringRef Query) const {
for (const auto &R : reverse(RegExes))
if (R.Rg.match(Query))
@@ -142,7 +143,10 @@ Error GlobMatcher::insert(StringRef Pattern, unsigned
LineNumber) {
return Error::success();
}
-void GlobMatcher::preprocess() {
+void GlobMatcher::LazyInit() const {
+ if (LLVM_LIKELY(Initialized))
+return;
+ Initialized = true;
for (const auto &[Idx, G] : enumerate(Globs)) {
StringRef Prefix = G.Pattern.prefix();
StringRef Suffix = G.Pattern.suffix();
@@ -167,6 +171,8 @@ void GlobMatcher::preprocess() {
}
unsigned GlobMatcher::match(StringRef Query) const {
+ LazyInit();
+
int Best = -1;
if (!PrefixSuffixToGlob.empty()) {
for (const auto &[_, SToGlob] : PrefixSuffixToGlob.find_prefixes(Query)) {
@@ -224,10 +230,6 @@ Error Matcher::insert(StringRef Pattern, unsigned
LineNumber) {
return std::visit([&](auto &V) { return V.insert(Pattern, LineNumber); }, M);
}
-void Matcher::preprocess() {
- return std::visit([&](auto &V) { return V.preprocess(); }, M);
-}
-
unsigned Matcher::match(StringRef Query) const {
if (RemoveDotSlash)
Query = llvm::sys::path::remove_leading_dotslash(Query);
@@ -237,7 +239,6 @@ unsigned Matcher::match(StringRef Query) const {
class SpecialCaseList::Section::SectionImpl {
friend class SpecialCaseList;
- void preprocess();
const Matcher *findMatcher(StringRef Prefix, StringRef Category) const;
public:
@@ -410,9 +411,6 @@ bool SpecialCaseList::parse(unsigned FileIdx, const
MemoryBuffer *MB,
}
}
- for (Section &S : Sections)
-S.Impl->preprocess();
-
return true;
}
@@ -462,13 +460,6 @@
SpecialCaseList::Section::SectionImpl::findMatcher(StringRef Prefix,
return &II->second;
}
-void SpecialCaseList::Section::SectionImpl::preprocess() {
- SectionMatcher.preprocess();
- for (auto &[K1, E] : Entries)
-for (auto &[K2, M] : E)
- M.preprocess();
-}
-
unsigned SpecialCaseList::Section::getLastMatch(StringRef Prefix,
StringRef Query,
St
[llvm-branch-commits] [NFC][SpecialCaseList] Precommit Version 4 tests (PR #167282)
llvmbot wrote:
@llvm/pr-subscribers-llvm-support
Author: Vitaly Buka (vitalybuka)
Changes
At the moment the behavior is no different from
Version 3.
---
Full diff: https://github.com/llvm/llvm-project/pull/167282.diff
1 Files Affected:
- (modified) llvm/unittests/Support/SpecialCaseListTest.cpp (+19-13)
``diff
diff --git a/llvm/unittests/Support/SpecialCaseListTest.cpp
b/llvm/unittests/Support/SpecialCaseListTest.cpp
index 750fedaf0a436..812e0d3d8520c 100644
--- a/llvm/unittests/Support/SpecialCaseListTest.cpp
+++ b/llvm/unittests/Support/SpecialCaseListTest.cpp
@@ -308,43 +308,49 @@ TEST_F(SpecialCaseListTest, Version2) {
}
TEST_F(SpecialCaseListTest, DotSlash) {
- std::unique_ptr SCL2 = makeSpecialCaseList("[dot]\n"
- "fun:./foo\n"
- "src:./bar\n"
- "[not]\n"
- "fun:foo\n"
- "src:bar\n");
- std::unique_ptr SCL3 = makeSpecialCaseList("[dot]\n"
- "fun:./foo\n"
- "src:./bar\n"
- "[not]\n"
- "fun:foo\n"
- "src:bar\n",
- /*Version=*/3);
+ StringRef IgnoreList = "[dot]\n"
+ "fun:./foo\n"
+ "src:./bar\n"
+ "[not]\n"
+ "fun:foo\n"
+ "src:bar\n";
+ std::unique_ptr SCL2 = makeSpecialCaseList(IgnoreList);
+ std::unique_ptr SCL3 =
+ makeSpecialCaseList(IgnoreList, /*Version=*/3);
+ std::unique_ptr SCL4 = makeSpecialCaseList(IgnoreList,
+ /*Version=*/4);
EXPECT_TRUE(SCL2->inSection("dot", "fun", "./foo"));
EXPECT_TRUE(SCL3->inSection("dot", "fun", "./foo"));
+ EXPECT_TRUE(SCL4->inSection("dot", "fun", "./foo"));
EXPECT_FALSE(SCL2->inSection("dot", "fun", "foo"));
EXPECT_FALSE(SCL3->inSection("dot", "fun", "foo"));
+ EXPECT_FALSE(SCL4->inSection("dot", "fun", "foo"));
EXPECT_TRUE(SCL2->inSection("dot", "src", "./bar"));
EXPECT_FALSE(SCL3->inSection("dot", "src", "./bar"));
+ EXPECT_FALSE(SCL4->inSection("dot", "src", "./bar"));
EXPECT_FALSE(SCL2->inSection("dot", "src", "bar"));
EXPECT_FALSE(SCL3->inSection("dot", "src", "bar"));
+ EXPECT_FALSE(SCL4->inSection("dot", "src", "bar"));
EXPECT_FALSE(SCL2->inSection("not", "fun", "./foo"));
EXPECT_FALSE(SCL3->inSection("not", "fun", "./foo"));
+ EXPECT_FALSE(SCL4->inSection("not", "fun", "./foo"));
EXPECT_TRUE(SCL2->inSection("not", "fun", "foo"));
EXPECT_TRUE(SCL3->inSection("not", "fun", "foo"));
+ EXPECT_TRUE(SCL4->inSection("not", "fun", "foo"));
EXPECT_FALSE(SCL2->inSection("not", "src", "./bar"));
EXPECT_TRUE(SCL3->inSection("not", "src", "./bar"));
+ EXPECT_TRUE(SCL4->inSection("not", "src", "./bar"));
EXPECT_TRUE(SCL2->inSection("not", "src", "bar"));
EXPECT_TRUE(SCL3->inSection("not", "src", "bar"));
+ EXPECT_TRUE(SCL4->inSection("not", "src", "bar"));
}
TEST_F(SpecialCaseListTest, LinesInSection) {
``
https://github.com/llvm/llvm-project/pull/167282
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [SpecialCaseList] Switch to Version 3. (PR #167283)
llvmbot wrote:
@llvm/pr-subscribers-llvm-support
Author: Vitaly Buka (vitalybuka)
Changes
The difference from Version 2 is that file path will be matched
twice: as is and after removing leading "./".
---
Full diff: https://github.com/llvm/llvm-project/pull/167283.diff
2 Files Affected:
- (modified) llvm/lib/Support/SpecialCaseList.cpp (+1-1)
- (modified) llvm/unittests/Support/SpecialCaseListTest.cpp (+3-3)
``diff
diff --git a/llvm/lib/Support/SpecialCaseList.cpp
b/llvm/lib/Support/SpecialCaseList.cpp
index 393f0a411eb55..b7263850dbe48 100644
--- a/llvm/lib/Support/SpecialCaseList.cpp
+++ b/llvm/lib/Support/SpecialCaseList.cpp
@@ -397,7 +397,7 @@ SpecialCaseList::addSection(StringRef SectionStr, unsigned
FileNo,
bool SpecialCaseList::parse(unsigned FileIdx, const MemoryBuffer *MB,
std::string &Error) {
- unsigned long long Version = 2;
+ unsigned long long Version = 3;
StringRef Header = MB->getBuffer();
if (Header.consume_front("#!special-case-list-v"))
diff --git a/llvm/unittests/Support/SpecialCaseListTest.cpp
b/llvm/unittests/Support/SpecialCaseListTest.cpp
index 1e725d5c32790..674074b009f21 100644
--- a/llvm/unittests/Support/SpecialCaseListTest.cpp
+++ b/llvm/unittests/Support/SpecialCaseListTest.cpp
@@ -314,9 +314,9 @@ TEST_F(SpecialCaseListTest, DotSlash) {
"[not]\n"
"fun:foo\n"
"src:bar\n";
- std::unique_ptr SCL2 = makeSpecialCaseList(IgnoreList);
- std::unique_ptr SCL3 =
- makeSpecialCaseList(IgnoreList, /*Version=*/3);
+ std::unique_ptr SCL2 = makeSpecialCaseList(IgnoreList,
+ /*Version=*/2);
+ std::unique_ptr SCL3 = makeSpecialCaseList(IgnoreList);
std::unique_ptr SCL4 = makeSpecialCaseList(IgnoreList,
/*Version=*/4);
``
https://github.com/llvm/llvm-project/pull/167283
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [LifetimeSafety] Ignore parentheses when tracking expressions (PR #167245)
https://github.com/Xazax-hun approved this pull request. https://github.com/llvm/llvm-project/pull/167245 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/21.x: [LoongArch] Add `isSafeToMove` hook to prevent unsafe instruction motion (#163725) (PR #166936)
https://github.com/wangleiat approved this pull request. LGTM, thanks. https://github.com/llvm/llvm-project/pull/166936 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] DAG: Fold copysign with a known signmask to a disjoint or (PR #167266)
https://github.com/arsenm created
https://github.com/llvm/llvm-project/pull/167266
DAG: Fold copysign with a known signmask to a disjoint or
If the sign bit is a computed sign mask (i.e., we know it's
either +0 or -0), turn this into a disjoint or. This pattern
appears in the pow implementations.
We also need to know the sign bit of the magnitude is 0 for
the or to be disjoint. Unfortunately the DAG's FP tracking is
weak and we did not have a way to check if the sign bit is known
0, so add something for that. Ideally we would get a complete
computeKnownFPClass implementation.
This is intended to help avoid the regression which caused
d3e7c4ce7a3d7 to be reverted.
Match shift to signbit pattern instead of computeKnownBits
Revert "Match shift to signbit pattern instead of computeKnownBits"
This reverts commit 49e2c3aa7a861fc8864c2d045b3804e31e1f13cc.
One case is slighly more sophisticated
>From 562a9c31a5dc58a5381ed695a49b90139a9f3f77 Mon Sep 17 00:00:00 2001
From: Matt Arsenault
Date: Thu, 1 Aug 2024 15:11:59 +0400
Subject: [PATCH 1/3] DAG: Fold copysign with a known signmask to a disjoint or
If the sign bit is a computed sign mask (i.e., we know it's
either +0 or -0), turn this into a disjoint or. This pattern
appears in the pow implementations.
We also need to know the sign bit of the magnitude is 0 for
the or to be disjoint. Unfortunately the DAG's FP tracking is
weak and we did not have a way to check if the sign bit is known
0, so add something for that. Ideally we would get a complete
computeKnownFPClass implementation.
This is intended to help avoid the regression which caused
d3e7c4ce7a3d7 to be reverted.
---
llvm/include/llvm/CodeGen/SelectionDAG.h | 4 +++
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 20 +
.../lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 28 +++
.../AMDGPU/copysign-simplify-demanded-bits.ll | 23 ++-
.../AMDGPU/copysign-to-disjoint-or-combine.ll | 22 ---
5 files changed, 67 insertions(+), 30 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/SelectionDAG.h
b/llvm/include/llvm/CodeGen/SelectionDAG.h
index 0dd4f23c6d85f..5b331e915 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAG.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAG.h
@@ -2072,6 +2072,10 @@ class SelectionDAG {
/// We use this predicate to simplify operations downstream.
LLVM_ABI bool SignBitIsZero(SDValue Op, unsigned Depth = 0) const;
+ /// Return true if the sign bit of Op is known to be zero, for a
+ /// floating-point value.
+ LLVM_ABI bool SignBitIsZeroFP(SDValue Op, unsigned Depth = 0) const;
+
/// Return true if 'Op & Mask' is known to be zero. We
/// use this predicate to simplify operations downstream. Op and Mask are
/// known to be the same type.
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index f144f17d5a8f2..4f2eb1e64dbe0 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -18863,6 +18863,26 @@ SDValue DAGCombiner::visitFCOPYSIGN(SDNode *N) {
if (SimplifyDemandedBits(SDValue(N, 0)))
return SDValue(N, 0);
+ if (VT != N1.getValueType())
+return SDValue();
+
+ // If this is equivalent to a disjoint or, replace it with one. This can
+ // happen if the sign operand is a sign mask (i.e., x << sign_bit_position).
+ if (DAG.SignBitIsZeroFP(N0) &&
+ DAG.computeKnownBits(N1).Zero.isMaxSignedValue()) {
+// TODO: Just directly match the shift pattern. computeKnownBits is heavy
+// for a such a narrowly targeted case.
+EVT IntVT = VT.changeTypeToInteger();
+// TODO: It appears to be profitable in some situations to unconditionally
+// emit a fabs(n0) to perform this combine.
+SDValue CastSrc0 = DAG.getNode(ISD::BITCAST, DL, IntVT, N0);
+SDValue CastSrc1 = DAG.getNode(ISD::BITCAST, DL, IntVT, N1);
+
+SDValue SignOr = DAG.getNode(ISD::OR, DL, IntVT, CastSrc0, CastSrc1,
+ SDNodeFlags::Disjoint);
+return DAG.getNode(ISD::BITCAST, DL, VT, SignOr);
+ }
+
return SDValue();
}
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 80bbfea7fb83c..d7b3b03deb757 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -2920,6 +2920,34 @@ bool SelectionDAG::SignBitIsZero(SDValue Op, unsigned
Depth) const {
return MaskedValueIsZero(Op, APInt::getSignMask(BitWidth), Depth);
}
+bool SelectionDAG::SignBitIsZeroFP(SDValue Op, unsigned Depth) const {
+ if (Depth >= MaxRecursionDepth)
+return false; // Limit search depth.
+
+ unsigned Opc = Op.getOpcode();
+ switch (Opc) {
+ case ISD::FABS:
+return true;
+ case ISD::AssertNoFPClass: {
+FPClassTest NoFPClass =
+static_cast(Op.getConstantOperandVal(1));
+
+const FPClassTest TestMask = fcNan | fcNegative;
+retur
[llvm-branch-commits] [llvm] AMDGPU: Add baseline tests for copysign with known signmask input (PR #167265)
llvmbot wrote:
@llvm/pr-subscribers-llvm-selectiondag
Author: Matt Arsenault (arsenm)
Changes
---
Full diff: https://github.com/llvm/llvm-project/pull/167265.diff
2 Files Affected:
- (modified) llvm/test/CodeGen/AMDGPU/copysign-simplify-demanded-bits.ll (+108)
- (added) llvm/test/CodeGen/AMDGPU/copysign-to-disjoint-or-combine.ll (+208)
``diff
diff --git a/llvm/test/CodeGen/AMDGPU/copysign-simplify-demanded-bits.ll
b/llvm/test/CodeGen/AMDGPU/copysign-simplify-demanded-bits.ll
index f5227eed458d6..0be2b5c70c93b 100644
--- a/llvm/test/CodeGen/AMDGPU/copysign-simplify-demanded-bits.ll
+++ b/llvm/test/CodeGen/AMDGPU/copysign-simplify-demanded-bits.ll
@@ -370,4 +370,112 @@ define float
@test_copysign_pow_fast_f32__integral_y(float %x, i32 %y.i) {
ret float %pow_sign1
}
+define double @test_pow_fast_f64integral_y(double %x, i32 %y.i) #0 {
+; GFX9-LABEL: test_pow_fast_f64integral_y:
+; GFX9: ; %bb.0:
+; GFX9-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX9-NEXT:s_mov_b32 s16, s33
+; GFX9-NEXT:s_mov_b32 s33, s32
+; GFX9-NEXT:s_or_saveexec_b64 s[18:19], -1
+; GFX9-NEXT:buffer_store_dword v43, off, s[0:3], s33 offset:12 ; 4-byte
Folded Spill
+; GFX9-NEXT:s_mov_b64 exec, s[18:19]
+; GFX9-NEXT:v_writelane_b32 v43, s16, 15
+; GFX9-NEXT:v_writelane_b32 v43, s30, 0
+; GFX9-NEXT:v_writelane_b32 v43, s31, 1
+; GFX9-NEXT:v_writelane_b32 v43, s34, 2
+; GFX9-NEXT:v_writelane_b32 v43, s35, 3
+; GFX9-NEXT:v_writelane_b32 v43, s36, 4
+; GFX9-NEXT:v_writelane_b32 v43, s37, 5
+; GFX9-NEXT:v_writelane_b32 v43, s38, 6
+; GFX9-NEXT:v_writelane_b32 v43, s39, 7
+; GFX9-NEXT:v_writelane_b32 v43, s48, 8
+; GFX9-NEXT:v_writelane_b32 v43, s49, 9
+; GFX9-NEXT:v_writelane_b32 v43, s50, 10
+; GFX9-NEXT:v_writelane_b32 v43, s51, 11
+; GFX9-NEXT:s_addk_i32 s32, 0x800
+; GFX9-NEXT:buffer_store_dword v40, off, s[0:3], s33 offset:8 ; 4-byte
Folded Spill
+; GFX9-NEXT:buffer_store_dword v41, off, s[0:3], s33 offset:4 ; 4-byte
Folded Spill
+; GFX9-NEXT:buffer_store_dword v42, off, s[0:3], s33 ; 4-byte Folded Spill
+; GFX9-NEXT:v_writelane_b32 v43, s52, 12
+; GFX9-NEXT:v_mov_b32_e32 v42, v1
+; GFX9-NEXT:v_writelane_b32 v43, s53, 13
+; GFX9-NEXT:v_and_b32_e32 v1, 0x7fff, v42
+; GFX9-NEXT:s_getpc_b64 s[16:17]
+; GFX9-NEXT:s_add_u32 s16, s16, _Z4log2d@rel32@lo+4
+; GFX9-NEXT:s_addc_u32 s17, s17, _Z4log2d@rel32@hi+12
+; GFX9-NEXT:v_writelane_b32 v43, s54, 14
+; GFX9-NEXT:v_mov_b32_e32 v40, v31
+; GFX9-NEXT:v_mov_b32_e32 v41, v2
+; GFX9-NEXT:s_mov_b32 s50, s15
+; GFX9-NEXT:s_mov_b32 s51, s14
+; GFX9-NEXT:s_mov_b32 s52, s13
+; GFX9-NEXT:s_mov_b32 s53, s12
+; GFX9-NEXT:s_mov_b64 s[34:35], s[10:11]
+; GFX9-NEXT:s_mov_b64 s[36:37], s[8:9]
+; GFX9-NEXT:s_mov_b64 s[38:39], s[6:7]
+; GFX9-NEXT:s_mov_b64 s[48:49], s[4:5]
+; GFX9-NEXT:s_brev_b32 s54, -2
+; GFX9-NEXT:s_swappc_b64 s[30:31], s[16:17]
+; GFX9-NEXT:v_cvt_f64_i32_e32 v[2:3], v41
+; GFX9-NEXT:s_getpc_b64 s[16:17]
+; GFX9-NEXT:s_add_u32 s16, s16, _Z4exp2d@rel32@lo+4
+; GFX9-NEXT:s_addc_u32 s17, s17, _Z4exp2d@rel32@hi+12
+; GFX9-NEXT:s_mov_b64 s[4:5], s[48:49]
+; GFX9-NEXT:s_mov_b64 s[6:7], s[38:39]
+; GFX9-NEXT:v_mul_f64 v[0:1], v[0:1], v[2:3]
+; GFX9-NEXT:s_mov_b64 s[8:9], s[36:37]
+; GFX9-NEXT:s_mov_b64 s[10:11], s[34:35]
+; GFX9-NEXT:s_mov_b32 s12, s53
+; GFX9-NEXT:s_mov_b32 s13, s52
+; GFX9-NEXT:s_mov_b32 s14, s51
+; GFX9-NEXT:s_mov_b32 s15, s50
+; GFX9-NEXT:v_mov_b32_e32 v31, v40
+; GFX9-NEXT:s_swappc_b64 s[30:31], s[16:17]
+; GFX9-NEXT:v_lshlrev_b32_e32 v2, 31, v41
+; GFX9-NEXT:v_and_b32_e32 v2, v2, v42
+; GFX9-NEXT:buffer_load_dword v42, off, s[0:3], s33 ; 4-byte Folded Reload
+; GFX9-NEXT:buffer_load_dword v41, off, s[0:3], s33 offset:4 ; 4-byte
Folded Reload
+; GFX9-NEXT:buffer_load_dword v40, off, s[0:3], s33 offset:8 ; 4-byte
Folded Reload
+; GFX9-NEXT:v_bfi_b32 v1, s54, v1, v2
+; GFX9-NEXT:v_readlane_b32 s54, v43, 14
+; GFX9-NEXT:v_readlane_b32 s53, v43, 13
+; GFX9-NEXT:v_readlane_b32 s52, v43, 12
+; GFX9-NEXT:v_readlane_b32 s51, v43, 11
+; GFX9-NEXT:v_readlane_b32 s50, v43, 10
+; GFX9-NEXT:v_readlane_b32 s49, v43, 9
+; GFX9-NEXT:v_readlane_b32 s48, v43, 8
+; GFX9-NEXT:v_readlane_b32 s39, v43, 7
+; GFX9-NEXT:v_readlane_b32 s38, v43, 6
+; GFX9-NEXT:v_readlane_b32 s37, v43, 5
+; GFX9-NEXT:v_readlane_b32 s36, v43, 4
+; GFX9-NEXT:v_readlane_b32 s35, v43, 3
+; GFX9-NEXT:v_readlane_b32 s34, v43, 2
+; GFX9-NEXT:v_readlane_b32 s31, v43, 1
+; GFX9-NEXT:v_readlane_b32 s30, v43, 0
+; GFX9-NEXT:s_mov_b32 s32, s33
+; GFX9-NEXT:v_readlane_b32 s4, v43, 15
+; GFX9-NEXT:s_or_saveexec_b64 s[6:7], -1
+; GFX9-NEXT:buffer_load_dword v43, off, s[0:3], s33 offset:12 ; 4-byte
Folded Reload
+; GFX9-NEXT:s_mov_b64 exec, s[6:7]
+; GFX9-NEX
[llvm-branch-commits] [llvm] DAG: Fold copysign with a known signmask to a disjoint or (PR #167266)
https://github.com/arsenm ready_for_review https://github.com/llvm/llvm-project/pull/167266 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] AMDGPU: Add baseline tests for copysign with known signmask input (PR #167265)
https://github.com/arsenm created
https://github.com/llvm/llvm-project/pull/167265
None
>From 0effb2d4cefc121ac929ba8aea4af82e052d4d3f Mon Sep 17 00:00:00 2001
From: Matt Arsenault
Date: Fri, 7 Nov 2025 22:20:41 -0800
Subject: [PATCH] AMDGPU: Add baseline tests for copysign with known signmask
input
---
.../AMDGPU/copysign-simplify-demanded-bits.ll | 108 +
.../AMDGPU/copysign-to-disjoint-or-combine.ll | 208 ++
2 files changed, 316 insertions(+)
create mode 100644 llvm/test/CodeGen/AMDGPU/copysign-to-disjoint-or-combine.ll
diff --git a/llvm/test/CodeGen/AMDGPU/copysign-simplify-demanded-bits.ll
b/llvm/test/CodeGen/AMDGPU/copysign-simplify-demanded-bits.ll
index f5227eed458d6..0be2b5c70c93b 100644
--- a/llvm/test/CodeGen/AMDGPU/copysign-simplify-demanded-bits.ll
+++ b/llvm/test/CodeGen/AMDGPU/copysign-simplify-demanded-bits.ll
@@ -370,4 +370,112 @@ define float
@test_copysign_pow_fast_f32__integral_y(float %x, i32 %y.i) {
ret float %pow_sign1
}
+define double @test_pow_fast_f64integral_y(double %x, i32 %y.i) #0 {
+; GFX9-LABEL: test_pow_fast_f64integral_y:
+; GFX9: ; %bb.0:
+; GFX9-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX9-NEXT:s_mov_b32 s16, s33
+; GFX9-NEXT:s_mov_b32 s33, s32
+; GFX9-NEXT:s_or_saveexec_b64 s[18:19], -1
+; GFX9-NEXT:buffer_store_dword v43, off, s[0:3], s33 offset:12 ; 4-byte
Folded Spill
+; GFX9-NEXT:s_mov_b64 exec, s[18:19]
+; GFX9-NEXT:v_writelane_b32 v43, s16, 15
+; GFX9-NEXT:v_writelane_b32 v43, s30, 0
+; GFX9-NEXT:v_writelane_b32 v43, s31, 1
+; GFX9-NEXT:v_writelane_b32 v43, s34, 2
+; GFX9-NEXT:v_writelane_b32 v43, s35, 3
+; GFX9-NEXT:v_writelane_b32 v43, s36, 4
+; GFX9-NEXT:v_writelane_b32 v43, s37, 5
+; GFX9-NEXT:v_writelane_b32 v43, s38, 6
+; GFX9-NEXT:v_writelane_b32 v43, s39, 7
+; GFX9-NEXT:v_writelane_b32 v43, s48, 8
+; GFX9-NEXT:v_writelane_b32 v43, s49, 9
+; GFX9-NEXT:v_writelane_b32 v43, s50, 10
+; GFX9-NEXT:v_writelane_b32 v43, s51, 11
+; GFX9-NEXT:s_addk_i32 s32, 0x800
+; GFX9-NEXT:buffer_store_dword v40, off, s[0:3], s33 offset:8 ; 4-byte
Folded Spill
+; GFX9-NEXT:buffer_store_dword v41, off, s[0:3], s33 offset:4 ; 4-byte
Folded Spill
+; GFX9-NEXT:buffer_store_dword v42, off, s[0:3], s33 ; 4-byte Folded Spill
+; GFX9-NEXT:v_writelane_b32 v43, s52, 12
+; GFX9-NEXT:v_mov_b32_e32 v42, v1
+; GFX9-NEXT:v_writelane_b32 v43, s53, 13
+; GFX9-NEXT:v_and_b32_e32 v1, 0x7fff, v42
+; GFX9-NEXT:s_getpc_b64 s[16:17]
+; GFX9-NEXT:s_add_u32 s16, s16, _Z4log2d@rel32@lo+4
+; GFX9-NEXT:s_addc_u32 s17, s17, _Z4log2d@rel32@hi+12
+; GFX9-NEXT:v_writelane_b32 v43, s54, 14
+; GFX9-NEXT:v_mov_b32_e32 v40, v31
+; GFX9-NEXT:v_mov_b32_e32 v41, v2
+; GFX9-NEXT:s_mov_b32 s50, s15
+; GFX9-NEXT:s_mov_b32 s51, s14
+; GFX9-NEXT:s_mov_b32 s52, s13
+; GFX9-NEXT:s_mov_b32 s53, s12
+; GFX9-NEXT:s_mov_b64 s[34:35], s[10:11]
+; GFX9-NEXT:s_mov_b64 s[36:37], s[8:9]
+; GFX9-NEXT:s_mov_b64 s[38:39], s[6:7]
+; GFX9-NEXT:s_mov_b64 s[48:49], s[4:5]
+; GFX9-NEXT:s_brev_b32 s54, -2
+; GFX9-NEXT:s_swappc_b64 s[30:31], s[16:17]
+; GFX9-NEXT:v_cvt_f64_i32_e32 v[2:3], v41
+; GFX9-NEXT:s_getpc_b64 s[16:17]
+; GFX9-NEXT:s_add_u32 s16, s16, _Z4exp2d@rel32@lo+4
+; GFX9-NEXT:s_addc_u32 s17, s17, _Z4exp2d@rel32@hi+12
+; GFX9-NEXT:s_mov_b64 s[4:5], s[48:49]
+; GFX9-NEXT:s_mov_b64 s[6:7], s[38:39]
+; GFX9-NEXT:v_mul_f64 v[0:1], v[0:1], v[2:3]
+; GFX9-NEXT:s_mov_b64 s[8:9], s[36:37]
+; GFX9-NEXT:s_mov_b64 s[10:11], s[34:35]
+; GFX9-NEXT:s_mov_b32 s12, s53
+; GFX9-NEXT:s_mov_b32 s13, s52
+; GFX9-NEXT:s_mov_b32 s14, s51
+; GFX9-NEXT:s_mov_b32 s15, s50
+; GFX9-NEXT:v_mov_b32_e32 v31, v40
+; GFX9-NEXT:s_swappc_b64 s[30:31], s[16:17]
+; GFX9-NEXT:v_lshlrev_b32_e32 v2, 31, v41
+; GFX9-NEXT:v_and_b32_e32 v2, v2, v42
+; GFX9-NEXT:buffer_load_dword v42, off, s[0:3], s33 ; 4-byte Folded Reload
+; GFX9-NEXT:buffer_load_dword v41, off, s[0:3], s33 offset:4 ; 4-byte
Folded Reload
+; GFX9-NEXT:buffer_load_dword v40, off, s[0:3], s33 offset:8 ; 4-byte
Folded Reload
+; GFX9-NEXT:v_bfi_b32 v1, s54, v1, v2
+; GFX9-NEXT:v_readlane_b32 s54, v43, 14
+; GFX9-NEXT:v_readlane_b32 s53, v43, 13
+; GFX9-NEXT:v_readlane_b32 s52, v43, 12
+; GFX9-NEXT:v_readlane_b32 s51, v43, 11
+; GFX9-NEXT:v_readlane_b32 s50, v43, 10
+; GFX9-NEXT:v_readlane_b32 s49, v43, 9
+; GFX9-NEXT:v_readlane_b32 s48, v43, 8
+; GFX9-NEXT:v_readlane_b32 s39, v43, 7
+; GFX9-NEXT:v_readlane_b32 s38, v43, 6
+; GFX9-NEXT:v_readlane_b32 s37, v43, 5
+; GFX9-NEXT:v_readlane_b32 s36, v43, 4
+; GFX9-NEXT:v_readlane_b32 s35, v43, 3
+; GFX9-NEXT:v_readlane_b32 s34, v43, 2
+; GFX9-NEXT:v_readlane_b32 s31, v43, 1
+; GFX9-NEXT:v_readlane_b32 s30, v43, 0
+; GFX9-NEXT:s_mov_b32 s32, s33
+; GFX9-NEXT:v_readlane_b32 s4, v43
[llvm-branch-commits] [llvm] AMDGPU: Add baseline tests for copysign with known signmask input (PR #167265)
llvmbot wrote:
@llvm/pr-subscribers-backend-amdgpu
Author: Matt Arsenault (arsenm)
Changes
---
Full diff: https://github.com/llvm/llvm-project/pull/167265.diff
2 Files Affected:
- (modified) llvm/test/CodeGen/AMDGPU/copysign-simplify-demanded-bits.ll (+108)
- (added) llvm/test/CodeGen/AMDGPU/copysign-to-disjoint-or-combine.ll (+208)
``diff
diff --git a/llvm/test/CodeGen/AMDGPU/copysign-simplify-demanded-bits.ll
b/llvm/test/CodeGen/AMDGPU/copysign-simplify-demanded-bits.ll
index f5227eed458d6..0be2b5c70c93b 100644
--- a/llvm/test/CodeGen/AMDGPU/copysign-simplify-demanded-bits.ll
+++ b/llvm/test/CodeGen/AMDGPU/copysign-simplify-demanded-bits.ll
@@ -370,4 +370,112 @@ define float
@test_copysign_pow_fast_f32__integral_y(float %x, i32 %y.i) {
ret float %pow_sign1
}
+define double @test_pow_fast_f64integral_y(double %x, i32 %y.i) #0 {
+; GFX9-LABEL: test_pow_fast_f64integral_y:
+; GFX9: ; %bb.0:
+; GFX9-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX9-NEXT:s_mov_b32 s16, s33
+; GFX9-NEXT:s_mov_b32 s33, s32
+; GFX9-NEXT:s_or_saveexec_b64 s[18:19], -1
+; GFX9-NEXT:buffer_store_dword v43, off, s[0:3], s33 offset:12 ; 4-byte
Folded Spill
+; GFX9-NEXT:s_mov_b64 exec, s[18:19]
+; GFX9-NEXT:v_writelane_b32 v43, s16, 15
+; GFX9-NEXT:v_writelane_b32 v43, s30, 0
+; GFX9-NEXT:v_writelane_b32 v43, s31, 1
+; GFX9-NEXT:v_writelane_b32 v43, s34, 2
+; GFX9-NEXT:v_writelane_b32 v43, s35, 3
+; GFX9-NEXT:v_writelane_b32 v43, s36, 4
+; GFX9-NEXT:v_writelane_b32 v43, s37, 5
+; GFX9-NEXT:v_writelane_b32 v43, s38, 6
+; GFX9-NEXT:v_writelane_b32 v43, s39, 7
+; GFX9-NEXT:v_writelane_b32 v43, s48, 8
+; GFX9-NEXT:v_writelane_b32 v43, s49, 9
+; GFX9-NEXT:v_writelane_b32 v43, s50, 10
+; GFX9-NEXT:v_writelane_b32 v43, s51, 11
+; GFX9-NEXT:s_addk_i32 s32, 0x800
+; GFX9-NEXT:buffer_store_dword v40, off, s[0:3], s33 offset:8 ; 4-byte
Folded Spill
+; GFX9-NEXT:buffer_store_dword v41, off, s[0:3], s33 offset:4 ; 4-byte
Folded Spill
+; GFX9-NEXT:buffer_store_dword v42, off, s[0:3], s33 ; 4-byte Folded Spill
+; GFX9-NEXT:v_writelane_b32 v43, s52, 12
+; GFX9-NEXT:v_mov_b32_e32 v42, v1
+; GFX9-NEXT:v_writelane_b32 v43, s53, 13
+; GFX9-NEXT:v_and_b32_e32 v1, 0x7fff, v42
+; GFX9-NEXT:s_getpc_b64 s[16:17]
+; GFX9-NEXT:s_add_u32 s16, s16, _Z4log2d@rel32@lo+4
+; GFX9-NEXT:s_addc_u32 s17, s17, _Z4log2d@rel32@hi+12
+; GFX9-NEXT:v_writelane_b32 v43, s54, 14
+; GFX9-NEXT:v_mov_b32_e32 v40, v31
+; GFX9-NEXT:v_mov_b32_e32 v41, v2
+; GFX9-NEXT:s_mov_b32 s50, s15
+; GFX9-NEXT:s_mov_b32 s51, s14
+; GFX9-NEXT:s_mov_b32 s52, s13
+; GFX9-NEXT:s_mov_b32 s53, s12
+; GFX9-NEXT:s_mov_b64 s[34:35], s[10:11]
+; GFX9-NEXT:s_mov_b64 s[36:37], s[8:9]
+; GFX9-NEXT:s_mov_b64 s[38:39], s[6:7]
+; GFX9-NEXT:s_mov_b64 s[48:49], s[4:5]
+; GFX9-NEXT:s_brev_b32 s54, -2
+; GFX9-NEXT:s_swappc_b64 s[30:31], s[16:17]
+; GFX9-NEXT:v_cvt_f64_i32_e32 v[2:3], v41
+; GFX9-NEXT:s_getpc_b64 s[16:17]
+; GFX9-NEXT:s_add_u32 s16, s16, _Z4exp2d@rel32@lo+4
+; GFX9-NEXT:s_addc_u32 s17, s17, _Z4exp2d@rel32@hi+12
+; GFX9-NEXT:s_mov_b64 s[4:5], s[48:49]
+; GFX9-NEXT:s_mov_b64 s[6:7], s[38:39]
+; GFX9-NEXT:v_mul_f64 v[0:1], v[0:1], v[2:3]
+; GFX9-NEXT:s_mov_b64 s[8:9], s[36:37]
+; GFX9-NEXT:s_mov_b64 s[10:11], s[34:35]
+; GFX9-NEXT:s_mov_b32 s12, s53
+; GFX9-NEXT:s_mov_b32 s13, s52
+; GFX9-NEXT:s_mov_b32 s14, s51
+; GFX9-NEXT:s_mov_b32 s15, s50
+; GFX9-NEXT:v_mov_b32_e32 v31, v40
+; GFX9-NEXT:s_swappc_b64 s[30:31], s[16:17]
+; GFX9-NEXT:v_lshlrev_b32_e32 v2, 31, v41
+; GFX9-NEXT:v_and_b32_e32 v2, v2, v42
+; GFX9-NEXT:buffer_load_dword v42, off, s[0:3], s33 ; 4-byte Folded Reload
+; GFX9-NEXT:buffer_load_dword v41, off, s[0:3], s33 offset:4 ; 4-byte
Folded Reload
+; GFX9-NEXT:buffer_load_dword v40, off, s[0:3], s33 offset:8 ; 4-byte
Folded Reload
+; GFX9-NEXT:v_bfi_b32 v1, s54, v1, v2
+; GFX9-NEXT:v_readlane_b32 s54, v43, 14
+; GFX9-NEXT:v_readlane_b32 s53, v43, 13
+; GFX9-NEXT:v_readlane_b32 s52, v43, 12
+; GFX9-NEXT:v_readlane_b32 s51, v43, 11
+; GFX9-NEXT:v_readlane_b32 s50, v43, 10
+; GFX9-NEXT:v_readlane_b32 s49, v43, 9
+; GFX9-NEXT:v_readlane_b32 s48, v43, 8
+; GFX9-NEXT:v_readlane_b32 s39, v43, 7
+; GFX9-NEXT:v_readlane_b32 s38, v43, 6
+; GFX9-NEXT:v_readlane_b32 s37, v43, 5
+; GFX9-NEXT:v_readlane_b32 s36, v43, 4
+; GFX9-NEXT:v_readlane_b32 s35, v43, 3
+; GFX9-NEXT:v_readlane_b32 s34, v43, 2
+; GFX9-NEXT:v_readlane_b32 s31, v43, 1
+; GFX9-NEXT:v_readlane_b32 s30, v43, 0
+; GFX9-NEXT:s_mov_b32 s32, s33
+; GFX9-NEXT:v_readlane_b32 s4, v43, 15
+; GFX9-NEXT:s_or_saveexec_b64 s[6:7], -1
+; GFX9-NEXT:buffer_load_dword v43, off, s[0:3], s33 offset:12 ; 4-byte
Folded Reload
+; GFX9-NEXT:s_mov_b64 exec, s[6:7]
+; GFX9-NEXT:
[llvm-branch-commits] [llvm] DAG: Fold copysign with a known signmask to a disjoint or (PR #167266)
arsenm wrote: > [!WARNING] > This pull request is not mergeable via GitHub because a downstack PR is > open. Once all requirements are satisfied, merge this PR as a stack href="https://app.graphite.com/github/pr/llvm/llvm-project/167266?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#167266** https://app.graphite.com/github/pr/llvm/llvm-project/167266?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> π https://app.graphite.com/github/pr/llvm/llvm-project/167266?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#167265** https://app.graphite.com/github/pr/llvm/llvm-project/167265?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#167264** https://app.graphite.com/github/pr/llvm/llvm-project/167264?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#167263** https://app.graphite.com/github/pr/llvm/llvm-project/167263?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/167266 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] AMDGPU: Add baseline tests for copysign with known signmask input (PR #167265)
arsenm wrote: > [!WARNING] > This pull request is not mergeable via GitHub because a downstack PR is > open. Once all requirements are satisfied, merge this PR as a stack href="https://app.graphite.com/github/pr/llvm/llvm-project/167265?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#167266** https://app.graphite.com/github/pr/llvm/llvm-project/167266?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#167265** https://app.graphite.com/github/pr/llvm/llvm-project/167265?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> π https://app.graphite.com/github/pr/llvm/llvm-project/167265?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#167264** https://app.graphite.com/github/pr/llvm/llvm-project/167264?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#167263** https://app.graphite.com/github/pr/llvm/llvm-project/167263?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/167265 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] AMDGPU: Add baseline tests for copysign with known signmask input (PR #167265)
https://github.com/arsenm ready_for_review https://github.com/llvm/llvm-project/pull/167265 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] DAG: Fold copysign with a known signmask to a disjoint or (PR #167266)
https://github.com/arsenm edited https://github.com/llvm/llvm-project/pull/167266 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] DAG: Fold copysign with a known signmask to a disjoint or (PR #167266)
llvmbot wrote:
@llvm/pr-subscribers-backend-amdgpu
Author: Matt Arsenault (arsenm)
Changes
If the sign bit is a computed sign mask (i.e., we know it's
either +0 or -0), turn this into a disjoint or. This pattern
appears in the pow implementations.
We also need to know the sign bit of the magnitude is 0 for
the or to be disjoint. Unfortunately the DAG's FP tracking is
weak and we did not have a way to check if the sign bit is known
0, so add something for that. Ideally we would get a complete
computeKnownFPClass implementation.
This is intended to help avoid the regression which caused
d3e7c4ce7a3d7 to be reverted.
---
Full diff: https://github.com/llvm/llvm-project/pull/167266.diff
5 Files Affected:
- (modified) llvm/include/llvm/CodeGen/SelectionDAG.h (+4)
- (modified) llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (+20)
- (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (+28)
- (modified) llvm/test/CodeGen/AMDGPU/copysign-simplify-demanded-bits.ll
(+9-14)
- (modified) llvm/test/CodeGen/AMDGPU/copysign-to-disjoint-or-combine.ll
(+6-16)
``diff
diff --git a/llvm/include/llvm/CodeGen/SelectionDAG.h
b/llvm/include/llvm/CodeGen/SelectionDAG.h
index 0dd4f23c6d85f..5b331e915 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAG.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAG.h
@@ -2072,6 +2072,10 @@ class SelectionDAG {
/// We use this predicate to simplify operations downstream.
LLVM_ABI bool SignBitIsZero(SDValue Op, unsigned Depth = 0) const;
+ /// Return true if the sign bit of Op is known to be zero, for a
+ /// floating-point value.
+ LLVM_ABI bool SignBitIsZeroFP(SDValue Op, unsigned Depth = 0) const;
+
/// Return true if 'Op & Mask' is known to be zero. We
/// use this predicate to simplify operations downstream. Op and Mask are
/// known to be the same type.
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index f144f17d5a8f2..4f2eb1e64dbe0 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -18863,6 +18863,26 @@ SDValue DAGCombiner::visitFCOPYSIGN(SDNode *N) {
if (SimplifyDemandedBits(SDValue(N, 0)))
return SDValue(N, 0);
+ if (VT != N1.getValueType())
+return SDValue();
+
+ // If this is equivalent to a disjoint or, replace it with one. This can
+ // happen if the sign operand is a sign mask (i.e., x << sign_bit_position).
+ if (DAG.SignBitIsZeroFP(N0) &&
+ DAG.computeKnownBits(N1).Zero.isMaxSignedValue()) {
+// TODO: Just directly match the shift pattern. computeKnownBits is heavy
+// for a such a narrowly targeted case.
+EVT IntVT = VT.changeTypeToInteger();
+// TODO: It appears to be profitable in some situations to unconditionally
+// emit a fabs(n0) to perform this combine.
+SDValue CastSrc0 = DAG.getNode(ISD::BITCAST, DL, IntVT, N0);
+SDValue CastSrc1 = DAG.getNode(ISD::BITCAST, DL, IntVT, N1);
+
+SDValue SignOr = DAG.getNode(ISD::OR, DL, IntVT, CastSrc0, CastSrc1,
+ SDNodeFlags::Disjoint);
+return DAG.getNode(ISD::BITCAST, DL, VT, SignOr);
+ }
+
return SDValue();
}
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 80bbfea7fb83c..d7b3b03deb757 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -2920,6 +2920,34 @@ bool SelectionDAG::SignBitIsZero(SDValue Op, unsigned
Depth) const {
return MaskedValueIsZero(Op, APInt::getSignMask(BitWidth), Depth);
}
+bool SelectionDAG::SignBitIsZeroFP(SDValue Op, unsigned Depth) const {
+ if (Depth >= MaxRecursionDepth)
+return false; // Limit search depth.
+
+ unsigned Opc = Op.getOpcode();
+ switch (Opc) {
+ case ISD::FABS:
+return true;
+ case ISD::AssertNoFPClass: {
+FPClassTest NoFPClass =
+static_cast(Op.getConstantOperandVal(1));
+
+const FPClassTest TestMask = fcNan | fcNegative;
+return (NoFPClass & TestMask) == TestMask;
+ }
+ case ISD::ARITH_FENCE:
+return SignBitIsZeroFP(Op, Depth + 1);
+ case ISD::FEXP:
+ case ISD::FEXP2:
+ case ISD::FEXP10:
+return Op->getFlags().hasNoNaNs();
+ default:
+return false;
+ }
+
+ llvm_unreachable("covered opcode switch");
+}
+
/// MaskedValueIsZero - Return true if 'V & Mask' is known to be zero. We use
/// this predicate to simplify operations downstream. Mask is known to be zero
/// for bits that V cannot have.
diff --git a/llvm/test/CodeGen/AMDGPU/copysign-simplify-demanded-bits.ll
b/llvm/test/CodeGen/AMDGPU/copysign-simplify-demanded-bits.ll
index 0be2b5c70c93b..ef676ddc8070e 100644
--- a/llvm/test/CodeGen/AMDGPU/copysign-simplify-demanded-bits.ll
+++ b/llvm/test/CodeGen/AMDGPU/copysign-simplify-demanded-bits.ll
@@ -345,15 +345,13 @@ define float
@test_copysign_pow_fast_f32__integral_y(float %x, i32 %y.i) {
; GFX9-NEXT:v_cmp_gt_f32_e32 vcc
[llvm-branch-commits] [llvm] DAG: Add AssertNoFPClass from call return attributes (PR #167264)
https://github.com/arsenm ready_for_review https://github.com/llvm/llvm-project/pull/167264 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] DAG: Handle AssertNoFPClass in computeKnownBits (PR #167289)
https://github.com/arsenm created
https://github.com/llvm/llvm-project/pull/167289
It's possible to determine the sign bit if the value is known
one of the positive/negative classes and not-nan.
>From bb863b1346b9be8b77d79d566eba6105873b8293 Mon Sep 17 00:00:00 2001
From: Matt Arsenault
Date: Sun, 9 Nov 2025 23:49:26 -0800
Subject: [PATCH] DAG: Handle AssertNoFPClass in computeKnownBits
It's possible to determine the sign bit if the value is known
one of the positive/negative classes and not-nan.
---
.../lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 21 +++
.../AMDGPU/compute-known-bits-nofpclass.ll| 2 --
2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 80bbfea7fb83c..27dcd8a546d91 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -4121,6 +4121,27 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op,
const APInt &DemandedElts,
Known.One.clearLowBits(LogOfAlign);
break;
}
+ case ISD::AssertNoFPClass: {
+Known = computeKnownBits(Op.getOperand(0), DemandedElts, Depth + 1);
+
+FPClassTest NoFPClass =
+static_cast(Op.getConstantOperandVal(1));
+const FPClassTest NegativeTestMask = fcNan | fcNegative;
+if ((NoFPClass & NegativeTestMask) == NegativeTestMask) {
+ // Cannot be negative.
+ Known.Zero.setSignBit();
+ Known.One.clearSignBit();
+}
+
+const FPClassTest PositiveTestMask = fcNan | fcPositive;
+if ((NoFPClass & PositiveTestMask) == PositiveTestMask) {
+ // Cannot be positive.
+ Known.Zero.clearSignBit();
+ Known.One.setSignBit();
+}
+
+break;
+ }
case ISD::FGETSIGN:
// All bits are zero except the low bit.
Known.Zero.setBitsFrom(1);
diff --git a/llvm/test/CodeGen/AMDGPU/compute-known-bits-nofpclass.ll
b/llvm/test/CodeGen/AMDGPU/compute-known-bits-nofpclass.ll
index d440d58246333..244c3f7c2a96a 100644
--- a/llvm/test/CodeGen/AMDGPU/compute-known-bits-nofpclass.ll
+++ b/llvm/test/CodeGen/AMDGPU/compute-known-bits-nofpclass.ll
@@ -5,7 +5,6 @@ define i32 @known_positive(float nofpclass(nan ninf nzero nsub
nnorm) %signbit.z
; CHECK-LABEL: known_positive:
; CHECK: ; %bb.0:
; CHECK-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
-; CHECK-NEXT:v_and_b32_e32 v0, 0x7fff, v0
; CHECK-NEXT:s_setpc_b64 s[30:31]
%cast = bitcast float %signbit.zero to i32
%and = and i32 %cast, 2147483647
@@ -27,7 +26,6 @@ define i32 @known_negative(float nofpclass(nan pinf pzero
psub pnorm) %signbit.o
; CHECK-LABEL: known_negative:
; CHECK: ; %bb.0:
; CHECK-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
-; CHECK-NEXT:v_or_b32_e32 v0, 0x8000, v0
; CHECK-NEXT:s_setpc_b64 s[30:31]
%cast = bitcast float %signbit.one to i32
%or = or i32 %cast, -2147483648
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] DAG: Handle AssertNoFPClass in computeKnownBits (PR #167289)
arsenm wrote: > [!WARNING] > This pull request is not mergeable via GitHub because a downstack PR is > open. Once all requirements are satisfied, merge this PR as a stack href="https://app.graphite.com/github/pr/llvm/llvm-project/167289?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#167289** https://app.graphite.com/github/pr/llvm/llvm-project/167289?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> π https://app.graphite.com/github/pr/llvm/llvm-project/167289?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#167288** https://app.graphite.com/github/pr/llvm/llvm-project/167288?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/167289 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] DAG: Handle AssertNoFPClass in computeKnownBits (PR #167289)
https://github.com/arsenm ready_for_review https://github.com/llvm/llvm-project/pull/167289 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BPF] Add CLI option to enable misaligned memory access (PR #167013)
clairechingching wrote: Hey @yonghong-song I tried moving the `-bpf-allow-misaligned-mem-access` option into BPFSubtarget, but realized that the parameters managed there are mostly about CPU instruction-set features. It seems more consistent to keep `-bpf-allow-misaligned-mem-access` where it currently is next to `-bpf-expand-memcpy-in-order`, but Iβm curious what you think. https://github.com/llvm/llvm-project/pull/167013 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] lifetime-safety-paren (PR #167245)
usx95 wrote: > [!WARNING] > This pull request is not mergeable via GitHub because a downstack PR is > open. Once all requirements are satisfied, merge this PR as a stack href="https://app.graphite.com/github/pr/llvm/llvm-project/167245?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#167245** https://app.graphite.com/github/pr/llvm/llvm-project/167245?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> π https://app.graphite.com/github/pr/llvm/llvm-project/167245?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#167240** https://app.graphite.com/github/pr/llvm/llvm-project/167240?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/167245 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] lifetime-safety-paren (PR #167245)
https://github.com/usx95 created
https://github.com/llvm/llvm-project/pull/167245
None
>From 0daf4537eafb50fd313c9ee520087231350e2df1 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena
Date: Sun, 9 Nov 2025 20:23:40 +
Subject: [PATCH] lifetime-safety-paren
---
clang/lib/Analysis/LifetimeSafety/Origins.cpp | 2 ++
1 file changed, 2 insertions(+)
diff --git a/clang/lib/Analysis/LifetimeSafety/Origins.cpp
b/clang/lib/Analysis/LifetimeSafety/Origins.cpp
index ea51a75324e06..0f2eaa94a5987 100644
--- a/clang/lib/Analysis/LifetimeSafety/Origins.cpp
+++ b/clang/lib/Analysis/LifetimeSafety/Origins.cpp
@@ -34,6 +34,8 @@ Origin &OriginManager::addOrigin(OriginID ID, const
clang::Expr &E) {
// TODO: Mark this method as const once we remove the call to getOrCreate.
OriginID OriginManager::get(const Expr &E) {
+ if (auto *ParenIgnored = E.IgnoreParens(); ParenIgnored != &E)
+return get(*ParenIgnored);
auto It = ExprToOriginID.find(&E);
if (It != ExprToOriginID.end())
return It->second;
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] lifetime-safety-paren (PR #167245)
https://github.com/usx95 updated
https://github.com/llvm/llvm-project/pull/167245
>From 818b350b41924d477abe93643180cc45f9f33566 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena
Date: Sun, 9 Nov 2025 20:23:40 +
Subject: [PATCH] lifetime-safety-paren
---
clang/lib/Analysis/LifetimeSafety/Origins.cpp | 2 ++
clang/test/Sema/warn-lifetime-safety.cpp | 24 +++
.../unittests/Analysis/LifetimeSafetyTest.cpp | 17 +
3 files changed, 43 insertions(+)
diff --git a/clang/lib/Analysis/LifetimeSafety/Origins.cpp
b/clang/lib/Analysis/LifetimeSafety/Origins.cpp
index ea51a75324e06..0f2eaa94a5987 100644
--- a/clang/lib/Analysis/LifetimeSafety/Origins.cpp
+++ b/clang/lib/Analysis/LifetimeSafety/Origins.cpp
@@ -34,6 +34,8 @@ Origin &OriginManager::addOrigin(OriginID ID, const
clang::Expr &E) {
// TODO: Mark this method as const once we remove the call to getOrCreate.
OriginID OriginManager::get(const Expr &E) {
+ if (auto *ParenIgnored = E.IgnoreParens(); ParenIgnored != &E)
+return get(*ParenIgnored);
auto It = ExprToOriginID.find(&E);
if (It != ExprToOriginID.end())
return It->second;
diff --git a/clang/test/Sema/warn-lifetime-safety.cpp
b/clang/test/Sema/warn-lifetime-safety.cpp
index 3057ac9385736..52165c4236988 100644
--- a/clang/test/Sema/warn-lifetime-safety.cpp
+++ b/clang/test/Sema/warn-lifetime-safety.cpp
@@ -635,3 +635,27 @@ void conditional_operator(bool cond) {
} // expected-note 4 {{destroyed here}}
(void)*p; // expected-note 4 {{later used here}}
}
+
+void parentheses(bool cond) {
+ MyObj* p;
+ {
+MyObj a;
+p = &a; // expected-warning {{object whose reference is captured
does not live long enough}}
+ } // expected-note {{destroyed here}}
+ (void)*p; // expected-note {{later used here}}
+
+ {
+MyObj a;
+p = ((GetPointer((a; // expected-warning {{object whose reference is
captured does not live long enough}}
+ } // expected-note {{destroyed here}}
+ (void)*p; // expected-note {{later used here}}
+
+ {
+MyObj a, b, c, d;
+p = &(cond ? cond ? a // expected-warning {{object whose reference is
captured does not live long enough}}.
+ : b // expected-warning {{object whose reference is
captured does not live long enough}}.
+ : cond ? c // expected-warning {{object whose reference is
captured does not live long enough}}.
+ : d); // expected-warning {{object whose reference is
captured does not live long enough}}.
+ } // expected-note 4 {{destroyed here}}
+ (void)*p; // expected-note 4 {{later used here}}
+}
diff --git a/clang/unittests/Analysis/LifetimeSafetyTest.cpp
b/clang/unittests/Analysis/LifetimeSafetyTest.cpp
index 9d61d56e078e3..601308c53f9a9 100644
--- a/clang/unittests/Analysis/LifetimeSafetyTest.cpp
+++ b/clang/unittests/Analysis/LifetimeSafetyTest.cpp
@@ -700,6 +700,23 @@ TEST_F(LifetimeAnalysisTest,
GslPointerInConditionalOperator) {
EXPECT_THAT(Origin("v"), HasLoansTo({"a", "b"}, "p1"));
}
+TEST_F(LifetimeAnalysisTest, ExtraParenthesis) {
+ SetupTest(R"(
+void target() {
+ MyObj a;
+ View x = ((Viewa));
+ View y = ((View{(((x)))}));
+ View z = ((View(((y);
+ View p = ((View{((x))}));
+ POINT(p1);
+}
+ )");
+ EXPECT_THAT(Origin("x"), HasLoansTo({"a"}, "p1"));
+ EXPECT_THAT(Origin("y"), HasLoansTo({"a"}, "p1"));
+ EXPECT_THAT(Origin("z"), HasLoansTo({"a"}, "p1"));
+ EXPECT_THAT(Origin("p"), HasLoansTo({"a"}, "p1"));
+}
+
// FIXME: Handle temporaries.
TEST_F(LifetimeAnalysisTest, ViewFromTemporary) {
SetupTest(R"(
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [LifetimeSafety] Ignore parentheses when tracking expressions (PR #167245)
https://github.com/usx95 edited https://github.com/llvm/llvm-project/pull/167245 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [LifetimeSafety] Ignore parentheses when tracking expressions (PR #167245)
https://github.com/usx95 edited https://github.com/llvm/llvm-project/pull/167245 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [LifetimeSafety] Ignore parentheses when tracking expressions (PR #167245)
https://github.com/usx95 edited https://github.com/llvm/llvm-project/pull/167245 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [LifetimeSafety] Ignore parentheses when tracking expressions (PR #167245)
https://github.com/usx95 edited https://github.com/llvm/llvm-project/pull/167245 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [LifetimeSafety] Ignore parentheses when tracking expressions (PR #167245)
llvmbot wrote:
@llvm/pr-subscribers-clang-analysis
Author: Utkarsh Saxena (usx95)
Changes
Add support for handling parenthesized expressions in lifetime safety analysis.
Modified the `OriginManager::get` method to ignore parentheses when retrieving
origins by recursively calling itself on the unparenthesized expression. This
ensures that expressions with extra parentheses are properly analyzed for
lifetime safety issues.
---
Full diff: https://github.com/llvm/llvm-project/pull/167245.diff
3 Files Affected:
- (modified) clang/lib/Analysis/LifetimeSafety/Origins.cpp (+2)
- (modified) clang/test/Sema/warn-lifetime-safety.cpp (+24)
- (modified) clang/unittests/Analysis/LifetimeSafetyTest.cpp (+17)
``diff
diff --git a/clang/lib/Analysis/LifetimeSafety/Origins.cpp
b/clang/lib/Analysis/LifetimeSafety/Origins.cpp
index ea51a75324e06..0f2eaa94a5987 100644
--- a/clang/lib/Analysis/LifetimeSafety/Origins.cpp
+++ b/clang/lib/Analysis/LifetimeSafety/Origins.cpp
@@ -34,6 +34,8 @@ Origin &OriginManager::addOrigin(OriginID ID, const
clang::Expr &E) {
// TODO: Mark this method as const once we remove the call to getOrCreate.
OriginID OriginManager::get(const Expr &E) {
+ if (auto *ParenIgnored = E.IgnoreParens(); ParenIgnored != &E)
+return get(*ParenIgnored);
auto It = ExprToOriginID.find(&E);
if (It != ExprToOriginID.end())
return It->second;
diff --git a/clang/test/Sema/warn-lifetime-safety.cpp
b/clang/test/Sema/warn-lifetime-safety.cpp
index 3057ac9385736..52165c4236988 100644
--- a/clang/test/Sema/warn-lifetime-safety.cpp
+++ b/clang/test/Sema/warn-lifetime-safety.cpp
@@ -635,3 +635,27 @@ void conditional_operator(bool cond) {
} // expected-note 4 {{destroyed here}}
(void)*p; // expected-note 4 {{later used here}}
}
+
+void parentheses(bool cond) {
+ MyObj* p;
+ {
+MyObj a;
+p = &a; // expected-warning {{object whose reference is captured
does not live long enough}}
+ } // expected-note {{destroyed here}}
+ (void)*p; // expected-note {{later used here}}
+
+ {
+MyObj a;
+p = ((GetPointer((a; // expected-warning {{object whose reference is
captured does not live long enough}}
+ } // expected-note {{destroyed here}}
+ (void)*p; // expected-note {{later used here}}
+
+ {
+MyObj a, b, c, d;
+p = &(cond ? cond ? a // expected-warning {{object whose reference is
captured does not live long enough}}.
+ : b // expected-warning {{object whose reference is
captured does not live long enough}}.
+ : cond ? c // expected-warning {{object whose reference is
captured does not live long enough}}.
+ : d); // expected-warning {{object whose reference is
captured does not live long enough}}.
+ } // expected-note 4 {{destroyed here}}
+ (void)*p; // expected-note 4 {{later used here}}
+}
diff --git a/clang/unittests/Analysis/LifetimeSafetyTest.cpp
b/clang/unittests/Analysis/LifetimeSafetyTest.cpp
index 9d61d56e078e3..601308c53f9a9 100644
--- a/clang/unittests/Analysis/LifetimeSafetyTest.cpp
+++ b/clang/unittests/Analysis/LifetimeSafetyTest.cpp
@@ -700,6 +700,23 @@ TEST_F(LifetimeAnalysisTest,
GslPointerInConditionalOperator) {
EXPECT_THAT(Origin("v"), HasLoansTo({"a", "b"}, "p1"));
}
+TEST_F(LifetimeAnalysisTest, ExtraParenthesis) {
+ SetupTest(R"(
+void target() {
+ MyObj a;
+ View x = ((Viewa));
+ View y = ((View{(((x)))}));
+ View z = ((View(((y);
+ View p = ((View{((x))}));
+ POINT(p1);
+}
+ )");
+ EXPECT_THAT(Origin("x"), HasLoansTo({"a"}, "p1"));
+ EXPECT_THAT(Origin("y"), HasLoansTo({"a"}, "p1"));
+ EXPECT_THAT(Origin("z"), HasLoansTo({"a"}, "p1"));
+ EXPECT_THAT(Origin("p"), HasLoansTo({"a"}, "p1"));
+}
+
// FIXME: Handle temporaries.
TEST_F(LifetimeAnalysisTest, ViewFromTemporary) {
SetupTest(R"(
``
https://github.com/llvm/llvm-project/pull/167245
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [LifetimeSafety] Ignore parentheses when tracking expressions (PR #167245)
https://github.com/usx95 edited https://github.com/llvm/llvm-project/pull/167245 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [LifetimeSafety] Ignore parentheses when tracking expressions (PR #167245)
https://github.com/usx95 ready_for_review https://github.com/llvm/llvm-project/pull/167245 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [RFC][Clang] Allow plugins to hook into back-end (PR #165257)
aengelke wrote: ping -- are there further opinions or any objections to this direction? https://github.com/llvm/llvm-project/pull/165257 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [LifetimeSafety] Ignore parentheses when tracking expressions (PR #167245)
https://github.com/usx95 updated
https://github.com/llvm/llvm-project/pull/167245
>From 8e0d7d89d011eb5b3ddc76c3a4d6fc32ad9abe54 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena
Date: Sun, 9 Nov 2025 20:23:40 +
Subject: [PATCH] lifetime-safety-paren
---
clang/lib/Analysis/LifetimeSafety/Origins.cpp | 2 ++
clang/test/Sema/warn-lifetime-safety.cpp | 31 +++
.../unittests/Analysis/LifetimeSafetyTest.cpp | 17 ++
3 files changed, 50 insertions(+)
diff --git a/clang/lib/Analysis/LifetimeSafety/Origins.cpp
b/clang/lib/Analysis/LifetimeSafety/Origins.cpp
index ea51a75324e06..0f2eaa94a5987 100644
--- a/clang/lib/Analysis/LifetimeSafety/Origins.cpp
+++ b/clang/lib/Analysis/LifetimeSafety/Origins.cpp
@@ -34,6 +34,8 @@ Origin &OriginManager::addOrigin(OriginID ID, const
clang::Expr &E) {
// TODO: Mark this method as const once we remove the call to getOrCreate.
OriginID OriginManager::get(const Expr &E) {
+ if (auto *ParenIgnored = E.IgnoreParens(); ParenIgnored != &E)
+return get(*ParenIgnored);
auto It = ExprToOriginID.find(&E);
if (It != ExprToOriginID.end())
return It->second;
diff --git a/clang/test/Sema/warn-lifetime-safety.cpp
b/clang/test/Sema/warn-lifetime-safety.cpp
index 3057ac9385736..00e5ca23c8503 100644
--- a/clang/test/Sema/warn-lifetime-safety.cpp
+++ b/clang/test/Sema/warn-lifetime-safety.cpp
@@ -635,3 +635,34 @@ void conditional_operator(bool cond) {
} // expected-note 4 {{destroyed here}}
(void)*p; // expected-note 4 {{later used here}}
}
+
+void parentheses(bool cond) {
+ MyObj* p;
+ {
+MyObj a;
+p = &a; // expected-warning {{object whose reference is captured
does not live long enough}}
+ } // expected-note {{destroyed here}}
+ (void)*p; // expected-note {{later used here}}
+
+ {
+MyObj a;
+p = ((GetPointer((a; // expected-warning {{object whose reference is
captured does not live long enough}}
+ } // expected-note {{destroyed here}}
+ (void)*p; // expected-note {{later used here}}
+
+ {
+MyObj a, b, c, d;
+p = &(cond ? (cond ? a // expected-warning {{object whose reference is
captured does not live long enough}}.
+ : b)// expected-warning {{object whose reference is
captured does not live long enough}}.
+ : (cond ? c // expected-warning {{object whose reference is
captured does not live long enough}}.
+ : d)); // expected-warning {{object whose reference is
captured does not live long enough}}.
+ } // expected-note 4 {{destroyed here}}
+ (void)*p; // expected-note 4 {{later used here}}
+
+ {
+MyObj a, b, c, d;
+p = ((cond ? (((cond ? &a : &b))) // expected-warning 2 {{object whose
reference is captured does not live long enough}}.
+ : &(((cond ? c : d); // expected-warning 2 {{object whose
reference is captured does not live long enough}}.
+ } // expected-note 4 {{destroyed here}}
+ (void)*p; // expected-note 4 {{later used here}}
+}
diff --git a/clang/unittests/Analysis/LifetimeSafetyTest.cpp
b/clang/unittests/Analysis/LifetimeSafetyTest.cpp
index 9d61d56e078e3..601308c53f9a9 100644
--- a/clang/unittests/Analysis/LifetimeSafetyTest.cpp
+++ b/clang/unittests/Analysis/LifetimeSafetyTest.cpp
@@ -700,6 +700,23 @@ TEST_F(LifetimeAnalysisTest,
GslPointerInConditionalOperator) {
EXPECT_THAT(Origin("v"), HasLoansTo({"a", "b"}, "p1"));
}
+TEST_F(LifetimeAnalysisTest, ExtraParenthesis) {
+ SetupTest(R"(
+void target() {
+ MyObj a;
+ View x = ((Viewa));
+ View y = ((View{(((x)))}));
+ View z = ((View(((y);
+ View p = ((View{((x))}));
+ POINT(p1);
+}
+ )");
+ EXPECT_THAT(Origin("x"), HasLoansTo({"a"}, "p1"));
+ EXPECT_THAT(Origin("y"), HasLoansTo({"a"}, "p1"));
+ EXPECT_THAT(Origin("z"), HasLoansTo({"a"}, "p1"));
+ EXPECT_THAT(Origin("p"), HasLoansTo({"a"}, "p1"));
+}
+
// FIXME: Handle temporaries.
TEST_F(LifetimeAnalysisTest, ViewFromTemporary) {
SetupTest(R"(
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
