[llvm-branch-commits] [llvm] RuntimeLibcalls: Add definitions for vector math functions (PR #167026)
@@ -182,10 +182,63 @@ foreach FPTy = ["F32", "F64", "F80", "F128", "PPCF128"]
in {
def MODF_#FPTy : RuntimeLibcall;
}
-foreach VecTy = ["V4F32", "V2F64", "NXV4F32", "NXV2F64"] in {
- def MODF_#VecTy : RuntimeLibcall;
- def SINCOS_#VecTy : RuntimeLibcall;
- def SINCOSPI_#VecTy : RuntimeLibcall;
+defvar F32VectorSuffixes = ["V2F32", "V4F32", "V8F32", "V16F32", "NXV4F32"];
+defvar F64VectorSuffixes = ["V2F64", "V4F64", "V8F64", "NXV2F64"];
arsenm wrote:
Yes, this can't express all information yet. This is far too much to handle at
once
https://github.com/llvm/llvm-project/pull/167026
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] DAG: Use sincos vector libcalls through RuntimeLibcalls (PR #166984)
@@ -425,6 +425,24 @@ RTLIB::Libcall RTLIB::getCOS(EVT RetVT) {
}
RTLIB::Libcall RTLIB::getSINCOS(EVT RetVT) {
+ // TODO: Tablegen should generate this function
+ if (RetVT.isVector()) {
+if (!RetVT.isSimple())
+ return RTLIB::UNKNOWN_LIBCALL;
+switch (RetVT.getSimpleVT().SimpleTy) {
+case MVT::v4f32:
+ return RTLIB::SINCOS_V4F32;
+case MVT::v2f64:
+ return RTLIB::SINCOS_V2F64;
+case MVT::nxv4f32:
+ return RTLIB::SINCOS_NXV4F32;
+case MVT::nxv2f64:
+ return RTLIB::SINCOS_NXV2F64;
+default:
arsenm wrote:
It could but I'm only handling cases that are tested
https://github.com/llvm/llvm-project/pull/166984
___
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: [llvm-rc] Don't interpret integer literals as octal numbers in rc.exe mode (#166915) (PR #167174)
https://github.com/llvmbot created
https://github.com/llvm/llvm-project/pull/167174
Backport 3673cc7a4222c6b60d8bb287ca048efa37f61e3b
Requested by: @mstorsjo
>From bfac69297fb425d0739bea10d3096933f63b55bf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?=
Date: Sat, 8 Nov 2025 22:24:29 +0200
Subject: [PATCH] [llvm-rc] Don't interpret integer literals as octal numbers
in rc.exe mode (#166915)
It turns out that rc.exe doesn't interpret integer literals as octal
numbers - but GNU windres does. Previously, llvm-rc did interpret them
as octal.
Fix the issue by stripping away the leading zeros during tokenization.
The alternative (which would be somewhat cleaner, as visible in
tokenizer.test) would be to retain them in the RCToken object, but strip
them out before calling
StringRef::getAsInteger. Alternatively to handle the radix detection
locally in llvm-rc code and not rely on getAsInteger to autodetect it.
Both of those solutions require propagating the IsWindres flag so that
it is available within RCToken, or at least when calling
RCToken::intValue().
Fixes: https://github.com/llvm/llvm-project/issues/144723
(cherry picked from commit 3673cc7a4222c6b60d8bb287ca048efa37f61e3b)
---
.../tools/llvm-rc/Inputs/octal-in-range.rc| 4 ++
.../llvm-rc/Inputs/octal-out-of-range.rc | 4 ++
llvm/test/tools/llvm-rc/Inputs/tokens.rc | 2 +-
llvm/test/tools/llvm-rc/octal.test| 38
llvm/test/tools/llvm-rc/tokenizer.test| 5 ++-
llvm/tools/llvm-rc/ResourceScriptToken.cpp| 44 +++
llvm/tools/llvm-rc/ResourceScriptToken.h | 2 +-
.../tools/llvm-rc/ResourceScriptTokenList.def | 2 +-
llvm/tools/llvm-rc/llvm-rc.cpp| 3 +-
9 files changed, 90 insertions(+), 14 deletions(-)
create mode 100644 llvm/test/tools/llvm-rc/Inputs/octal-in-range.rc
create mode 100644 llvm/test/tools/llvm-rc/Inputs/octal-out-of-range.rc
create mode 100644 llvm/test/tools/llvm-rc/octal.test
diff --git a/llvm/test/tools/llvm-rc/Inputs/octal-in-range.rc
b/llvm/test/tools/llvm-rc/Inputs/octal-in-range.rc
new file mode 100644
index 0..8327ef9be9f5c
--- /dev/null
+++ b/llvm/test/tools/llvm-rc/Inputs/octal-in-range.rc
@@ -0,0 +1,4 @@
+1 VERSIONINFO
+FILEVERSION 0010,0010,0010,0010
+BEGIN
+END
diff --git a/llvm/test/tools/llvm-rc/Inputs/octal-out-of-range.rc
b/llvm/test/tools/llvm-rc/Inputs/octal-out-of-range.rc
new file mode 100644
index 0..ce520f245a48d
--- /dev/null
+++ b/llvm/test/tools/llvm-rc/Inputs/octal-out-of-range.rc
@@ -0,0 +1,4 @@
+1 VERSIONINFO
+FILEVERSION 9,08,09,1
+BEGIN
+END
diff --git a/llvm/test/tools/llvm-rc/Inputs/tokens.rc
b/llvm/test/tools/llvm-rc/Inputs/tokens.rc
index 20f77912477d9..caf01aeff45fe 100644
--- a/llvm/test/tools/llvm-rc/Inputs/tokens.rc
+++ b/llvm/test/tools/llvm-rc/Inputs/tokens.rc
@@ -1,4 +1,4 @@
-1 + 2 - 3214L & 0x120894 032173 2|&~+(-7){0xabcdef 0xABCDEFl} Begin End
+1 + 2 - 3214L & 0x120894 032173 -0042 009 2|&~+(-7){0xabcdef 0xABCDEFl} Begin
End
1*3/4
He11o LLVM
identifier-with-dashes
diff --git a/llvm/test/tools/llvm-rc/octal.test
b/llvm/test/tools/llvm-rc/octal.test
new file mode 100644
index 0..686c1fcf1608e
--- /dev/null
+++ b/llvm/test/tools/llvm-rc/octal.test
@@ -0,0 +1,38 @@
+; RUN: llvm-rc -no-preprocess /FO %t.in-range-rc.res --
%p/Inputs/octal-in-range.rc
+; RUN: llvm-readobj %t.in-range-rc.res | FileCheck %s
--check-prefix=IN-RANGE-RC
+; RUN: llvm-windres --no-preprocess %p/Inputs/octal-in-range.rc
%t.in-range-windres.res
+; RUN: llvm-readobj %t.in-range-windres.res | FileCheck %s
--check-prefix=IN-RANGE-WINDRES
+
+; IN-RANGE-RC: Data: (
+; IN-RANGE-RC-NEXT: : 5C003400 5600 53005F00 56004500
|\.4...V.S._.V.E.|
+; IN-RANGE-RC-NEXT: 0010: 52005300 49004F00 4E005F00 49004E00
|R.S.I.O.N._.I.N.|
+; IN-RANGE-RC-NEXT: 0020: 46004F00 BD04EFFE 0100
|F.O.|
+; IN-RANGE-RC-NEXT: 0030: 0A000A00 0A000A00
||
+; IN-RANGE-RC-NEXT: 0040:
||
+; IN-RANGE-RC-NEXT: 0050: ||
+; IN-RANGE-RC-NEXT: )
+
+; IN-RANGE-WINDRES: Data: (
+; IN-RANGE-WINDRES-NEXT: : 5C003400 5600 53005F00 56004500
|\.4...V.S._.V.E.|
+; IN-RANGE-WINDRES-NEXT: 0010: 52005300 49004F00 4E005F00 49004E00
|R.S.I.O.N._.I.N.|
+; IN-RANGE-WINDRES-NEXT: 0020: 46004F00 BD04EFFE 0100
|F.O.|
+; IN-RANGE-WINDRES-NEXT: 0030: 08000800 08000800
||
+; IN-RANGE-WINDRES-NEXT: 0040:
||
+; IN-RANGE-WINDRES-NEXT: 0050:
||
+; IN-RANGE-WINDRES-NEXT: )
+
+; RUN: llvm-rc -no-preprocess /FO %t.out-of-range-rc.res --
%p/Inputs/octal-out-of-range.rc
+; RUN: llvm-readobj %t.out-of-range-rc.res | FileCheck %s
--check-prefix=OUT-OF-RA
[llvm-branch-commits] [llvm] release/21.x: [llvm-rc] Don't interpret integer literals as octal numbers in rc.exe mode (#166915) (PR #167174)
https://github.com/llvmbot milestoned https://github.com/llvm/llvm-project/pull/167174 ___ 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: [llvm-rc] Don't interpret integer literals as octal numbers in rc.exe mode (#166915) (PR #167174)
llvmbot wrote: @aganea What do you think about merging this PR to the release branch? https://github.com/llvm/llvm-project/pull/167174 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] DAG: Use sincos vector libcalls through RuntimeLibcalls (PR #166984)
@@ -425,6 +425,24 @@ RTLIB::Libcall RTLIB::getCOS(EVT RetVT) {
}
RTLIB::Libcall RTLIB::getSINCOS(EVT RetVT) {
+ // TODO: Tablegen should generate this function
+ if (RetVT.isVector()) {
+if (!RetVT.isSimple())
+ return RTLIB::UNKNOWN_LIBCALL;
+switch (RetVT.getSimpleVT().SimpleTy) {
+case MVT::v4f32:
+ return RTLIB::SINCOS_V4F32;
+case MVT::v2f64:
+ return RTLIB::SINCOS_V2F64;
+case MVT::nxv4f32:
+ return RTLIB::SINCOS_NXV4F32;
+case MVT::nxv2f64:
+ return RTLIB::SINCOS_NXV2F64;
+default:
Andarwinux wrote:
Can this handle SINCOS_V8F64? AMDLIBM has this.
https://github.com/llvm/llvm-project/pull/166984
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] RuntimeLibcalls: Add definitions for vector math functions (PR #167026)
@@ -182,10 +182,63 @@ foreach FPTy = ["F32", "F64", "F80", "F128", "PPCF128"]
in {
def MODF_#FPTy : RuntimeLibcall;
}
-foreach VecTy = ["V4F32", "V2F64", "NXV4F32", "NXV2F64"] in {
- def MODF_#VecTy : RuntimeLibcall;
- def SINCOS_#VecTy : RuntimeLibcall;
- def SINCOSPI_#VecTy : RuntimeLibcall;
+defvar F32VectorSuffixes = ["V2F32", "V4F32", "V8F32", "V16F32", "NXV4F32"];
+defvar F64VectorSuffixes = ["V2F64", "V4F64", "V8F64", "NXV2F64"];
Andarwinux wrote:
Compared to VABI_PREFIX in VecFuncs.def, VectorSuffixes appears to lack certain
semantics. For instance, in VecFuncs.def, it is possible to add “FIXED(8),
MASKED, _ZGV_LLVM_M8vv”, but in VectorSuffixes, V8F64 seems unable to express
the NOMASK/MASKED semantics.
https://github.com/llvm/llvm-project/pull/167026
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] RuntimeLibcalls: Add definitions for vector math functions (PR #167026)
arsenm wrote: > What is the ultimate purpose of these PR? One of my use cases is using > SLEEFGNUABI as libmvec on MinGW that doesn't have libmvec. Will this be > affected? Merge TargetLibraryInfo and RuntimeLibcalls. We're maintaining 2 lists of functions now that are basically the same thing https://github.com/llvm/llvm-project/pull/167026 ___ 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: [llvm-rc] Don't interpret integer literals as octal numbers in rc.exe mode (#166915) (PR #167174)
https://github.com/aganea approved this pull request. https://github.com/llvm/llvm-project/pull/167174 ___ 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 created https://github.com/llvm/llvm-project/pull/167193 This method is not used anywhere. Remove it. ___ 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)
llvmbot wrote:
@llvm/pr-subscribers-llvm-support
Author: Vitaly Buka (vitalybuka)
Changes
This method is not used anywhere. Remove it.
---
Full diff: https://github.com/llvm/llvm-project/pull/167193.diff
2 Files Affected:
- (modified) llvm/include/llvm/Support/SpecialCaseList.h (-5)
- (modified) llvm/lib/Support/SpecialCaseList.cpp (-13)
``diff
diff --git a/llvm/include/llvm/Support/SpecialCaseList.h
b/llvm/include/llvm/Support/SpecialCaseList.h
index cb8e568de02e0..a10bbc61dcc3e 100644
--- a/llvm/include/llvm/Support/SpecialCaseList.h
+++ b/llvm/include/llvm/Support/SpecialCaseList.h
@@ -218,11 +218,6 @@ class SpecialCaseList {
LLVM_ABI unsigned getLastMatch(StringRef Prefix, StringRef Query,
StringRef Category) const;
-// Helper method to search by Prefix, Query, and Category. Returns
-// matching rule, or empty string if there is no match.
-LLVM_ABI StringRef getLongestMatch(StringRef Prefix, StringRef Query,
- StringRef Category) const;
-
private:
friend class SpecialCaseList;
LLVM_ABI void preprocess(bool OrderBySize);
diff --git a/llvm/lib/Support/SpecialCaseList.cpp
b/llvm/lib/Support/SpecialCaseList.cpp
index 246d90cce3a43..813fce35d88fe 100644
--- a/llvm/lib/Support/SpecialCaseList.cpp
+++ b/llvm/lib/Support/SpecialCaseList.cpp
@@ -380,17 +380,4 @@ unsigned SpecialCaseList::Section::getLastMatch(StringRef
Prefix,
return LastLine;
}
-StringRef SpecialCaseList::Section::getLongestMatch(StringRef Prefix,
-StringRef Query,
-StringRef Category) const {
- StringRef LongestRule;
- if (const Matcher *M = findMatcher(Prefix, Category)) {
-M->match(Query, [&](StringRef Rule, unsigned) {
- if (LongestRule.size() < Rule.size())
-LongestRule = Rule;
-});
- }
- return LongestRule;
-}
-
} // namespace llvm
``
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] [llvm] [AMDGPU] Enable amdgpu-lower-exec-sync pass in pipeline (PR #165746)
https://github.com/skc7 updated https://github.com/llvm/llvm-project/pull/165746
>From 6f7c7fa85142c7bc2d3bcc8df0a4ac440331bb5e Mon Sep 17 00:00:00 2001
From: skc7
Date: Thu, 30 Oct 2025 22:42:33 +0530
Subject: [PATCH 1/5] [AMDGPU] Enable amdgpu-lower-special-lds pass in pipeline
---
.../AMDGPU/AMDGPULowerModuleLDSPass.cpp | 126 --
llvm/lib/Target/AMDGPU/AMDGPUMemoryUtils.cpp | 6 +
llvm/lib/Target/AMDGPU/AMDGPUSwLowerLDS.cpp | 3 +-
.../lib/Target/AMDGPU/AMDGPUTargetMachine.cpp | 14 ++
...amdgpu-lower-special-lds-and-module-lds.ll | 119 +
.../amdgpu-lower-special-lds-and-sw-lds.ll| 86
llvm/test/CodeGen/AMDGPU/llc-pipeline-npm.ll | 6 +-
llvm/test/CodeGen/AMDGPU/llc-pipeline.ll | 5 +
.../test/CodeGen/AMDGPU/s-barrier-lowering.ll | 2 +-
9 files changed, 236 insertions(+), 131 deletions(-)
create mode 100644
llvm/test/CodeGen/AMDGPU/amdgpu-lower-special-lds-and-module-lds.ll
create mode 100644
llvm/test/CodeGen/AMDGPU/amdgpu-lower-special-lds-and-sw-lds.ll
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
b/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
index a4ef524c43466..3c0328e93ffbd 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
@@ -922,126 +922,6 @@ class AMDGPULowerModuleLDS {
return KernelToCreatedDynamicLDS;
}
- static GlobalVariable *uniquifyGVPerKernel(Module &M, GlobalVariable *GV,
- Function *KF) {
-bool NeedsReplacement = false;
-for (Use &U : GV->uses()) {
- if (auto *I = dyn_cast(U.getUser())) {
-Function *F = I->getFunction();
-if (isKernelLDS(F) && F != KF) {
- NeedsReplacement = true;
- break;
-}
- }
-}
-if (!NeedsReplacement)
- return GV;
-// Create a new GV used only by this kernel and its function
-GlobalVariable *NewGV = new GlobalVariable(
-M, GV->getValueType(), GV->isConstant(), GV->getLinkage(),
-GV->getInitializer(), GV->getName() + "." + KF->getName(), nullptr,
-GV->getThreadLocalMode(), GV->getType()->getAddressSpace());
-NewGV->copyAttributesFrom(GV);
-for (Use &U : make_early_inc_range(GV->uses())) {
- if (auto *I = dyn_cast(U.getUser())) {
-Function *F = I->getFunction();
-if (!isKernelLDS(F) || F == KF) {
- U.getUser()->replaceUsesOfWith(GV, NewGV);
-}
- }
-}
-return NewGV;
- }
-
- bool lowerSpecialLDSVariables(
- Module &M, LDSUsesInfoTy &LDSUsesInfo,
- VariableFunctionMap &LDSToKernelsThatNeedToAccessItIndirectly) {
-bool Changed = false;
-const DataLayout &DL = M.getDataLayout();
-// The 1st round: give module-absolute assignments
-int NumAbsolutes = 0;
-std::vector OrderedGVs;
-for (auto &K : LDSToKernelsThatNeedToAccessItIndirectly) {
- GlobalVariable *GV = K.first;
- if (!isNamedBarrier(*GV))
-continue;
- // give a module-absolute assignment if it is indirectly accessed by
- // multiple kernels. This is not precise, but we don't want to duplicate
- // a function when it is called by multiple kernels.
- if (LDSToKernelsThatNeedToAccessItIndirectly[GV].size() > 1) {
-OrderedGVs.push_back(GV);
- } else {
-// leave it to the 2nd round, which will give a kernel-relative
-// assignment if it is only indirectly accessed by one kernel
-LDSUsesInfo.direct_access[*K.second.begin()].insert(GV);
- }
- LDSToKernelsThatNeedToAccessItIndirectly.erase(GV);
-}
-OrderedGVs = sortByName(std::move(OrderedGVs));
-for (GlobalVariable *GV : OrderedGVs) {
- unsigned BarrierScope = llvm::AMDGPU::Barrier::BARRIER_SCOPE_WORKGROUP;
- unsigned BarId = NumAbsolutes + 1;
- unsigned BarCnt = DL.getTypeAllocSize(GV->getValueType()) / 16;
- NumAbsolutes += BarCnt;
-
- // 4 bits for alignment, 5 bits for the barrier num,
- // 3 bits for the barrier scope
- unsigned Offset = 0x802000u | BarrierScope << 9 | BarId << 4;
- recordLDSAbsoluteAddress(&M, GV, Offset);
-}
-OrderedGVs.clear();
-
-// The 2nd round: give a kernel-relative assignment for GV that
-// either only indirectly accessed by single kernel or only directly
-// accessed by multiple kernels.
-std::vector OrderedKernels;
-for (auto &K : LDSUsesInfo.direct_access) {
- Function *F = K.first;
- assert(isKernelLDS(F));
- OrderedKernels.push_back(F);
-}
-OrderedKernels = sortByName(std::move(OrderedKernels));
-
-llvm::DenseMap Kernel2BarId;
-for (Function *F : OrderedKernels) {
- for (GlobalVariable *GV : LDSUsesInfo.direct_access[F]) {
-if (!isNamedBarrier(*GV))
- continue;
-
-LDSUsesInfo.direct_access[F].erase(GV);
-if (GV->isAbsoluteSymbolRef()) {
- // already assigned
-
[llvm-branch-commits] [llvm] [AMDGPU] Remove named-barrier LDS lowering logic from amdgpu-lower-module-lds (PR #166731)
https://github.com/skc7 updated https://github.com/llvm/llvm-project/pull/166731
>From 16a03346058a75ae95b88c441d72267bb6b03327 Mon Sep 17 00:00:00 2001
From: skc7
Date: Thu, 6 Nov 2025 14:29:17 +0530
Subject: [PATCH] [AMDGPU] Remove lowering named-barrier LDS logci from
amdgpu-lower-module-lds
---
.../AMDGPU/AMDGPULowerModuleLDSPass.cpp | 126 --
1 file changed, 126 deletions(-)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
b/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
index a4ef524c43466..3c0328e93ffbd 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
@@ -922,126 +922,6 @@ class AMDGPULowerModuleLDS {
return KernelToCreatedDynamicLDS;
}
- static GlobalVariable *uniquifyGVPerKernel(Module &M, GlobalVariable *GV,
- Function *KF) {
-bool NeedsReplacement = false;
-for (Use &U : GV->uses()) {
- if (auto *I = dyn_cast(U.getUser())) {
-Function *F = I->getFunction();
-if (isKernelLDS(F) && F != KF) {
- NeedsReplacement = true;
- break;
-}
- }
-}
-if (!NeedsReplacement)
- return GV;
-// Create a new GV used only by this kernel and its function
-GlobalVariable *NewGV = new GlobalVariable(
-M, GV->getValueType(), GV->isConstant(), GV->getLinkage(),
-GV->getInitializer(), GV->getName() + "." + KF->getName(), nullptr,
-GV->getThreadLocalMode(), GV->getType()->getAddressSpace());
-NewGV->copyAttributesFrom(GV);
-for (Use &U : make_early_inc_range(GV->uses())) {
- if (auto *I = dyn_cast(U.getUser())) {
-Function *F = I->getFunction();
-if (!isKernelLDS(F) || F == KF) {
- U.getUser()->replaceUsesOfWith(GV, NewGV);
-}
- }
-}
-return NewGV;
- }
-
- bool lowerSpecialLDSVariables(
- Module &M, LDSUsesInfoTy &LDSUsesInfo,
- VariableFunctionMap &LDSToKernelsThatNeedToAccessItIndirectly) {
-bool Changed = false;
-const DataLayout &DL = M.getDataLayout();
-// The 1st round: give module-absolute assignments
-int NumAbsolutes = 0;
-std::vector OrderedGVs;
-for (auto &K : LDSToKernelsThatNeedToAccessItIndirectly) {
- GlobalVariable *GV = K.first;
- if (!isNamedBarrier(*GV))
-continue;
- // give a module-absolute assignment if it is indirectly accessed by
- // multiple kernels. This is not precise, but we don't want to duplicate
- // a function when it is called by multiple kernels.
- if (LDSToKernelsThatNeedToAccessItIndirectly[GV].size() > 1) {
-OrderedGVs.push_back(GV);
- } else {
-// leave it to the 2nd round, which will give a kernel-relative
-// assignment if it is only indirectly accessed by one kernel
-LDSUsesInfo.direct_access[*K.second.begin()].insert(GV);
- }
- LDSToKernelsThatNeedToAccessItIndirectly.erase(GV);
-}
-OrderedGVs = sortByName(std::move(OrderedGVs));
-for (GlobalVariable *GV : OrderedGVs) {
- unsigned BarrierScope = llvm::AMDGPU::Barrier::BARRIER_SCOPE_WORKGROUP;
- unsigned BarId = NumAbsolutes + 1;
- unsigned BarCnt = DL.getTypeAllocSize(GV->getValueType()) / 16;
- NumAbsolutes += BarCnt;
-
- // 4 bits for alignment, 5 bits for the barrier num,
- // 3 bits for the barrier scope
- unsigned Offset = 0x802000u | BarrierScope << 9 | BarId << 4;
- recordLDSAbsoluteAddress(&M, GV, Offset);
-}
-OrderedGVs.clear();
-
-// The 2nd round: give a kernel-relative assignment for GV that
-// either only indirectly accessed by single kernel or only directly
-// accessed by multiple kernels.
-std::vector OrderedKernels;
-for (auto &K : LDSUsesInfo.direct_access) {
- Function *F = K.first;
- assert(isKernelLDS(F));
- OrderedKernels.push_back(F);
-}
-OrderedKernels = sortByName(std::move(OrderedKernels));
-
-llvm::DenseMap Kernel2BarId;
-for (Function *F : OrderedKernels) {
- for (GlobalVariable *GV : LDSUsesInfo.direct_access[F]) {
-if (!isNamedBarrier(*GV))
- continue;
-
-LDSUsesInfo.direct_access[F].erase(GV);
-if (GV->isAbsoluteSymbolRef()) {
- // already assigned
- continue;
-}
-OrderedGVs.push_back(GV);
- }
- OrderedGVs = sortByName(std::move(OrderedGVs));
- for (GlobalVariable *GV : OrderedGVs) {
-// GV could also be used directly by other kernels. If so, we need to
-// create a new GV used only by this kernel and its function.
-auto NewGV = uniquifyGVPerKernel(M, GV, F);
-Changed |= (NewGV != GV);
-unsigned BarrierScope = llvm::AMDGPU::Barrier::BARRIER_SCOPE_WORKGROUP;
-unsigned BarId = Kernel2BarId[F];
-BarId += NumAbsolutes + 1;
-unsigned BarCnt = DL.getTypeAllocSize(GV->getValueType()) / 16;
-
[llvm-branch-commits] [llvm] [openmp] [OpenMP][Offload] Add offload runtime support for dyn_groupprivate clause (PR #152831)
https://github.com/kevinsala updated
https://github.com/llvm/llvm-project/pull/152831
>From fa3c7425ae9e5ffea83841f2be61b0f494b99038 Mon Sep 17 00:00:00 2001
From: Kevin Sala
Date: Fri, 8 Aug 2025 11:25:14 -0700
Subject: [PATCH 1/5] [OpenMP][Offload] Add offload runtime support for
dyn_groupprivate clause
---
offload/DeviceRTL/include/DeviceTypes.h | 4 +
offload/DeviceRTL/include/Interface.h | 2 +-
offload/DeviceRTL/include/State.h | 2 +-
offload/DeviceRTL/src/Kernel.cpp | 14 +-
offload/DeviceRTL/src/State.cpp | 48 +-
offload/include/Shared/APITypes.h | 6 +-
offload/include/Shared/Environment.h | 4 +-
offload/include/device.h | 3 +
offload/include/omptarget.h | 7 +-
offload/libomptarget/OpenMP/API.cpp | 14 ++
offload/libomptarget/device.cpp | 6 +
offload/libomptarget/exports | 1 +
.../amdgpu/dynamic_hsa/hsa_ext_amd.h | 1 +
offload/plugins-nextgen/amdgpu/src/rtl.cpp| 34 +++--
.../common/include/PluginInterface.h | 33 +++-
.../common/src/PluginInterface.cpp| 86 ---
.../plugins-nextgen/cuda/dynamic_cuda/cuda.h | 1 +
offload/plugins-nextgen/cuda/src/rtl.cpp | 37 +++--
offload/plugins-nextgen/host/src/rtl.cpp | 4 +-
.../offloading/dyn_groupprivate_strict.cpp| 141 ++
openmp/runtime/src/include/omp.h.var | 10 ++
openmp/runtime/src/kmp_csupport.cpp | 9 ++
openmp/runtime/src/kmp_stub.cpp | 16 ++
23 files changed, 418 insertions(+), 65 deletions(-)
create mode 100644 offload/test/offloading/dyn_groupprivate_strict.cpp
diff --git a/offload/DeviceRTL/include/DeviceTypes.h
b/offload/DeviceRTL/include/DeviceTypes.h
index 2e5d92380f040..a43b506d6879e 100644
--- a/offload/DeviceRTL/include/DeviceTypes.h
+++ b/offload/DeviceRTL/include/DeviceTypes.h
@@ -163,4 +163,8 @@ typedef enum omp_allocator_handle_t {
///}
+enum omp_access_t {
+ omp_access_cgroup = 0,
+};
+
#endif
diff --git a/offload/DeviceRTL/include/Interface.h
b/offload/DeviceRTL/include/Interface.h
index c4bfaaa2404b4..672afea206785 100644
--- a/offload/DeviceRTL/include/Interface.h
+++ b/offload/DeviceRTL/include/Interface.h
@@ -222,7 +222,7 @@ struct KernelEnvironmentTy;
int8_t __kmpc_is_spmd_exec_mode();
int32_t __kmpc_target_init(KernelEnvironmentTy &KernelEnvironment,
- KernelLaunchEnvironmentTy &KernelLaunchEnvironment);
+ KernelLaunchEnvironmentTy *KernelLaunchEnvironment);
void __kmpc_target_deinit();
diff --git a/offload/DeviceRTL/include/State.h
b/offload/DeviceRTL/include/State.h
index db396dae6e445..17c3c6f2d3e42 100644
--- a/offload/DeviceRTL/include/State.h
+++ b/offload/DeviceRTL/include/State.h
@@ -116,7 +116,7 @@ extern Local ThreadStates;
/// Initialize the state machinery. Must be called by all threads.
void init(bool IsSPMD, KernelEnvironmentTy &KernelEnvironment,
- KernelLaunchEnvironmentTy &KernelLaunchEnvironment);
+ KernelLaunchEnvironmentTy *KernelLaunchEnvironment);
/// Return the kernel and kernel launch environment associated with the current
/// kernel. The former is static and contains compile time information that
diff --git a/offload/DeviceRTL/src/Kernel.cpp b/offload/DeviceRTL/src/Kernel.cpp
index 467e44a65276c..58e9a09105a76 100644
--- a/offload/DeviceRTL/src/Kernel.cpp
+++ b/offload/DeviceRTL/src/Kernel.cpp
@@ -34,8 +34,8 @@ enum OMPTgtExecModeFlags : unsigned char {
};
static void
-inititializeRuntime(bool IsSPMD, KernelEnvironmentTy &KernelEnvironment,
-KernelLaunchEnvironmentTy &KernelLaunchEnvironment) {
+initializeRuntime(bool IsSPMD, KernelEnvironmentTy &KernelEnvironment,
+ KernelLaunchEnvironmentTy *KernelLaunchEnvironment) {
// Order is important here.
synchronize::init(IsSPMD);
mapping::init(IsSPMD);
@@ -80,17 +80,17 @@ extern "C" {
/// \param Ident Source location identification, can be NULL.
///
int32_t __kmpc_target_init(KernelEnvironmentTy &KernelEnvironment,
- KernelLaunchEnvironmentTy &KernelLaunchEnvironment)
{
+ KernelLaunchEnvironmentTy *KernelLaunchEnvironment)
{
ConfigurationEnvironmentTy &Configuration = KernelEnvironment.Configuration;
bool IsSPMD = Configuration.ExecMode & OMP_TGT_EXEC_MODE_SPMD;
bool UseGenericStateMachine = Configuration.UseGenericStateMachine;
if (IsSPMD) {
-inititializeRuntime(/*IsSPMD=*/true, KernelEnvironment,
-KernelLaunchEnvironment);
+initializeRuntime(/*IsSPMD=*/true, KernelEnvironment,
+ KernelLaunchEnvironment);
synchronize::threadsAligned(atomic::relaxed);
} else {
-inititializeRuntime(/*IsSPMD=*/false, KernelEnvironment,
-KernelLaunchEnv
[llvm-branch-commits] [llvm] [openmp] [OpenMP][Offload] Add offload runtime support for dyn_groupprivate clause (PR #152831)
@@ -107,7 +107,7 @@ enum TargetAllocTy : int32_t {
inline KernelArgsTy CTorDTorKernelArgs = {1, 0, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr,
-0, {0,0,0}, {1, 0, 0}, {1, 0, 0}, 0};
+0, {0,0,0,0}, {1, 0, 0}, {1, 0, 0}, 0};
kevinsala wrote:
This struct was removed.
https://github.com/llvm/llvm-project/pull/152831
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [openmp] [OpenMP][Offload] Add offload runtime support for dyn_groupprivate clause (PR #152831)
kevinsala wrote: Ping. https://github.com/llvm/llvm-project/pull/152831 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] DAG: Move expandMultipleResultFPLibCall to TargetLowering (NFC) (PR #166988)
https://github.com/RKSimon approved this pull request. https://github.com/llvm/llvm-project/pull/166988 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [IRBuilder] Add getByteTy and use it in CreatePtrAdd (PR #106539)
https://github.com/s-barannikov updated
https://github.com/llvm/llvm-project/pull/106539
>From 29393ec1a47e1daec9a5d9374df5bd5785b37903 Mon Sep 17 00:00:00 2001
From: Sergei Barannikov
Date: Thu, 22 Aug 2024 15:10:58 +0300
Subject: [PATCH] [IRBuilder] Add getByteTy and use it in CreatePtrAdd
The change requires DataLayout instance to be available, which, in turn,
requires insertion point to be set. In-tree tests detected only one case
when the function was called without setting an insertion point, it was
changed to create a constant expression directly.
---
llvm/include/llvm/IR/IRBuilder.h | 10 +++--
.../Instrumentation/SanitizerCoverage.cpp | 5 ++---
llvm/unittests/IR/IRBuilderTest.cpp | 22 +++
3 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index 972a253344ddf..3bc1b85506fda 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -543,6 +543,12 @@ class IRBuilderBase {
// Type creation methods
//======//
+ /// Fetch the type representing a byte.
+ IntegerType *getByteTy() {
+const DataLayout &DL = BB->getDataLayout();
+return Type::getIntNTy(Context, DL.getByteWidth());
+ }
+
/// Fetch the type representing a single bit
IntegerType *getInt1Ty() {
return Type::getInt1Ty(Context);
@@ -2038,12 +2044,12 @@ class IRBuilderBase {
Value *CreatePtrAdd(Value *Ptr, Value *Offset, const Twine &Name = "",
GEPNoWrapFlags NW = GEPNoWrapFlags::none()) {
-return CreateGEP(getInt8Ty(), Ptr, Offset, Name, NW);
+return CreateGEP(getByteTy(), Ptr, Offset, Name, NW);
}
Value *CreateInBoundsPtrAdd(Value *Ptr, Value *Offset,
const Twine &Name = "") {
-return CreateGEP(getInt8Ty(), Ptr, Offset, Name,
+return CreateGEP(getByteTy(), Ptr, Offset, Name,
GEPNoWrapFlags::inBounds());
}
diff --git a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
index 09abf6a33648c..6a8887a95726c 100644
--- a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
+++ b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
@@ -369,14 +369,13 @@ ModuleSanitizerCoverage::CreateSecStartEnd(Module &M,
const char *Section,
GlobalVariable *SecEnd = new GlobalVariable(M, Ty, false, Linkage, nullptr,
getSectionEnd(Section));
SecEnd->setVisibility(GlobalValue::HiddenVisibility);
- IRBuilder<> IRB(M.getContext());
if (!TargetTriple.isOSBinFormatCOFF())
return std::make_pair(SecStart, SecEnd);
// Account for the fact that on windows-msvc __start_* symbols actually
// point to a uint64_t before the start of the array.
- auto GEP =
- IRB.CreatePtrAdd(SecStart, ConstantInt::get(IntptrTy, sizeof(uint64_t)));
+ Constant *GEP = ConstantExpr::getGetElementPtr(
+ Int8Ty, SecStart, ConstantInt::get(IntptrTy, sizeof(uint64_t)));
return std::make_pair(GEP, SecEnd);
}
diff --git a/llvm/unittests/IR/IRBuilderTest.cpp
b/llvm/unittests/IR/IRBuilderTest.cpp
index 4d5bbe971a060..cba3fb8250f3d 100644
--- a/llvm/unittests/IR/IRBuilderTest.cpp
+++ b/llvm/unittests/IR/IRBuilderTest.cpp
@@ -521,6 +521,14 @@ TEST_F(IRBuilderTest, DataLayout) {
EXPECT_FALSE(M->getDataLayout().isLegalInteger(32));
}
+TEST_F(IRBuilderTest, GetByteTy) {
+ IRBuilder<> Builder(BB);
+
+ EXPECT_TRUE(Builder.getByteTy()->isIntegerTy(8));
+ M->setDataLayout("b:32");
+ EXPECT_TRUE(Builder.getByteTy()->isIntegerTy(32));
+}
+
TEST_F(IRBuilderTest, GetIntTy) {
IRBuilder<> Builder(BB);
IntegerType *Ty1 = Builder.getInt1Ty();
@@ -532,6 +540,20 @@ TEST_F(IRBuilderTest, GetIntTy) {
EXPECT_EQ(IntPtrTy, IntegerType::get(Ctx, IntPtrBitSize));
}
+TEST_F(IRBuilderTest, CreatePtrAdd) {
+ IRBuilder<> Builder(BB);
+
+ M->setDataLayout("b:16-p:32:32");
+ Value *V = Builder.CreatePtrAdd(GV, ConstantInt::get(Ctx, APInt(32, 42)));
+ ASSERT_TRUE(isa(V));
+ EXPECT_TRUE(cast(V)->getResultElementType()->isIntegerTy(16));
+
+ M->setDataLayout("b:32-p:64:32");
+ V = Builder.CreateInBoundsPtrAdd(GV, ConstantInt::get(Ctx, APInt(64, 42)));
+ ASSERT_TRUE(isa(V));
+ EXPECT_TRUE(cast(V)->getResultElementType()->isIntegerTy(32));
+}
+
TEST_F(IRBuilderTest, UnaryOperators) {
IRBuilder Builder(BB);
Value *V = Builder.CreateLoad(GV->getValueType(), GV);
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [ValueTracking] Make isBytewiseValue byte width agnostic (PR #106538)
https://github.com/s-barannikov updated
https://github.com/llvm/llvm-project/pull/106538
>From c5eb6f75da616f6bb8d025ec07a884cd6c186082 Mon Sep 17 00:00:00 2001
From: Sergei Barannikov
Date: Fri, 2 Aug 2024 13:14:49 +0300
Subject: [PATCH] [ValueTracking] Make isBytewiseValue byte width agnostic
This is a simple change to show how easy it can be to support unusual
byte widths in the middle end.
---
llvm/lib/Analysis/ValueTracking.cpp | 30 +++--
1 file changed, 16 insertions(+), 14 deletions(-)
diff --git a/llvm/lib/Analysis/ValueTracking.cpp
b/llvm/lib/Analysis/ValueTracking.cpp
index 41ff816a33262..5d17034b6c93e 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -6260,21 +6260,22 @@ bool llvm::canIgnoreSignBitOfNaN(const Use &U) {
}
Value *llvm::isBytewiseValue(Value *V, const DataLayout &DL) {
+ unsigned ByteWidth = DL.getByteWidth();
// All byte-wide stores are splatable, even of arbitrary variables.
- if (V->getType()->isIntegerTy(8))
+ if (V->getType()->isIntegerTy(ByteWidth))
return V;
LLVMContext &Ctx = V->getContext();
// Undef don't care.
- auto *UndefInt8 = UndefValue::get(Type::getInt8Ty(Ctx));
+ auto *UndefByte = UndefValue::get(Type::getIntNTy(Ctx, ByteWidth));
if (isa(V))
-return UndefInt8;
+return UndefByte;
// Return poison for zero-sized type.
if (DL.getTypeStoreSize(V->getType()).isZero())
-return PoisonValue::get(Type::getInt8Ty(Ctx));
+return PoisonValue::get(Type::getIntNTy(Ctx, ByteWidth));
Constant *C = dyn_cast(V);
if (!C) {
@@ -6289,7 +6290,7 @@ Value *llvm::isBytewiseValue(Value *V, const DataLayout
&DL) {
// Handle 'null' ConstantArrayZero etc.
if (C->isNullValue())
-return Constant::getNullValue(Type::getInt8Ty(Ctx));
+return Constant::getNullValue(Type::getIntNTy(Ctx, ByteWidth));
// Constant floating-point values can be handled as integer values if the
// corresponding integer value is "byteable". An important case is 0.0.
@@ -6306,13 +6307,14 @@ Value *llvm::isBytewiseValue(Value *V, const DataLayout
&DL) {
: nullptr;
}
- // We can handle constant integers that are multiple of 8 bits.
+ // We can handle constant integers that are multiple of the byte width.
if (ConstantInt *CI = dyn_cast(C)) {
-if (CI->getBitWidth() % 8 == 0) {
- assert(CI->getBitWidth() > 8 && "8 bits should be handled above!");
- if (!CI->getValue().isSplat(8))
+if (CI->getBitWidth() % ByteWidth == 0) {
+ assert(CI->getBitWidth() > ByteWidth &&
+ "single byte should be handled above!");
+ if (!CI->getValue().isSplat(ByteWidth))
return nullptr;
- return ConstantInt::get(Ctx, CI->getValue().trunc(8));
+ return ConstantInt::get(Ctx, CI->getValue().trunc(ByteWidth));
}
}
@@ -6332,15 +6334,15 @@ Value *llvm::isBytewiseValue(Value *V, const DataLayout
&DL) {
return LHS;
if (!LHS || !RHS)
return nullptr;
-if (LHS == UndefInt8)
+if (LHS == UndefByte)
return RHS;
-if (RHS == UndefInt8)
+if (RHS == UndefByte)
return LHS;
return nullptr;
};
if (ConstantDataSequential *CA = dyn_cast(C)) {
-Value *Val = UndefInt8;
+Value *Val = UndefByte;
for (uint64_t I = 0, E = CA->getNumElements(); I != E; ++I)
if (!(Val = Merge(Val, isBytewiseValue(CA->getElementAsConstant(I),
DL
return nullptr;
@@ -6348,7 +6350,7 @@ Value *llvm::isBytewiseValue(Value *V, const DataLayout
&DL) {
}
if (isa(C)) {
-Value *Val = UndefInt8;
+Value *Val = UndefByte;
for (Value *Op : C->operands())
if (!(Val = Merge(Val, isBytewiseValue(Op, DL
return nullptr;
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [SimplifyLibCalls] Add initial support for non-8-bit bytes (PR #106542)
https://github.com/s-barannikov updated https://github.com/llvm/llvm-project/pull/106542 >From 73b19130005768e6af7ce6a50780a65feb031e7e Mon Sep 17 00:00:00 2001 From: Sergei Barannikov Date: Wed, 28 Aug 2024 16:09:44 +0300 Subject: [PATCH] [SimplifyLibCalls] Add initial support for non-8-bit bytes The patch makes CharWidth argument of `getStringLength` mandatory and ensures the correct values are passed in most cases. This is *not* a complete support for unusual byte widths in SimplifyLibCalls since `getConstantStringInfo` returns false for those. The code guarded by `getConstantStringInfo` returning true is unchanged because the changes are currently not testable. --- llvm/include/llvm/Analysis/ValueTracking.h| 4 +- .../llvm/Transforms/Utils/SimplifyLibCalls.h | 4 +- llvm/lib/Analysis/MemoryBuiltins.cpp | 3 +- llvm/lib/Analysis/ValueTracking.cpp | 40 ++-- .../InstCombine/InstCombineCalls.cpp | 12 +- .../InstCombine/InstructionCombining.cpp | 5 +- .../lib/Transforms/Utils/SimplifyLibCalls.cpp | 193 -- .../InstCombine/SimplifyLibCalls/fputs-b16.ll | 19 ++ .../SimplifyLibCalls/fwrite-b16.ll| 19 ++ .../SimplifyLibCalls/memchr-b16.ll| 34 +++ .../SimplifyLibCalls/memcmp-b32.ll| 32 +++ .../SimplifyLibCalls/memcpy-b16.ll| 69 +++ .../SimplifyLibCalls/memcpy_chk-b16.ll| 17 ++ .../SimplifyLibCalls/mempcpy-b16.ll | 17 ++ .../SimplifyLibCalls/memrchr-b16.ll | 20 ++ .../SimplifyLibCalls/memset-b16.ll| 66 ++ .../SimplifyLibCalls/stpcpy-b16.ll| 31 +++ .../SimplifyLibCalls/stpcpy_chk-b16.ll| 44 .../SimplifyLibCalls/stpncpy-b16.ll | 47 + .../SimplifyLibCalls/strcat-b16.ll| 20 ++ .../SimplifyLibCalls/strchr-b16.ll| 45 .../SimplifyLibCalls/strcmp-b32.ll| 50 + .../SimplifyLibCalls/strcpy-b16.ll| 18 ++ .../SimplifyLibCalls/strcpy_chk-b16.ll| 30 +++ .../SimplifyLibCalls/strlcpy-b16.ll | 18 ++ .../SimplifyLibCalls/strlen-b16.ll| 16 ++ .../SimplifyLibCalls/strncat-b16.ll | 20 ++ .../SimplifyLibCalls/strncmp-b32.ll | 34 +++ .../SimplifyLibCalls/strncpy-b16.ll | 43 .../SimplifyLibCalls/strndup-b16.ll | 17 ++ .../SimplifyLibCalls/strnlen-b16.ll | 18 ++ .../SimplifyLibCalls/wcslen-b16.ll| 19 ++ llvm/test/Transforms/InstCombine/bcmp-1.ll| 2 +- llvm/test/Transforms/InstCombine/memcmp-1.ll | 2 +- llvm/test/Transforms/InstCombine/strncmp-1.ll | 2 +- 35 files changed, 929 insertions(+), 101 deletions(-) create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/fputs-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/fwrite-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/memchr-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/memcmp-b32.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/memcpy-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/memcpy_chk-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/mempcpy-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/memrchr-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/memset-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/stpcpy-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/stpcpy_chk-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/stpncpy-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/strcat-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/strchr-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/strcmp-b32.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/strcpy-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/strcpy_chk-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/strlcpy-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/strlen-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/strncat-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/strncmp-b32.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/strncpy-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/strndup-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/strnlen-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/wcslen-b16.ll diff --git a/llvm/include/llvm/Analysis/ValueTracking.h b/llvm/include/llvm/Analysis/ValueTracking.h index 36e
[llvm-branch-commits] [llvm] [IR] Account for byte width in m_PtrAdd (PR #106540)
https://github.com/s-barannikov updated
https://github.com/llvm/llvm-project/pull/106540
>From 856e1f0e6e767a154e93acb22a923ccee3b69850 Mon Sep 17 00:00:00 2001
From: Sergei Barannikov
Date: Thu, 29 Aug 2024 00:54:20 +0300
Subject: [PATCH] [IR] Account for byte width in m_PtrAdd
The method has few uses yet, so just pass DL argument to it. The change
follows m_PtrToIntSameSize, and I don't see a better way of delivering
the byte width to the method.
---
llvm/include/llvm/IR/PatternMatch.h | 13 ++
llvm/lib/Analysis/InstructionSimplify.cpp | 2 +-
.../InstCombineSimplifyDemanded.cpp | 7 ++---
.../InstCombine/InstructionCombining.cpp | 2 +-
.../Scalar/SeparateConstOffsetFromGEP.cpp | 2 +-
llvm/unittests/IR/PatternMatch.cpp| 26 ++-
6 files changed, 35 insertions(+), 17 deletions(-)
diff --git a/llvm/include/llvm/IR/PatternMatch.h
b/llvm/include/llvm/IR/PatternMatch.h
index 88aef4a368f29..39a65d8b7db99 100644
--- a/llvm/include/llvm/IR/PatternMatch.h
+++ b/llvm/include/llvm/IR/PatternMatch.h
@@ -2046,15 +2046,17 @@ struct m_SplatOrPoisonMask {
};
template struct PtrAdd_match {
+ const DataLayout &DL;
PointerOpTy PointerOp;
OffsetOpTy OffsetOp;
- PtrAdd_match(const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp)
- : PointerOp(PointerOp), OffsetOp(OffsetOp) {}
+ PtrAdd_match(const DataLayout &DL, const PointerOpTy &PointerOp,
+ const OffsetOpTy &OffsetOp)
+ : DL(DL), PointerOp(PointerOp), OffsetOp(OffsetOp) {}
template bool match(OpTy *V) const {
auto *GEP = dyn_cast(V);
-return GEP && GEP->getSourceElementType()->isIntegerTy(8) &&
+return GEP && GEP->getSourceElementType()->isIntegerTy(DL.getByteWidth())
&&
PointerOp.match(GEP->getPointerOperand()) &&
OffsetOp.match(GEP->idx_begin()->get());
}
@@ -2096,8 +2098,9 @@ inline auto m_GEP(const OperandTypes &...Ops) {
/// Matches GEP with i8 source element type
template
inline PtrAdd_match
-m_PtrAdd(const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp) {
- return PtrAdd_match(PointerOp, OffsetOp);
+m_PtrAdd(const DataLayout &DL, const PointerOpTy &PointerOp,
+ const OffsetOpTy &OffsetOp) {
+ return PtrAdd_match(DL, PointerOp, OffsetOp);
}
//===--===//
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp
b/llvm/lib/Analysis/InstructionSimplify.cpp
index 2a0a6a2d302b1..ba2aedc5fc714 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -5533,7 +5533,7 @@ static Value *simplifyCastInst(unsigned CastOpc, Value
*Op, Type *Ty,
Value *Ptr, *X;
if ((CastOpc == Instruction::PtrToInt || CastOpc == Instruction::PtrToAddr)
&&
match(Op,
-m_PtrAdd(m_Value(Ptr),
+m_PtrAdd(Q.DL, m_Value(Ptr),
m_Sub(m_Value(X), m_PtrToIntOrAddr(m_Deferred(Ptr) &&
X->getType() == Ty && Ty == Q.DL.getIndexType(Ptr->getType()))
return X;
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
index 550dfc57a348b..0728063385bc3 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
@@ -1052,9 +1052,10 @@ Value
*InstCombinerImpl::SimplifyDemandedUseBits(Instruction *I,
Value *InnerPtr;
uint64_t GEPIndex;
uint64_t PtrMaskImmediate;
-if (match(I, m_Intrinsic(
- m_PtrAdd(m_Value(InnerPtr), m_ConstantInt(GEPIndex)),
- m_ConstantInt(PtrMaskImmediate {
+if (match(I,
+ m_Intrinsic(
+ m_PtrAdd(DL, m_Value(InnerPtr), m_ConstantInt(GEPIndex)),
+ m_ConstantInt(PtrMaskImmediate {
LHSKnown = computeKnownBits(InnerPtr, I, Depth + 1);
if (!LHSKnown.isZero()) {
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index b158e0f626850..aba0216d6a760 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -2692,7 +2692,7 @@ static Instruction
*canonicalizeGEPOfConstGEPI8(GetElementPtrInst &GEP,
auto &DL = IC.getDataLayout();
Value *Base;
const APInt *C1;
- if (!match(Src, m_PtrAdd(m_Value(Base), m_APInt(C1
+ if (!match(Src, m_PtrAdd(DL, m_Value(Base), m_APInt(C1
return nullptr;
Value *VarIndex;
const APInt *C2;
diff --git a/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
b/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
index 333cbb6ed1384..8362412b742f6 100644
--- a/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
+++ b/llvm/lib/Transforms/Scalar/SeparateConstOff
[llvm-branch-commits] [llvm] [IR] Account for byte width in m_PtrAdd (PR #106540)
https://github.com/s-barannikov updated
https://github.com/llvm/llvm-project/pull/106540
>From 856e1f0e6e767a154e93acb22a923ccee3b69850 Mon Sep 17 00:00:00 2001
From: Sergei Barannikov
Date: Thu, 29 Aug 2024 00:54:20 +0300
Subject: [PATCH] [IR] Account for byte width in m_PtrAdd
The method has few uses yet, so just pass DL argument to it. The change
follows m_PtrToIntSameSize, and I don't see a better way of delivering
the byte width to the method.
---
llvm/include/llvm/IR/PatternMatch.h | 13 ++
llvm/lib/Analysis/InstructionSimplify.cpp | 2 +-
.../InstCombineSimplifyDemanded.cpp | 7 ++---
.../InstCombine/InstructionCombining.cpp | 2 +-
.../Scalar/SeparateConstOffsetFromGEP.cpp | 2 +-
llvm/unittests/IR/PatternMatch.cpp| 26 ++-
6 files changed, 35 insertions(+), 17 deletions(-)
diff --git a/llvm/include/llvm/IR/PatternMatch.h
b/llvm/include/llvm/IR/PatternMatch.h
index 88aef4a368f29..39a65d8b7db99 100644
--- a/llvm/include/llvm/IR/PatternMatch.h
+++ b/llvm/include/llvm/IR/PatternMatch.h
@@ -2046,15 +2046,17 @@ struct m_SplatOrPoisonMask {
};
template struct PtrAdd_match {
+ const DataLayout &DL;
PointerOpTy PointerOp;
OffsetOpTy OffsetOp;
- PtrAdd_match(const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp)
- : PointerOp(PointerOp), OffsetOp(OffsetOp) {}
+ PtrAdd_match(const DataLayout &DL, const PointerOpTy &PointerOp,
+ const OffsetOpTy &OffsetOp)
+ : DL(DL), PointerOp(PointerOp), OffsetOp(OffsetOp) {}
template bool match(OpTy *V) const {
auto *GEP = dyn_cast(V);
-return GEP && GEP->getSourceElementType()->isIntegerTy(8) &&
+return GEP && GEP->getSourceElementType()->isIntegerTy(DL.getByteWidth())
&&
PointerOp.match(GEP->getPointerOperand()) &&
OffsetOp.match(GEP->idx_begin()->get());
}
@@ -2096,8 +2098,9 @@ inline auto m_GEP(const OperandTypes &...Ops) {
/// Matches GEP with i8 source element type
template
inline PtrAdd_match
-m_PtrAdd(const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp) {
- return PtrAdd_match(PointerOp, OffsetOp);
+m_PtrAdd(const DataLayout &DL, const PointerOpTy &PointerOp,
+ const OffsetOpTy &OffsetOp) {
+ return PtrAdd_match(DL, PointerOp, OffsetOp);
}
//===--===//
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp
b/llvm/lib/Analysis/InstructionSimplify.cpp
index 2a0a6a2d302b1..ba2aedc5fc714 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -5533,7 +5533,7 @@ static Value *simplifyCastInst(unsigned CastOpc, Value
*Op, Type *Ty,
Value *Ptr, *X;
if ((CastOpc == Instruction::PtrToInt || CastOpc == Instruction::PtrToAddr)
&&
match(Op,
-m_PtrAdd(m_Value(Ptr),
+m_PtrAdd(Q.DL, m_Value(Ptr),
m_Sub(m_Value(X), m_PtrToIntOrAddr(m_Deferred(Ptr) &&
X->getType() == Ty && Ty == Q.DL.getIndexType(Ptr->getType()))
return X;
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
index 550dfc57a348b..0728063385bc3 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
@@ -1052,9 +1052,10 @@ Value
*InstCombinerImpl::SimplifyDemandedUseBits(Instruction *I,
Value *InnerPtr;
uint64_t GEPIndex;
uint64_t PtrMaskImmediate;
-if (match(I, m_Intrinsic(
- m_PtrAdd(m_Value(InnerPtr), m_ConstantInt(GEPIndex)),
- m_ConstantInt(PtrMaskImmediate {
+if (match(I,
+ m_Intrinsic(
+ m_PtrAdd(DL, m_Value(InnerPtr), m_ConstantInt(GEPIndex)),
+ m_ConstantInt(PtrMaskImmediate {
LHSKnown = computeKnownBits(InnerPtr, I, Depth + 1);
if (!LHSKnown.isZero()) {
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index b158e0f626850..aba0216d6a760 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -2692,7 +2692,7 @@ static Instruction
*canonicalizeGEPOfConstGEPI8(GetElementPtrInst &GEP,
auto &DL = IC.getDataLayout();
Value *Base;
const APInt *C1;
- if (!match(Src, m_PtrAdd(m_Value(Base), m_APInt(C1
+ if (!match(Src, m_PtrAdd(DL, m_Value(Base), m_APInt(C1
return nullptr;
Value *VarIndex;
const APInt *C2;
diff --git a/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
b/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
index 333cbb6ed1384..8362412b742f6 100644
--- a/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
+++ b/llvm/lib/Transforms/Scalar/SeparateConstOff
[llvm-branch-commits] [clang] [llvm] [ValueTracking] Add CharWidth argument to getConstantStringInfo (NFC) (PR #106541)
https://github.com/s-barannikov updated
https://github.com/llvm/llvm-project/pull/106541
>From 0d66f010d7d2f1a91a41a1db311480efde023dc3 Mon Sep 17 00:00:00 2001
From: Sergei Barannikov
Date: Wed, 28 Aug 2024 23:51:13 +0300
Subject: [PATCH] [ValueTracking] Add CharWidth argument to
getConstantStringInfo (NFC)
The method assumes that host chars and target chars have the same width.
Add a CharWidth argument so that it can bail out if the requested char
width differs from the host char width.
Alternatively, the check could be done at call sites, but this is more
error-prone.
In the future, this method will be replaced with a different one that
allows host/target chars to have different widths. The prototype will
be the same except that StringRef is replaced with something that is
byte width agnostic. Adding CharWidth argument now reduces the future
diff.
---
clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp | 4 +-
llvm/include/llvm/Analysis/ValueTracking.h| 2 +-
llvm/lib/Analysis/ValueTracking.cpp | 7 +-
.../AMDGPU/AMDGPUPrintfRuntimeBinding.cpp | 4 +-
llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp | 2 +-
.../Target/SPIRV/SPIRVPrepareFunctions.cpp| 2 +-
.../WebAssembly/WebAssemblyAsmPrinter.cpp | 2 +-
.../AggressiveInstCombine.cpp | 12 +-
.../lib/Transforms/Utils/AMDGPUEmitPrintf.cpp | 4 +-
.../lib/Transforms/Utils/SimplifyLibCalls.cpp | 103 --
10 files changed, 96 insertions(+), 46 deletions(-)
diff --git a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
index 9eab70955b6b9..075ffa0117aae 100644
--- a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
@@ -306,7 +306,7 @@ void CodeGenFunction::ProcessOrderScopeAMDGCN(Value *Order,
Value *Scope,
// Some of the atomic builtins take the scope as a string name.
StringRef scp;
- if (llvm::getConstantStringInfo(Scope, scp)) {
+ if (llvm::getConstantStringInfo(Scope, scp, /*CharWidth=*/8)) {
if (getTarget().getTriple().isSPIRV())
scp = mapScopeToSPIRV(scp);
SSID = getLLVMContext().getOrInsertSyncScopeID(scp);
@@ -369,7 +369,7 @@ void
CodeGenFunction::AddAMDGPUFenceAddressSpaceMMRA(llvm::Instruction *Inst,
for (unsigned K = 2; K < E->getNumArgs(); ++K) {
llvm::Value *V = EmitScalarExpr(E->getArg(K));
StringRef AS;
-if (llvm::getConstantStringInfo(V, AS)) {
+if (llvm::getConstantStringInfo(V, AS, /*CharWidth=*/8)) {
MMRAs.push_back({Tag, AS});
// TODO: Delete the resulting unused constant?
continue;
diff --git a/llvm/include/llvm/Analysis/ValueTracking.h
b/llvm/include/llvm/Analysis/ValueTracking.h
index 093309cb8bbee..36ebc8f8d7fb5 100644
--- a/llvm/include/llvm/Analysis/ValueTracking.h
+++ b/llvm/include/llvm/Analysis/ValueTracking.h
@@ -399,7 +399,7 @@ LLVM_ABI bool getConstantDataArrayInfo(const Value *V,
/// trailing null characters as well as any other characters that come after
/// it.
LLVM_ABI bool getConstantStringInfo(const Value *V, StringRef &Str,
-bool TrimAtNul = true);
+unsigned CharWidth, bool TrimAtNul = true);
/// If we can compute the length of the string pointed to by the specified
/// pointer, return 'len+1'. If we can't, return 0.
diff --git a/llvm/lib/Analysis/ValueTracking.cpp
b/llvm/lib/Analysis/ValueTracking.cpp
index 5d17034b6c93e..7363d060bdba7 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -6628,9 +6628,12 @@ bool llvm::getConstantDataArrayInfo(const Value *V,
/// return true. When TrimAtNul is set, Str will contain only the bytes up
/// to but not including the first nul. Return false on failure.
bool llvm::getConstantStringInfo(const Value *V, StringRef &Str,
- bool TrimAtNul) {
+ unsigned CharWidth, bool TrimAtNul) {
+ if (CharWidth != CHAR_BIT)
+return false;
+
ConstantDataArraySlice Slice;
- if (!getConstantDataArrayInfo(V, Slice, 8))
+ if (!getConstantDataArrayInfo(V, Slice, CharWidth))
return false;
if (Slice.Array == nullptr) {
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
b/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
index f5e14c71b02d9..a5b9d51d488c2 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
@@ -121,7 +121,7 @@ static_assert(NonLiteralStr.size() == 3);
static StringRef getAsConstantStr(Value *V) {
StringRef S;
- if (!getConstantStringInfo(V, S))
+ if (!getConstantStringInfo(V, S, /*CharWidth=*/8))
S = NonLiteralStr;
return S;
@@ -154,7 +154,7 @@ bool
AMDGPUPrintfRuntimeBindingImpl::lowerPrintfForGpu(Module &M) {
Value *Op = CI->getArgOperand(0);
StringRef FormatStr;
-if (!getConstantStringInfo(Op, FormatStr)) {
+if (!getC
[llvm-branch-commits] [llvm] [SimplifyLibCalls] Add initial support for non-8-bit bytes (PR #106542)
https://github.com/s-barannikov updated https://github.com/llvm/llvm-project/pull/106542 >From 73b19130005768e6af7ce6a50780a65feb031e7e Mon Sep 17 00:00:00 2001 From: Sergei Barannikov Date: Wed, 28 Aug 2024 16:09:44 +0300 Subject: [PATCH] [SimplifyLibCalls] Add initial support for non-8-bit bytes The patch makes CharWidth argument of `getStringLength` mandatory and ensures the correct values are passed in most cases. This is *not* a complete support for unusual byte widths in SimplifyLibCalls since `getConstantStringInfo` returns false for those. The code guarded by `getConstantStringInfo` returning true is unchanged because the changes are currently not testable. --- llvm/include/llvm/Analysis/ValueTracking.h| 4 +- .../llvm/Transforms/Utils/SimplifyLibCalls.h | 4 +- llvm/lib/Analysis/MemoryBuiltins.cpp | 3 +- llvm/lib/Analysis/ValueTracking.cpp | 40 ++-- .../InstCombine/InstCombineCalls.cpp | 12 +- .../InstCombine/InstructionCombining.cpp | 5 +- .../lib/Transforms/Utils/SimplifyLibCalls.cpp | 193 -- .../InstCombine/SimplifyLibCalls/fputs-b16.ll | 19 ++ .../SimplifyLibCalls/fwrite-b16.ll| 19 ++ .../SimplifyLibCalls/memchr-b16.ll| 34 +++ .../SimplifyLibCalls/memcmp-b32.ll| 32 +++ .../SimplifyLibCalls/memcpy-b16.ll| 69 +++ .../SimplifyLibCalls/memcpy_chk-b16.ll| 17 ++ .../SimplifyLibCalls/mempcpy-b16.ll | 17 ++ .../SimplifyLibCalls/memrchr-b16.ll | 20 ++ .../SimplifyLibCalls/memset-b16.ll| 66 ++ .../SimplifyLibCalls/stpcpy-b16.ll| 31 +++ .../SimplifyLibCalls/stpcpy_chk-b16.ll| 44 .../SimplifyLibCalls/stpncpy-b16.ll | 47 + .../SimplifyLibCalls/strcat-b16.ll| 20 ++ .../SimplifyLibCalls/strchr-b16.ll| 45 .../SimplifyLibCalls/strcmp-b32.ll| 50 + .../SimplifyLibCalls/strcpy-b16.ll| 18 ++ .../SimplifyLibCalls/strcpy_chk-b16.ll| 30 +++ .../SimplifyLibCalls/strlcpy-b16.ll | 18 ++ .../SimplifyLibCalls/strlen-b16.ll| 16 ++ .../SimplifyLibCalls/strncat-b16.ll | 20 ++ .../SimplifyLibCalls/strncmp-b32.ll | 34 +++ .../SimplifyLibCalls/strncpy-b16.ll | 43 .../SimplifyLibCalls/strndup-b16.ll | 17 ++ .../SimplifyLibCalls/strnlen-b16.ll | 18 ++ .../SimplifyLibCalls/wcslen-b16.ll| 19 ++ llvm/test/Transforms/InstCombine/bcmp-1.ll| 2 +- llvm/test/Transforms/InstCombine/memcmp-1.ll | 2 +- llvm/test/Transforms/InstCombine/strncmp-1.ll | 2 +- 35 files changed, 929 insertions(+), 101 deletions(-) create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/fputs-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/fwrite-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/memchr-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/memcmp-b32.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/memcpy-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/memcpy_chk-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/mempcpy-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/memrchr-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/memset-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/stpcpy-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/stpcpy_chk-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/stpncpy-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/strcat-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/strchr-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/strcmp-b32.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/strcpy-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/strcpy_chk-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/strlcpy-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/strlen-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/strncat-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/strncmp-b32.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/strncpy-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/strndup-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/strnlen-b16.ll create mode 100644 llvm/test/Transforms/InstCombine/SimplifyLibCalls/wcslen-b16.ll diff --git a/llvm/include/llvm/Analysis/ValueTracking.h b/llvm/include/llvm/Analysis/ValueTracking.h index 36e
[llvm-branch-commits] [llvm] [IRBuilder] Add getByteTy and use it in CreatePtrAdd (PR #106539)
https://github.com/s-barannikov updated
https://github.com/llvm/llvm-project/pull/106539
>From 29393ec1a47e1daec9a5d9374df5bd5785b37903 Mon Sep 17 00:00:00 2001
From: Sergei Barannikov
Date: Thu, 22 Aug 2024 15:10:58 +0300
Subject: [PATCH] [IRBuilder] Add getByteTy and use it in CreatePtrAdd
The change requires DataLayout instance to be available, which, in turn,
requires insertion point to be set. In-tree tests detected only one case
when the function was called without setting an insertion point, it was
changed to create a constant expression directly.
---
llvm/include/llvm/IR/IRBuilder.h | 10 +++--
.../Instrumentation/SanitizerCoverage.cpp | 5 ++---
llvm/unittests/IR/IRBuilderTest.cpp | 22 +++
3 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index 972a253344ddf..3bc1b85506fda 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -543,6 +543,12 @@ class IRBuilderBase {
// Type creation methods
//======//
+ /// Fetch the type representing a byte.
+ IntegerType *getByteTy() {
+const DataLayout &DL = BB->getDataLayout();
+return Type::getIntNTy(Context, DL.getByteWidth());
+ }
+
/// Fetch the type representing a single bit
IntegerType *getInt1Ty() {
return Type::getInt1Ty(Context);
@@ -2038,12 +2044,12 @@ class IRBuilderBase {
Value *CreatePtrAdd(Value *Ptr, Value *Offset, const Twine &Name = "",
GEPNoWrapFlags NW = GEPNoWrapFlags::none()) {
-return CreateGEP(getInt8Ty(), Ptr, Offset, Name, NW);
+return CreateGEP(getByteTy(), Ptr, Offset, Name, NW);
}
Value *CreateInBoundsPtrAdd(Value *Ptr, Value *Offset,
const Twine &Name = "") {
-return CreateGEP(getInt8Ty(), Ptr, Offset, Name,
+return CreateGEP(getByteTy(), Ptr, Offset, Name,
GEPNoWrapFlags::inBounds());
}
diff --git a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
index 09abf6a33648c..6a8887a95726c 100644
--- a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
+++ b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
@@ -369,14 +369,13 @@ ModuleSanitizerCoverage::CreateSecStartEnd(Module &M,
const char *Section,
GlobalVariable *SecEnd = new GlobalVariable(M, Ty, false, Linkage, nullptr,
getSectionEnd(Section));
SecEnd->setVisibility(GlobalValue::HiddenVisibility);
- IRBuilder<> IRB(M.getContext());
if (!TargetTriple.isOSBinFormatCOFF())
return std::make_pair(SecStart, SecEnd);
// Account for the fact that on windows-msvc __start_* symbols actually
// point to a uint64_t before the start of the array.
- auto GEP =
- IRB.CreatePtrAdd(SecStart, ConstantInt::get(IntptrTy, sizeof(uint64_t)));
+ Constant *GEP = ConstantExpr::getGetElementPtr(
+ Int8Ty, SecStart, ConstantInt::get(IntptrTy, sizeof(uint64_t)));
return std::make_pair(GEP, SecEnd);
}
diff --git a/llvm/unittests/IR/IRBuilderTest.cpp
b/llvm/unittests/IR/IRBuilderTest.cpp
index 4d5bbe971a060..cba3fb8250f3d 100644
--- a/llvm/unittests/IR/IRBuilderTest.cpp
+++ b/llvm/unittests/IR/IRBuilderTest.cpp
@@ -521,6 +521,14 @@ TEST_F(IRBuilderTest, DataLayout) {
EXPECT_FALSE(M->getDataLayout().isLegalInteger(32));
}
+TEST_F(IRBuilderTest, GetByteTy) {
+ IRBuilder<> Builder(BB);
+
+ EXPECT_TRUE(Builder.getByteTy()->isIntegerTy(8));
+ M->setDataLayout("b:32");
+ EXPECT_TRUE(Builder.getByteTy()->isIntegerTy(32));
+}
+
TEST_F(IRBuilderTest, GetIntTy) {
IRBuilder<> Builder(BB);
IntegerType *Ty1 = Builder.getInt1Ty();
@@ -532,6 +540,20 @@ TEST_F(IRBuilderTest, GetIntTy) {
EXPECT_EQ(IntPtrTy, IntegerType::get(Ctx, IntPtrBitSize));
}
+TEST_F(IRBuilderTest, CreatePtrAdd) {
+ IRBuilder<> Builder(BB);
+
+ M->setDataLayout("b:16-p:32:32");
+ Value *V = Builder.CreatePtrAdd(GV, ConstantInt::get(Ctx, APInt(32, 42)));
+ ASSERT_TRUE(isa(V));
+ EXPECT_TRUE(cast(V)->getResultElementType()->isIntegerTy(16));
+
+ M->setDataLayout("b:32-p:64:32");
+ V = Builder.CreateInBoundsPtrAdd(GV, ConstantInt::get(Ctx, APInt(64, 42)));
+ ASSERT_TRUE(isa(V));
+ EXPECT_TRUE(cast(V)->getResultElementType()->isIntegerTy(32));
+}
+
TEST_F(IRBuilderTest, UnaryOperators) {
IRBuilder Builder(BB);
Value *V = Builder.CreateLoad(GV->getValueType(), GV);
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [ValueTracking] Make isBytewiseValue byte width agnostic (PR #106538)
https://github.com/s-barannikov updated
https://github.com/llvm/llvm-project/pull/106538
>From c5eb6f75da616f6bb8d025ec07a884cd6c186082 Mon Sep 17 00:00:00 2001
From: Sergei Barannikov
Date: Fri, 2 Aug 2024 13:14:49 +0300
Subject: [PATCH] [ValueTracking] Make isBytewiseValue byte width agnostic
This is a simple change to show how easy it can be to support unusual
byte widths in the middle end.
---
llvm/lib/Analysis/ValueTracking.cpp | 30 +++--
1 file changed, 16 insertions(+), 14 deletions(-)
diff --git a/llvm/lib/Analysis/ValueTracking.cpp
b/llvm/lib/Analysis/ValueTracking.cpp
index 41ff816a33262..5d17034b6c93e 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -6260,21 +6260,22 @@ bool llvm::canIgnoreSignBitOfNaN(const Use &U) {
}
Value *llvm::isBytewiseValue(Value *V, const DataLayout &DL) {
+ unsigned ByteWidth = DL.getByteWidth();
// All byte-wide stores are splatable, even of arbitrary variables.
- if (V->getType()->isIntegerTy(8))
+ if (V->getType()->isIntegerTy(ByteWidth))
return V;
LLVMContext &Ctx = V->getContext();
// Undef don't care.
- auto *UndefInt8 = UndefValue::get(Type::getInt8Ty(Ctx));
+ auto *UndefByte = UndefValue::get(Type::getIntNTy(Ctx, ByteWidth));
if (isa(V))
-return UndefInt8;
+return UndefByte;
// Return poison for zero-sized type.
if (DL.getTypeStoreSize(V->getType()).isZero())
-return PoisonValue::get(Type::getInt8Ty(Ctx));
+return PoisonValue::get(Type::getIntNTy(Ctx, ByteWidth));
Constant *C = dyn_cast(V);
if (!C) {
@@ -6289,7 +6290,7 @@ Value *llvm::isBytewiseValue(Value *V, const DataLayout
&DL) {
// Handle 'null' ConstantArrayZero etc.
if (C->isNullValue())
-return Constant::getNullValue(Type::getInt8Ty(Ctx));
+return Constant::getNullValue(Type::getIntNTy(Ctx, ByteWidth));
// Constant floating-point values can be handled as integer values if the
// corresponding integer value is "byteable". An important case is 0.0.
@@ -6306,13 +6307,14 @@ Value *llvm::isBytewiseValue(Value *V, const DataLayout
&DL) {
: nullptr;
}
- // We can handle constant integers that are multiple of 8 bits.
+ // We can handle constant integers that are multiple of the byte width.
if (ConstantInt *CI = dyn_cast(C)) {
-if (CI->getBitWidth() % 8 == 0) {
- assert(CI->getBitWidth() > 8 && "8 bits should be handled above!");
- if (!CI->getValue().isSplat(8))
+if (CI->getBitWidth() % ByteWidth == 0) {
+ assert(CI->getBitWidth() > ByteWidth &&
+ "single byte should be handled above!");
+ if (!CI->getValue().isSplat(ByteWidth))
return nullptr;
- return ConstantInt::get(Ctx, CI->getValue().trunc(8));
+ return ConstantInt::get(Ctx, CI->getValue().trunc(ByteWidth));
}
}
@@ -6332,15 +6334,15 @@ Value *llvm::isBytewiseValue(Value *V, const DataLayout
&DL) {
return LHS;
if (!LHS || !RHS)
return nullptr;
-if (LHS == UndefInt8)
+if (LHS == UndefByte)
return RHS;
-if (RHS == UndefInt8)
+if (RHS == UndefByte)
return LHS;
return nullptr;
};
if (ConstantDataSequential *CA = dyn_cast(C)) {
-Value *Val = UndefInt8;
+Value *Val = UndefByte;
for (uint64_t I = 0, E = CA->getNumElements(); I != E; ++I)
if (!(Val = Merge(Val, isBytewiseValue(CA->getElementAsConstant(I),
DL
return nullptr;
@@ -6348,7 +6350,7 @@ Value *llvm::isBytewiseValue(Value *V, const DataLayout
&DL) {
}
if (isa(C)) {
-Value *Val = UndefInt8;
+Value *Val = UndefByte;
for (Value *Op : C->operands())
if (!(Val = Merge(Val, isBytewiseValue(Op, DL
return nullptr;
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [llvm] [ValueTracking] Add CharWidth argument to getConstantStringInfo (NFC) (PR #106541)
https://github.com/s-barannikov updated
https://github.com/llvm/llvm-project/pull/106541
>From 0d66f010d7d2f1a91a41a1db311480efde023dc3 Mon Sep 17 00:00:00 2001
From: Sergei Barannikov
Date: Wed, 28 Aug 2024 23:51:13 +0300
Subject: [PATCH] [ValueTracking] Add CharWidth argument to
getConstantStringInfo (NFC)
The method assumes that host chars and target chars have the same width.
Add a CharWidth argument so that it can bail out if the requested char
width differs from the host char width.
Alternatively, the check could be done at call sites, but this is more
error-prone.
In the future, this method will be replaced with a different one that
allows host/target chars to have different widths. The prototype will
be the same except that StringRef is replaced with something that is
byte width agnostic. Adding CharWidth argument now reduces the future
diff.
---
clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp | 4 +-
llvm/include/llvm/Analysis/ValueTracking.h| 2 +-
llvm/lib/Analysis/ValueTracking.cpp | 7 +-
.../AMDGPU/AMDGPUPrintfRuntimeBinding.cpp | 4 +-
llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp | 2 +-
.../Target/SPIRV/SPIRVPrepareFunctions.cpp| 2 +-
.../WebAssembly/WebAssemblyAsmPrinter.cpp | 2 +-
.../AggressiveInstCombine.cpp | 12 +-
.../lib/Transforms/Utils/AMDGPUEmitPrintf.cpp | 4 +-
.../lib/Transforms/Utils/SimplifyLibCalls.cpp | 103 --
10 files changed, 96 insertions(+), 46 deletions(-)
diff --git a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
index 9eab70955b6b9..075ffa0117aae 100644
--- a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
@@ -306,7 +306,7 @@ void CodeGenFunction::ProcessOrderScopeAMDGCN(Value *Order,
Value *Scope,
// Some of the atomic builtins take the scope as a string name.
StringRef scp;
- if (llvm::getConstantStringInfo(Scope, scp)) {
+ if (llvm::getConstantStringInfo(Scope, scp, /*CharWidth=*/8)) {
if (getTarget().getTriple().isSPIRV())
scp = mapScopeToSPIRV(scp);
SSID = getLLVMContext().getOrInsertSyncScopeID(scp);
@@ -369,7 +369,7 @@ void
CodeGenFunction::AddAMDGPUFenceAddressSpaceMMRA(llvm::Instruction *Inst,
for (unsigned K = 2; K < E->getNumArgs(); ++K) {
llvm::Value *V = EmitScalarExpr(E->getArg(K));
StringRef AS;
-if (llvm::getConstantStringInfo(V, AS)) {
+if (llvm::getConstantStringInfo(V, AS, /*CharWidth=*/8)) {
MMRAs.push_back({Tag, AS});
// TODO: Delete the resulting unused constant?
continue;
diff --git a/llvm/include/llvm/Analysis/ValueTracking.h
b/llvm/include/llvm/Analysis/ValueTracking.h
index 093309cb8bbee..36ebc8f8d7fb5 100644
--- a/llvm/include/llvm/Analysis/ValueTracking.h
+++ b/llvm/include/llvm/Analysis/ValueTracking.h
@@ -399,7 +399,7 @@ LLVM_ABI bool getConstantDataArrayInfo(const Value *V,
/// trailing null characters as well as any other characters that come after
/// it.
LLVM_ABI bool getConstantStringInfo(const Value *V, StringRef &Str,
-bool TrimAtNul = true);
+unsigned CharWidth, bool TrimAtNul = true);
/// If we can compute the length of the string pointed to by the specified
/// pointer, return 'len+1'. If we can't, return 0.
diff --git a/llvm/lib/Analysis/ValueTracking.cpp
b/llvm/lib/Analysis/ValueTracking.cpp
index 5d17034b6c93e..7363d060bdba7 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -6628,9 +6628,12 @@ bool llvm::getConstantDataArrayInfo(const Value *V,
/// return true. When TrimAtNul is set, Str will contain only the bytes up
/// to but not including the first nul. Return false on failure.
bool llvm::getConstantStringInfo(const Value *V, StringRef &Str,
- bool TrimAtNul) {
+ unsigned CharWidth, bool TrimAtNul) {
+ if (CharWidth != CHAR_BIT)
+return false;
+
ConstantDataArraySlice Slice;
- if (!getConstantDataArrayInfo(V, Slice, 8))
+ if (!getConstantDataArrayInfo(V, Slice, CharWidth))
return false;
if (Slice.Array == nullptr) {
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
b/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
index f5e14c71b02d9..a5b9d51d488c2 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
@@ -121,7 +121,7 @@ static_assert(NonLiteralStr.size() == 3);
static StringRef getAsConstantStr(Value *V) {
StringRef S;
- if (!getConstantStringInfo(V, S))
+ if (!getConstantStringInfo(V, S, /*CharWidth=*/8))
S = NonLiteralStr;
return S;
@@ -154,7 +154,7 @@ bool
AMDGPUPrintfRuntimeBindingImpl::lowerPrintfForGpu(Module &M) {
Value *Op = CI->getArgOperand(0);
StringRef FormatStr;
-if (!getConstantStringInfo(Op, FormatStr)) {
+if (!getC
[llvm-branch-commits] [llvm] [mlir] [IR] Make @llvm.memset prototype byte width dependent (PR #106537)
https://github.com/s-barannikov updated
https://github.com/llvm/llvm-project/pull/106537
>From 5332872212e1b2a846e42a7b70012beb7e2339f0 Mon Sep 17 00:00:00 2001
From: Sergei Barannikov
Date: Thu, 1 Aug 2024 23:47:25 +0300
Subject: [PATCH] [IR] Make @llvm.memset prototype byte width dependent
This patch changes the type of the value argument of @llvm.memset and
similar intrinsics from i8 to iN, where N is the byte width specified
in data layout string.
Note that the argument still has fixed type (not overloaded), but type
checker will complain if the type does not match the byte width.
Ideally, the type of the argument would be dependent on the address
space of the pointer argument. It is easy to do this (and I did it
downstream as a PoC), but since data layout string doesn't currently
allow different byte widths for different address spaces, I refrained
from doing it now.
---
llvm/include/llvm-c/Core.h| 2 +-
llvm/include/llvm/IR/Intrinsics.h | 13 ++--
llvm/include/llvm/IR/Intrinsics.td| 13 ++--
llvm/lib/AsmParser/LLParser.cpp | 4 +-
llvm/lib/IR/AutoUpgrade.cpp | 4 +-
llvm/lib/IR/Core.cpp | 4 +-
llvm/lib/IR/Function.cpp | 4 +-
llvm/lib/IR/IRBuilder.cpp | 2 +-
llvm/lib/IR/Intrinsics.cpp| 61 +++
llvm/lib/IR/Verifier.cpp | 2 +-
llvm/lib/Target/AMDGPU/SIISelLowering.cpp | 3 +-
.../NumericalStabilitySanitizer.cpp | 2 +-
.../LLVMIR/LLVMToLLVMIRTranslation.cpp| 4 +-
13 files changed, 71 insertions(+), 47 deletions(-)
diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h
index 4e380d9bd5969..56ac4ed6c1ec2 100644
--- a/llvm/include/llvm-c/Core.h
+++ b/llvm/include/llvm-c/Core.h
@@ -2963,7 +2963,7 @@ LLVM_C_ABI LLVMValueRef
LLVMGetIntrinsicDeclaration(LLVMModuleRef Mod,
*
* @see llvm::Intrinsic::getType()
*/
-LLVM_C_ABI LLVMTypeRef LLVMIntrinsicGetType(LLVMContextRef Ctx, unsigned ID,
+LLVM_C_ABI LLVMTypeRef LLVMIntrinsicGetType(LLVMModuleRef Mod, unsigned ID,
LLVMTypeRef *ParamTypes,
size_t ParamCount);
diff --git a/llvm/include/llvm/IR/Intrinsics.h
b/llvm/include/llvm/IR/Intrinsics.h
index 9577d0141f168..39a888b83ac14 100644
--- a/llvm/include/llvm/IR/Intrinsics.h
+++ b/llvm/include/llvm/IR/Intrinsics.h
@@ -23,6 +23,7 @@
namespace llvm {
+class DataLayout;
class Type;
class FunctionType;
class Function;
@@ -75,7 +76,7 @@ namespace Intrinsic {
LLVM_ABI std::string getNameNoUnnamedTypes(ID Id, ArrayRef Tys);
/// Return the function type for an intrinsic.
- LLVM_ABI FunctionType *getType(LLVMContext &Context, ID id,
+ LLVM_ABI FunctionType *getType(const Module *M, ID id,
ArrayRef Tys = {});
/// Returns true if the intrinsic can be overloaded.
@@ -135,6 +136,7 @@ namespace Intrinsic {
struct IITDescriptor {
enum IITDescriptorKind {
Void,
+ Byte,
VarArg,
MMX,
Token,
@@ -247,9 +249,9 @@ namespace Intrinsic {
///
/// Returns false if the given type matches with the constraints, true
/// otherwise.
- LLVM_ABI MatchIntrinsicTypesResult
- matchIntrinsicSignature(FunctionType *FTy, ArrayRef &Infos,
- SmallVectorImpl &ArgTys);
+ LLVM_ABI MatchIntrinsicTypesResult matchIntrinsicSignature(
+ const DataLayout &DL, FunctionType *FTy, ArrayRef &Infos,
+ SmallVectorImpl &ArgTys);
/// Verify if the intrinsic has variable arguments. This method is intended
to
/// be called after all the fixed arguments have been matched first.
@@ -264,7 +266,8 @@ namespace Intrinsic {
///
/// Returns false if the given ID and function type combination is not a
/// valid intrinsic call.
- LLVM_ABI bool getIntrinsicSignature(Intrinsic::ID, FunctionType *FT,
+ LLVM_ABI bool getIntrinsicSignature(const DataLayout &DL, Intrinsic::ID,
+ FunctionType *FT,
SmallVectorImpl &ArgTys);
/// Same as previous, but accepts a Function instead of ID and FunctionType.
diff --git a/llvm/include/llvm/IR/Intrinsics.td
b/llvm/include/llvm/IR/Intrinsics.td
index 07aa2faffa7c5..1f2a2a83ec932 100644
--- a/llvm/include/llvm/IR/Intrinsics.td
+++ b/llvm/include/llvm/IR/Intrinsics.td
@@ -334,6 +334,7 @@ def IIT_V6 : IIT_Vec<6, 50>;
def IIT_V10 : IIT_Vec<10, 51>;
def IIT_V2048 : IIT_Vec<2048, 52>;
def IIT_V4096 : IIT_Vec<4096, 53>;
+def IIT_BYTE : IIT_Base<54>;
}
defvar IIT_all_FixedTypes = !filter(iit, IIT_all,
@@ -376,6 +377,10 @@ class LLVMType {
!foreach(iit, IITs, iit.Number));
}
+class LLVMByteType : LLVMType {
+ let Sig = [IIT_BYTE.Number];
+}
+
class LLVMAnyType : LLVMType {
let ArgCode = !cond(
!eq(vt, Any) : ArgKind.Any,
@@ -481,7 +486,
[llvm-branch-commits] [llvm] [mlir] [IR] Make @llvm.memset prototype byte width dependent (PR #106537)
https://github.com/s-barannikov updated
https://github.com/llvm/llvm-project/pull/106537
>From 5332872212e1b2a846e42a7b70012beb7e2339f0 Mon Sep 17 00:00:00 2001
From: Sergei Barannikov
Date: Thu, 1 Aug 2024 23:47:25 +0300
Subject: [PATCH] [IR] Make @llvm.memset prototype byte width dependent
This patch changes the type of the value argument of @llvm.memset and
similar intrinsics from i8 to iN, where N is the byte width specified
in data layout string.
Note that the argument still has fixed type (not overloaded), but type
checker will complain if the type does not match the byte width.
Ideally, the type of the argument would be dependent on the address
space of the pointer argument. It is easy to do this (and I did it
downstream as a PoC), but since data layout string doesn't currently
allow different byte widths for different address spaces, I refrained
from doing it now.
---
llvm/include/llvm-c/Core.h| 2 +-
llvm/include/llvm/IR/Intrinsics.h | 13 ++--
llvm/include/llvm/IR/Intrinsics.td| 13 ++--
llvm/lib/AsmParser/LLParser.cpp | 4 +-
llvm/lib/IR/AutoUpgrade.cpp | 4 +-
llvm/lib/IR/Core.cpp | 4 +-
llvm/lib/IR/Function.cpp | 4 +-
llvm/lib/IR/IRBuilder.cpp | 2 +-
llvm/lib/IR/Intrinsics.cpp| 61 +++
llvm/lib/IR/Verifier.cpp | 2 +-
llvm/lib/Target/AMDGPU/SIISelLowering.cpp | 3 +-
.../NumericalStabilitySanitizer.cpp | 2 +-
.../LLVMIR/LLVMToLLVMIRTranslation.cpp| 4 +-
13 files changed, 71 insertions(+), 47 deletions(-)
diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h
index 4e380d9bd5969..56ac4ed6c1ec2 100644
--- a/llvm/include/llvm-c/Core.h
+++ b/llvm/include/llvm-c/Core.h
@@ -2963,7 +2963,7 @@ LLVM_C_ABI LLVMValueRef
LLVMGetIntrinsicDeclaration(LLVMModuleRef Mod,
*
* @see llvm::Intrinsic::getType()
*/
-LLVM_C_ABI LLVMTypeRef LLVMIntrinsicGetType(LLVMContextRef Ctx, unsigned ID,
+LLVM_C_ABI LLVMTypeRef LLVMIntrinsicGetType(LLVMModuleRef Mod, unsigned ID,
LLVMTypeRef *ParamTypes,
size_t ParamCount);
diff --git a/llvm/include/llvm/IR/Intrinsics.h
b/llvm/include/llvm/IR/Intrinsics.h
index 9577d0141f168..39a888b83ac14 100644
--- a/llvm/include/llvm/IR/Intrinsics.h
+++ b/llvm/include/llvm/IR/Intrinsics.h
@@ -23,6 +23,7 @@
namespace llvm {
+class DataLayout;
class Type;
class FunctionType;
class Function;
@@ -75,7 +76,7 @@ namespace Intrinsic {
LLVM_ABI std::string getNameNoUnnamedTypes(ID Id, ArrayRef Tys);
/// Return the function type for an intrinsic.
- LLVM_ABI FunctionType *getType(LLVMContext &Context, ID id,
+ LLVM_ABI FunctionType *getType(const Module *M, ID id,
ArrayRef Tys = {});
/// Returns true if the intrinsic can be overloaded.
@@ -135,6 +136,7 @@ namespace Intrinsic {
struct IITDescriptor {
enum IITDescriptorKind {
Void,
+ Byte,
VarArg,
MMX,
Token,
@@ -247,9 +249,9 @@ namespace Intrinsic {
///
/// Returns false if the given type matches with the constraints, true
/// otherwise.
- LLVM_ABI MatchIntrinsicTypesResult
- matchIntrinsicSignature(FunctionType *FTy, ArrayRef &Infos,
- SmallVectorImpl &ArgTys);
+ LLVM_ABI MatchIntrinsicTypesResult matchIntrinsicSignature(
+ const DataLayout &DL, FunctionType *FTy, ArrayRef &Infos,
+ SmallVectorImpl &ArgTys);
/// Verify if the intrinsic has variable arguments. This method is intended
to
/// be called after all the fixed arguments have been matched first.
@@ -264,7 +266,8 @@ namespace Intrinsic {
///
/// Returns false if the given ID and function type combination is not a
/// valid intrinsic call.
- LLVM_ABI bool getIntrinsicSignature(Intrinsic::ID, FunctionType *FT,
+ LLVM_ABI bool getIntrinsicSignature(const DataLayout &DL, Intrinsic::ID,
+ FunctionType *FT,
SmallVectorImpl &ArgTys);
/// Same as previous, but accepts a Function instead of ID and FunctionType.
diff --git a/llvm/include/llvm/IR/Intrinsics.td
b/llvm/include/llvm/IR/Intrinsics.td
index 07aa2faffa7c5..1f2a2a83ec932 100644
--- a/llvm/include/llvm/IR/Intrinsics.td
+++ b/llvm/include/llvm/IR/Intrinsics.td
@@ -334,6 +334,7 @@ def IIT_V6 : IIT_Vec<6, 50>;
def IIT_V10 : IIT_Vec<10, 51>;
def IIT_V2048 : IIT_Vec<2048, 52>;
def IIT_V4096 : IIT_Vec<4096, 53>;
+def IIT_BYTE : IIT_Base<54>;
}
defvar IIT_all_FixedTypes = !filter(iit, IIT_all,
@@ -376,6 +377,10 @@ class LLVMType {
!foreach(iit, IITs, iit.Number));
}
+class LLVMByteType : LLVMType {
+ let Sig = [IIT_BYTE.Number];
+}
+
class LLVMAnyType : LLVMType {
let ArgCode = !cond(
!eq(vt, Any) : ArgKind.Any,
@@ -481,7 +486,
[llvm-branch-commits] [llvm] DAG: Move expandMultipleResultFPLibCall to TargetLowering (NFC) (PR #166988)
https://github.com/MacDue approved this pull request. https://github.com/llvm/llvm-project/pull/166988 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] RuntimeLibcalls: Add a few libm entries from TargetLibraryInfo (PR #167049)
https://github.com/RKSimon approved this pull request. https://github.com/llvm/llvm-project/pull/167049 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
