[llvm-branch-commits] [llvm] release/20.x: [workflows] Add missing -y option to apt-get for abi tests (#133337) (PR #133813)
llvmbot wrote: @llvm/pr-subscribers-github-workflow Author: None (llvmbot) Changes Backport 7793bae97d2bad36d870c6df438a6fc034f15112 Requested by: @tstellar --- Full diff: https://github.com/llvm/llvm-project/pull/133813.diff 2 Files Affected: - (modified) .github/workflows/libclang-abi-tests.yml (+2-2) - (modified) .github/workflows/llvm-tests.yml (+2-2) ``diff diff --git a/.github/workflows/libclang-abi-tests.yml b/.github/workflows/libclang-abi-tests.yml index ff8f38b43098e..65cffccff776f 100644 --- a/.github/workflows/libclang-abi-tests.yml +++ b/.github/workflows/libclang-abi-tests.yml @@ -104,7 +104,7 @@ jobs: - name: Install abi-compliance-checker run: | sudo apt-get update - sudo apt-get install abi-dumper autoconf pkg-config + sudo apt-get install -y abi-dumper autoconf pkg-config - name: Install universal-ctags run: | git clone https://github.com/universal-ctags/ctags.git @@ -157,7 +157,7 @@ jobs: - name: Install abi-compliance-checker run: | sudo apt-get update - sudo apt-get install abi-compliance-checker + sudo apt-get install -y abi-compliance-checker - name: Compare ABI run: | for lib in ${{ needs.abi-dump-setup.outputs.ABI_LIBS }}; do diff --git a/.github/workflows/llvm-tests.yml b/.github/workflows/llvm-tests.yml index 92debf2a8a269..e2ca2ff44890e 100644 --- a/.github/workflows/llvm-tests.yml +++ b/.github/workflows/llvm-tests.yml @@ -92,7 +92,7 @@ jobs: - name: Install abi-compliance-checker run: | sudo apt-get update - sudo apt-get install abi-dumper autoconf pkg-config + sudo apt-get -y install abi-dumper autoconf pkg-config - name: Install universal-ctags run: | git clone https://github.com/universal-ctags/ctags.git @@ -166,7 +166,7 @@ jobs: - name: Install abi-compliance-checker run: | sudo apt-get update - sudo apt-get install abi-compliance-checker + sudo apt-get -y install abi-compliance-checker - name: Compare ABI run: | if [ -s symbol-list/llvm.symbols ]; then `` https://github.com/llvm/llvm-project/pull/133813 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] [Sanitizers][Darwin][Test] XFAIL malloc_zone.cpp (PR #133832)
llvmbot wrote: @llvm/pr-subscribers-compiler-rt-sanitizer Author: Mariusz Borsa (wrotki) Changes The malloc_zone.cpp test currently fails on Darwin hosts, in SanitizerCommon tests with lsan enabled. Need to XFAIL this test to buy time to investigate this failure. Also we're trying to bring the number of test failing on Darwin bots to 0, to get clearer signal of any new failures. rdar://145873843 Co-authored-by: Mariusz Borsa(cherry picked from commit 02837acaaf2cfdfcbf77e4a7f6629575edb6ffb4) --- Full diff: https://github.com/llvm/llvm-project/pull/133832.diff 1 Files Affected: - (modified) compiler-rt/test/sanitizer_common/TestCases/Darwin/malloc_zone.cpp (+2) ``diff diff --git a/compiler-rt/test/sanitizer_common/TestCases/Darwin/malloc_zone.cpp b/compiler-rt/test/sanitizer_common/TestCases/Darwin/malloc_zone.cpp index fd6ef03629438..5aa087fb4ca12 100644 --- a/compiler-rt/test/sanitizer_common/TestCases/Darwin/malloc_zone.cpp +++ b/compiler-rt/test/sanitizer_common/TestCases/Darwin/malloc_zone.cpp @@ -17,6 +17,8 @@ // UBSan does not install a malloc zone. // XFAIL: ubsan // +// Currently fails on darwin/lsan +// XFAIL: darwin && lsan #include #include `` https://github.com/llvm/llvm-project/pull/133832 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [LV] Reduce register usage for scaled reductions (PR #133090)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff 5f81501485b6c9d3e6a35fd382e1c10634e9658c b11c7631712479056bfd588c5031c065a53466fc --extensions h,cpp -- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h llvm/lib/Transforms/Vectorize/VPlan.h `` View the diff from clang-format here. ``diff diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 8b17622538..101ce4a8ab 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -5033,7 +5033,8 @@ calculateRegisterUsage(VPlan &Plan, ArrayRef VFs, VF = VF.divideCoefficientBy(ReductionR->getVFScaleFactor()); else if (auto *PartialReductionR = dyn_cast(R)) - VF = VF.divideCoefficientBy(PartialReductionR->getVFScaleFactor()); + VF = + VF.divideCoefficientBy(PartialReductionR->getVFScaleFactor()); LLVM_DEBUG(if (VF != VFs[J]) { dbgs() << "LV(REG): Scaled down VF from " << VFs[J] << " to " << VF << " for "; `` https://github.com/llvm/llvm-project/pull/133090 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/20.x: [workflows] Add missing -y option to apt-get for abi tests (#133337) (PR #133813)
https://github.com/llvmbot milestoned https://github.com/llvm/llvm-project/pull/133813 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] Backport/20.x: [LoongArch] Fix the type of tls-le symbols (PR #133027)
zhaoqi5 wrote: > > LGTM. > > Note: test/CodeGen is probably not the best place for such tests. > > `test/MC/CSKY/relocation-specifier.s` contains a nice example and tests > > multiple relocations at the same time. > > Will this be fixed in the main branch? Thanks. I have open a new PR (https://github.com/llvm/llvm-project/pull/133839) to fix this in the main branch. Do you think we should merge this PR and then cherry-pick the new PR, or simply add the modifications of the new PR to this PR? https://github.com/llvm/llvm-project/pull/133027 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] llvm-reduce: Fix introducing unreachable code in simplify conditionals (PR #133842)
https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/133842 After replacing the branch condition, this was calling simplifyCFG to perform the cleanups of the branch. This is far too heavy of a hammer. We do not want all of the extra optimizations in simplifyCFG, and this could also leave behind dead code. Instead, minimally fold the terminator and try to delete the newly dead code. This is pretty much a direct copy of what bugpoint does. >From 80eec0683d3659d470ef88206ac25c47c7af1e01 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Mon, 31 Mar 2025 22:25:09 +0700 Subject: [PATCH] llvm-reduce: Fix introducing unreachable code in simplify conditionals After replacing the branch condition, this was calling simplifyCFG to perform the cleanups of the branch. This is far too heavy of a hammer. We do not want all of the extra optimizations in simplifyCFG, and this could also leave behind dead code. Instead, minimally fold the terminator and try to delete the newly dead code. This is pretty much a direct copy of what bugpoint does. --- .../tools/llvm-reduce/reduce-conditionals.ll | 132 -- .../deltas/ReduceUsingSimplifyCFG.cpp | 19 ++- llvm/tools/llvm-reduce/deltas/Utils.cpp | 39 ++ llvm/tools/llvm-reduce/deltas/Utils.h | 6 + 4 files changed, 182 insertions(+), 14 deletions(-) diff --git a/llvm/test/tools/llvm-reduce/reduce-conditionals.ll b/llvm/test/tools/llvm-reduce/reduce-conditionals.ll index a832673d7350b..e1a9f3ae13944 100644 --- a/llvm/test/tools/llvm-reduce/reduce-conditionals.ll +++ b/llvm/test/tools/llvm-reduce/reduce-conditionals.ll @@ -1,10 +1,12 @@ -; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=simplify-conditionals-true --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t -; RUN: FileCheck --check-prefixes=RESULT-TRUE %s < %t +; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=simplify-conditionals-true --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS,CHECK --test-arg %s --test-arg --input-file %s -o %t +; RUN: FileCheck --check-prefixes=RESULT-TRUE,RESULT,CHECK %s < %t -; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=simplify-conditionals-false --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t -; RUN: FileCheck --check-prefixes=RESULT-FALSE %s < %t +; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=simplify-conditionals-false --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS,CHECK --test-arg %s --test-arg --input-file %s -o %t +; RUN: FileCheck --check-prefixes=RESULT-FALSE,RESULT,CHECK %s < %t -; CHECK-INTERESTINGNESS-LABEL: @func( +; Make sure there is no unreachable code introduced by the reduction + +; CHECK-LABEL: @func_simplifies_true( ; CHECK-INTERESTINGNESS: store i32 1, ; RESULT-TRUE: bb0: @@ -13,15 +15,98 @@ ; RESULT-TRUE-NEXT: br label %bb2 ; RESULT-TRUE-NOT: bb1 +; RESULT-FALSE: bb0: +; RESULT-FALSE-NEXT: store i32 0, ptr null, align 4 +; RESULT-FALSE-NEXT: br i1 %cond0, label %bb1, label %bb2 + +; RESULT-FALSE: bb1: ; preds = %bb0 +; RESULT-FALSE-NEXT: store i32 1, ptr null, align 4 +; RESULT-FALSE-NEXT: br label %bb3 + +; RESULT-FALSE: bb2: ; preds = %bb0 +; RESULT-FALSE-NEXT: store i32 2, ptr null, align 4 +; RESULT-FALSE-NEXT: br label %bb3 + +; RESULT-FALSE: bb3: ; preds = %bb1, %bb2 +; RESULT-FALSE-NEXT: ret void +define void @func_simplifies_true(i1 %cond0, i1 %cond1) { +bb0: + store i32 0, ptr null + br i1 %cond0, label %bb1, label %bb2 + +bb1: + store i32 1, ptr null + br i1 %cond1, label %bb2, label %bb3 + +bb2: + store i32 2, ptr null + br label %bb3 + +bb3: + ret void +} + +; CHECK-LABEL: @func_simplifies_false( +; CHECK-INTERESTINGNESS: store i32 0, + +; RESULT-TRUE: bb0: +; RESULT-TRUE: store i32 0, ptr null, align 4 +; RESULT-TRUE-NEXT: store i32 1, ptr null, align 4 +; RESULT-TRUE-NEXT: br label %bb2 +; RESULT-TRUE-NOT: bb1 + ; RESULT-FALSE: bb0: ; RESULT-FALSE: store i32 0, ptr null, align 4 ; RESULT-FALSE-NEXT: br label %bb2 -; RESULT-FALSE: bb1: ; No predecessors! -; RESULT-FALSE-NEXT: store i32 1, ptr null, align 4 +; RESULT-FALSE: bb2: ; preds = %bb0 +; RESULT-FALSE-NEXT: store i32 2, ptr null, align 4 ; RESULT-FALSE-NEXT: br label %bb3 -define void @func(i1 %cond0, i1 %cond1) { + +; RESULT-FALSE: bb3: ; preds = %bb2 +; RESULT-FALSE-NEXT: ret void +define void @func_simplifies_false(i1 %cond0, i1 %cond1) { +bb0: + store i32 0, ptr null + br i1 %cond0, label %bb1, label %bb2 + +bb1: + store i32 1, ptr null + br i1 %cond1, label %bb2, label %bb3 + +bb2: + store i32 2, ptr null + br label %bb3 + +bb3: + ret void +} + +; Make sure we don't break the reduction in the other functions by +; ha
[llvm-branch-commits] [clang] [clang-tools-extra] [libcxx] [clang] improved preservation of template keyword (PR #133610)
https://github.com/zyn0217 approved this pull request. Thanks for the improvement. https://github.com/llvm/llvm-project/pull/133610 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [clang-tools-extra] [libcxx] [clang] improved preservation of template keyword (PR #133610)
@@ -544,6 +545,35 @@ class QualifiedTemplateName : public llvm::FoldingSetNode { } }; +struct IdentifierOrOverloadedOperator { + IdentifierOrOverloadedOperator() = default; + IdentifierOrOverloadedOperator(const IdentifierInfo *II); + IdentifierOrOverloadedOperator(OverloadedOperatorKind OOK); + + /// Returns the identifier to which this template name refers. + const IdentifierInfo *getIdentifier() const { +if (getOperator() != OO_None) + return nullptr; +return reinterpret_cast(PtrOrOp); + } + + /// Return the overloaded operator to which this template name refers. + OverloadedOperatorKind getOperator() const { +uintptr_t OOK = -PtrOrOp; +return OOK < NUM_OVERLOADED_OPERATORS ? OverloadedOperatorKind(OOK) + : OO_None; zyn0217 wrote: IIRC this pointer/integer mechanism is also used in that lambda patch. We probably want to extract a generic implementation of it. https://github.com/llvm/llvm-project/pull/133610 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [clang-tools-extra] [libcxx] [clang] improved preservation of template keyword (PR #133610)
@@ -587,12 +587,12 @@ bool Parser::ParseOptionalCXXScopeSpecifier( << II.getName() << FixItHint::CreateInsertion(Tok.getLocation(), "template "); } - -SourceLocation TemplateNameLoc = ConsumeToken(); +ConsumeToken(); TemplateNameKind TNK = Actions.ActOnTemplateName( -getCurScope(), SS, TemplateNameLoc, TemplateName, ObjectType, -EnteringContext, Template, /*AllowInjectedClassName*/ true); +getCurScope(), SS, /*TemplateKWLoc=*/SourceLocation(), TemplateName, zyn0217 wrote: We don't want to track the `template` keyword's location following an NNS prefix anymore? Even that is never used, I think we need to mention the change in the release note. Or am I missing any code that would track the location instead? https://github.com/llvm/llvm-project/pull/133610 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [clang-tools-extra] [libcxx] [clang] improved preservation of template keyword (PR #133610)
@@ -124,6 +124,31 @@ void SubstTemplateTemplateParmPackStorage::Profile( ID.AddBoolean(Final); } +IdentifierOrOverloadedOperator::IdentifierOrOverloadedOperator( +const IdentifierInfo *II) +: PtrOrOp(reinterpret_cast(II)) { + static_assert(NUM_OVERLOADED_OPERATORS <= 4096, +"NUM_OVERLOADED_OPERATORS is too large"); zyn0217 wrote: How did you determine the upper limit? https://github.com/llvm/llvm-project/pull/133610 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/20.x: [TailDuplicator] Determine if computed gotos using `blockaddress` (#132536) (PR #133082)
tstellar wrote: This has some CI test faliures. https://github.com/llvm/llvm-project/pull/133082 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [mlir][LLVM] Delete `LLVMFixedVectorType` and `LLVMScalableVectorType` (PR #133286)
@@ -959,26 +862,12 @@ Type mlir::LLVM::getVectorType(Type elementType, } Type mlir::LLVM::getFixedVectorType(Type elementType, unsigned numElements) { Dinistro wrote: I guess that we can burn out these API's in a subsequent step? Maybe we should mark them as deprecated now? https://github.com/llvm/llvm-project/pull/133286 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] 068da73 - Revert "[Clang][Cmake] fix libtool duplicate member name warnings (#133619)"
Author: Farzon Lotfi Date: 2025-03-31T16:51:59-04:00 New Revision: 068da73e6dab35fdbd18c6b5c3ad1e0a9ed5a783 URL: https://github.com/llvm/llvm-project/commit/068da73e6dab35fdbd18c6b5c3ad1e0a9ed5a783 DIFF: https://github.com/llvm/llvm-project/commit/068da73e6dab35fdbd18c6b5c3ad1e0a9ed5a783.diff LOG: Revert "[Clang][Cmake] fix libtool duplicate member name warnings (#133619)" This reverts commit cc2b4326142e6df6755472edaf264a0af4fe599a. Added: Modified: clang/lib/CodeGen/CMakeLists.txt clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp Removed: clang/lib/CodeGen/TargetBuiltins/CMakeLists.txt clang/lib/CodeGen/Targets/CMakeLists.txt diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt index cdf9f909a3675..ebe2fbd7db295 100644 --- a/clang/lib/CodeGen/CMakeLists.txt +++ b/clang/lib/CodeGen/CMakeLists.txt @@ -116,8 +116,45 @@ add_clang_library(clangCodeGen PatternInit.cpp SanitizerMetadata.cpp SwiftCallingConv.cpp + TargetBuiltins/ARM.cpp + TargetBuiltins/AMDGPU.cpp + TargetBuiltins/Hexagon.cpp + TargetBuiltins/NVPTX.cpp + TargetBuiltins/PPC.cpp + TargetBuiltins/RISCV.cpp + TargetBuiltins/SPIR.cpp + TargetBuiltins/SystemZ.cpp + TargetBuiltins/WebAssembly.cpp + TargetBuiltins/X86.cpp TargetInfo.cpp + Targets/AArch64.cpp + Targets/AMDGPU.cpp + Targets/ARC.cpp + Targets/ARM.cpp + Targets/AVR.cpp + Targets/BPF.cpp + Targets/CSKY.cpp + Targets/DirectX.cpp + Targets/Hexagon.cpp + Targets/Lanai.cpp + Targets/LoongArch.cpp + Targets/M68k.cpp + Targets/MSP430.cpp + Targets/Mips.cpp + Targets/NVPTX.cpp + Targets/PNaCl.cpp + Targets/PPC.cpp + Targets/RISCV.cpp + Targets/SPIR.cpp + Targets/Sparc.cpp + Targets/SystemZ.cpp + Targets/TCE.cpp + Targets/VE.cpp + Targets/WebAssembly.cpp + Targets/X86.cpp + Targets/XCore.cpp VarBypassDetector.cpp + DEPENDS vt_gen intrinsics_gen @@ -133,16 +170,4 @@ add_clang_library(clangCodeGen clangFrontend clangLex clangSerialization - clangCodeGenTargetBuiltins - clangCodeGenTargets - ) - - target_include_directories(clangCodeGen -PUBLIC -${CMAKE_CURRENT_SOURCE_DIR} -${CMAKE_CURRENT_SOURCE_DIR}/TargetBuiltins -${CMAKE_CURRENT_SOURCE_DIR}/Targets ) - - add_subdirectory(TargetBuiltins) - add_subdirectory(Targets) diff --git a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp index 577fee05d4af6..b56b739094ff3 100644 --- a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp +++ b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp @@ -1,4 +1,4 @@ -//===--- AMDGPU.cpp - Emit LLVM Code for builtins -===// +//===--- AMDCPU.cpp - Emit LLVM Code for builtins -===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/clang/lib/CodeGen/TargetBuiltins/CMakeLists.txt b/clang/lib/CodeGen/TargetBuiltins/CMakeLists.txt deleted file mode 100644 index 8526c063b4593..0 --- a/clang/lib/CodeGen/TargetBuiltins/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..) - -add_clang_library(clangCodeGenTargetBuiltins STATIC - ARM.cpp - AMDGPU.cpp - Hexagon.cpp - NVPTX.cpp - PPC.cpp - RISCV.cpp - SPIR.cpp - SystemZ.cpp - WebAssembly.cpp - X86.cpp -) - -target_link_libraries(clangCodeGenTargetBuiltins - PRIVATE - clangCodeGen -) diff --git a/clang/lib/CodeGen/Targets/CMakeLists.txt b/clang/lib/CodeGen/Targets/CMakeLists.txt deleted file mode 100644 index fd79b6191b379..0 --- a/clang/lib/CodeGen/Targets/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..) - -add_clang_library(clangCodeGenTargets STATIC - AArch64.cpp - AMDGPU.cpp - ARC.cpp - ARM.cpp - AVR.cpp - BPF.cpp - CSKY.cpp - DirectX.cpp - Hexagon.cpp - Lanai.cpp - LoongArch.cpp - M68k.cpp - MSP430.cpp - Mips.cpp - NVPTX.cpp - PNaCl.cpp - PPC.cpp - RISCV.cpp - SPIR.cpp - Sparc.cpp - SystemZ.cpp - TCE.cpp - VE.cpp - WebAssembly.cpp - X86.cpp - XCore.cpp -) - -target_link_libraries(clangCodeGenTargets - PRIVATE - clangCodeGen -) ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)
https://github.com/redstar created https://github.com/llvm/llvm-project/pull/133799 The GOFF format uses symbol definitions to represent sections and symbols. Introducing a section can require up to 3 symbol definitions. However, most of these details are not needed by the AsmPrinter. To mapped from a section (a MCSectionGOFF) to the symbol definitions, a new class called MCGOFFSymbolMapper is used. The same information can also be used by the assembly output, which justifies this centralized approach. Writing the mapped symbols is then straight forward. >From 77c230f82a61769714bee98b2e848820850d9cb5 Mon Sep 17 00:00:00 2001 From: Kai Nacke Date: Mon, 24 Mar 2025 16:26:19 -0400 Subject: [PATCH] [GOFF] Add writing of section symbols The GOFF format uses symbol definitions to represent sections and symbols. Introducing a section can require up to 3 symbol definitions. However, most of these details are not needed by the AsmPrinter. To mapped from a section (a MCSectionGOFF) to the symbol definitions, a new class called MCGOFFSymbolMapper is used. The same information can also be used by the assembly output, which justifies this centralized approach. Writing the mapped symbols is then straight forward. --- llvm/include/llvm/BinaryFormat/GOFF.h | 85 +++ llvm/include/llvm/MC/MCGOFFSymbolMapper.h | 148 +++ llvm/lib/MC/CMakeLists.txt| 1 + llvm/lib/MC/GOFFObjectWriter.cpp | 290 +++--- llvm/lib/MC/MCGOFFSymbolMapper.cpp| 203 +++ llvm/lib/MC/MCObjectFileInfo.cpp | 2 +- llvm/test/CodeGen/SystemZ/zos-ppa2.ll | 2 +- llvm/test/MC/GOFF/section.ll | 73 ++ 8 files changed, 765 insertions(+), 39 deletions(-) create mode 100644 llvm/include/llvm/MC/MCGOFFSymbolMapper.h create mode 100644 llvm/lib/MC/MCGOFFSymbolMapper.cpp create mode 100644 llvm/test/MC/GOFF/section.ll diff --git a/llvm/include/llvm/BinaryFormat/GOFF.h b/llvm/include/llvm/BinaryFormat/GOFF.h index 443bcfc9479a8..43d80e0c247e9 100644 --- a/llvm/include/llvm/BinaryFormat/GOFF.h +++ b/llvm/include/llvm/BinaryFormat/GOFF.h @@ -169,6 +169,91 @@ enum SubsectionKind : uint8_t { SK_PPA1 = 2, SK_PPA2 = 4, }; + +// The standard System/390 convention is to name the high-order (leftmost) bit +// in a byte as bit zero. The Flags type helps to set bits in byte according +// to this numeration order. +class Flags { + uint8_t Val; + + constexpr static uint8_t bits(uint8_t BitIndex, uint8_t Length, uint8_t Value, +uint8_t OldValue) { +uint8_t Pos = 8 - BitIndex - Length; +uint8_t Mask = ((1 << Length) - 1) << Pos; +Value = Value << Pos; +return (OldValue & ~Mask) | Value; + } + +public: + constexpr Flags() : Val(0) {} + constexpr Flags(uint8_t BitIndex, uint8_t Length, uint8_t Value) + : Val(bits(BitIndex, Length, Value, 0)) {} + + template + constexpr void set(uint8_t BitIndex, uint8_t Length, T NewValue) { +Val = bits(BitIndex, Length, static_cast(NewValue), Val); + } + + template + constexpr T get(uint8_t BitIndex, uint8_t Length) const { +return static_cast((Val >> (8 - BitIndex - Length)) & + ((1 << Length) - 1)); + } + + constexpr operator uint8_t() const { return Val; } +}; + +// Structure for the flag field of a symbol. See +// https://www.ibm.com/docs/en/zos/3.1.0?topic=formats-external-symbol-definition-record, +// offset 41, for the definition. +struct SymbolFlags { + Flags SymFlags; + +#define GOFF_SYMBOL_FLAG(NAME, TYPE, BITINDEX, LENGTH) \ + void set##NAME(TYPE Val) { SymFlags.set(BITINDEX, LENGTH, Val); } \ + TYPE get##NAME() const { return SymFlags.get(BITINDEX, LENGTH); } + + GOFF_SYMBOL_FLAG(FillBytePresence, bool, 0, 1) + GOFF_SYMBOL_FLAG(Mangled, bool, 1, 1) + GOFF_SYMBOL_FLAG(Renameable, bool, 2, 1) + GOFF_SYMBOL_FLAG(RemovableClass, bool, 3, 1) + GOFF_SYMBOL_FLAG(ReservedQwords, ESDReserveQwords, 5, 3) + +#undef GOFF_SYMBOL_FLAG + +constexpr operator uint8_t() const { return static_cast(SymFlags); } +}; + +// Structure for the behavioral attributes. See +// https://www.ibm.com/docs/en/zos/3.1.0?topic=record-external-symbol-definition-behavioral-attributes +// for the definition. +struct BehavioralAttributes { + Flags Attr[10]; + +#define GOFF_BEHAVIORAL_ATTRIBUTE(NAME, TYPE, ATTRIDX, BITINDEX, LENGTH) \ + void set##NAME(TYPE Val) { Attr[ATTRIDX].set(BITINDEX, LENGTH, Val); } \ + TYPE get##NAME() const { return Attr[ATTRIDX].get(BITINDEX, LENGTH); } + + GOFF_BEHAVIORAL_ATTRIBUTE(Amode, GOFF::ESDAmode, 0, 0, 8) + GOFF_BEHAVIORAL_ATTRIBUTE(Rmode, GOFF::ESDRmode, 1, 0, 8) + GOFF_BEHAVIORAL_ATTRIBUTE(TextStyle, GOFF::ESDTextStyle, 2, 0, 4) + GOFF_BEHAVIORAL_ATTRIBUTE(BindingAlgorithm, GOFF::ESDBindingAlgorithm, 2, 4, +4) + GOFF_BEHAVIORAL_ATTRIBUTE(TaskingBehavior, GOFF::ESDTaskingBehavior, 3, 0, 3) + GOFF_BEHAVIORAL_ATTRIBUTE(Re
[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff 7810f30bb64b71e006ff7f0b16dff684ed63597b 77c230f82a61769714bee98b2e848820850d9cb5 --extensions cpp,h -- llvm/include/llvm/MC/MCGOFFSymbolMapper.h llvm/lib/MC/MCGOFFSymbolMapper.cpp llvm/include/llvm/BinaryFormat/GOFF.h llvm/lib/MC/GOFFObjectWriter.cpp llvm/lib/MC/MCObjectFileInfo.cpp `` View the diff from clang-format here. ``diff diff --git a/llvm/include/llvm/BinaryFormat/GOFF.h b/llvm/include/llvm/BinaryFormat/GOFF.h index 43d80e0c24..077a5a36df 100644 --- a/llvm/include/llvm/BinaryFormat/GOFF.h +++ b/llvm/include/llvm/BinaryFormat/GOFF.h @@ -221,7 +221,7 @@ struct SymbolFlags { #undef GOFF_SYMBOL_FLAG -constexpr operator uint8_t() const { return static_cast(SymFlags); } + constexpr operator uint8_t() const { return static_cast(SymFlags); } }; // Structure for the behavioral attributes. See `` https://github.com/llvm/llvm-project/pull/133799 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add infastructure to parse parameters (PR #133800)
https://github.com/inbelic created https://github.com/llvm/llvm-project/pull/133800 - defines `ParamType` as a way to represent a reference to some parameter in a root signature - defines `ParseParam` and `ParseParams` as an infastructure to define how the parameters of a given struct should be parsed in an orderless manner - implements parsing of two param types: `UInt32` and `Register` to demonstrate the parsing implementation and allow for unit testing Part two of implementing: https://github.com/llvm/llvm-project/issues/126569 >From 71ae66142abb2e6e43a60ce521dc638ec702399f Mon Sep 17 00:00:00 2001 From: Finn Plummer Date: Mon, 31 Mar 2025 18:29:26 + Subject: [PATCH 1/3] [HLSL][RootSignature] Add infastructure to parse parameters - defines `ParamType` as a way to represent a reference to some parameter in a root signature - defines `ParseParam` and `ParseParams` as an infastructure to define how the parameters of a given struct should be parsed in an orderless manner --- .../clang/Basic/DiagnosticParseKinds.td | 4 +- .../clang/Parse/ParseHLSLRootSignature.h | 32 clang/lib/Parse/ParseHLSLRootSignature.cpp| 51 +++ .../llvm/Frontend/HLSL/HLSLRootSignature.h| 6 +++ 4 files changed, 92 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index 2582e1e5ef0f6..f25c9c930cc61 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -1830,8 +1830,10 @@ def err_hlsl_virtual_function def err_hlsl_virtual_inheritance : Error<"virtual inheritance is unsupported in HLSL">; -// HLSL Root Siganture diagnostic messages +// HLSL Root Signature Parser Diagnostics def err_hlsl_unexpected_end_of_params : Error<"expected %0 to denote end of parameters, or, another valid parameter of %1">; +def err_hlsl_rootsig_repeat_param : Error<"specified the same parameter '%0' multiple times">; +def err_hlsl_rootsig_missing_param : Error<"did not specify mandatory parameter '%0'">; } // end of Parser diagnostics diff --git a/clang/include/clang/Parse/ParseHLSLRootSignature.h b/clang/include/clang/Parse/ParseHLSLRootSignature.h index 43b41315b88b5..b39267dbaaa28 100644 --- a/clang/include/clang/Parse/ParseHLSLRootSignature.h +++ b/clang/include/clang/Parse/ParseHLSLRootSignature.h @@ -69,6 +69,38 @@ class RootSignatureParser { bool parseDescriptorTable(); bool parseDescriptorTableClause(); + /// Each unique ParamType will have a custom parse method defined that we can + /// use to invoke the parameters. + /// + /// This function will switch on the ParamType using std::visit and dispatch + /// onto the corresponding parse method + bool parseParam(llvm::hlsl::rootsig::ParamType Ref); + + /// Parameter arguments (eg. `bReg`, `space`, ...) can be specified in any + /// order, exactly once, and only a subset are mandatory. This function acts + /// as the infastructure to do so in a declarative way. + /// + /// For the example: + /// SmallDenseMap Params = { + ///TokenKind::bReg, &Clause.Register, + ///TokenKind::kw_space, &Clause.Space + /// }; + /// SmallDenseSet Mandatory = { + ///TokenKind::kw_numDescriptors + /// }; + /// + /// We can read it is as: + /// + /// when 'b0' is encountered, invoke the parse method for the type + /// of &Clause.Register (Register *) and update the parameter + /// when 'space' is encountered, invoke a parse method for the type + /// of &Clause.Space (uint32_t *) and update the parameter + /// + /// and 'bReg' must be specified + bool parseParams( + llvm::SmallDenseMap &Params, + llvm::SmallDenseSet &Mandatory); + /// Invoke the Lexer to consume a token and update CurToken with the result void consumeNextToken() { CurToken = Lexer.ConsumeToken(); } diff --git a/clang/lib/Parse/ParseHLSLRootSignature.cpp b/clang/lib/Parse/ParseHLSLRootSignature.cpp index 33caca5fa1c82..8bb78def243fe 100644 --- a/clang/lib/Parse/ParseHLSLRootSignature.cpp +++ b/clang/lib/Parse/ParseHLSLRootSignature.cpp @@ -118,6 +118,57 @@ bool RootSignatureParser::parseDescriptorTableClause() { return false; } +// Helper struct so that we can use the overloaded notation of std::visit +template struct ParseMethods : Ts... { using Ts::operator()...; }; +template ParseMethods(Ts...) -> ParseMethods; + +bool RootSignatureParser::parseParam(ParamType Ref) { + bool Error = true; + std::visit(ParseMethods{}, Ref); + + return Error; +} + +bool RootSignatureParser::parseParams( +llvm::SmallDenseMap &Params, +llvm::SmallDenseSet &Mandatory) { + + // Initialize a vector of possible keywords + SmallVector Keywords; + for (auto Pair : Params) +Keywords.push_back(Pair.first); + + // Keep track of which keywords have been seen to report duplicates + llvm::SmallDenseSet Seen; + + while (tryConsumeExpectedToken(Keyw
[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add infastructure to parse parameters (PR #133800)
llvmbot wrote: @llvm/pr-subscribers-hlsl Author: Finn Plummer (inbelic) Changes - defines `ParamType` as a way to represent a reference to some parameter in a root signature - defines `ParseParam` and `ParseParams` as an infastructure to define how the parameters of a given struct should be parsed in an orderless manner - implements parsing of two param types: `UInt32` and `Register` to demonstrate the parsing implementation and allow for unit testing Part two of implementing: https://github.com/llvm/llvm-project/issues/126569 --- Full diff: https://github.com/llvm/llvm-project/pull/133800.diff 5 Files Affected: - (modified) clang/include/clang/Basic/DiagnosticParseKinds.td (+4-1) - (modified) clang/include/clang/Parse/ParseHLSLRootSignature.h (+40) - (modified) clang/lib/Parse/ParseHLSLRootSignature.cpp (+151-14) - (modified) clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp (+142-4) - (modified) llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h (+15) ``diff diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index 2582e1e5ef0f6..ab12159ba5ae1 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -1830,8 +1830,11 @@ def err_hlsl_virtual_function def err_hlsl_virtual_inheritance : Error<"virtual inheritance is unsupported in HLSL">; -// HLSL Root Siganture diagnostic messages +// HLSL Root Signature Parser Diagnostics def err_hlsl_unexpected_end_of_params : Error<"expected %0 to denote end of parameters, or, another valid parameter of %1">; +def err_hlsl_rootsig_repeat_param : Error<"specified the same parameter '%0' multiple times">; +def err_hlsl_rootsig_missing_param : Error<"did not specify mandatory parameter '%0'">; +def err_hlsl_number_literal_overflow : Error<"integer literal is too large to be represented as a 32-bit %select{signed |}0 integer type">; } // end of Parser diagnostics diff --git a/clang/include/clang/Parse/ParseHLSLRootSignature.h b/clang/include/clang/Parse/ParseHLSLRootSignature.h index 43b41315b88b5..02e99e83875db 100644 --- a/clang/include/clang/Parse/ParseHLSLRootSignature.h +++ b/clang/include/clang/Parse/ParseHLSLRootSignature.h @@ -69,6 +69,46 @@ class RootSignatureParser { bool parseDescriptorTable(); bool parseDescriptorTableClause(); + /// Each unique ParamType will have a custom parse method defined that we can + /// use to invoke the parameters. + /// + /// This function will switch on the ParamType using std::visit and dispatch + /// onto the corresponding parse method + bool parseParam(llvm::hlsl::rootsig::ParamType Ref); + + /// Parameter arguments (eg. `bReg`, `space`, ...) can be specified in any + /// order, exactly once, and only a subset are mandatory. This function acts + /// as the infastructure to do so in a declarative way. + /// + /// For the example: + /// SmallDenseMap Params = { + ///TokenKind::bReg, &Clause.Register, + ///TokenKind::kw_space, &Clause.Space + /// }; + /// SmallDenseSet Mandatory = { + ///TokenKind::kw_numDescriptors + /// }; + /// + /// We can read it is as: + /// + /// when 'b0' is encountered, invoke the parse method for the type + /// of &Clause.Register (Register *) and update the parameter + /// when 'space' is encountered, invoke a parse method for the type + /// of &Clause.Space (uint32_t *) and update the parameter + /// + /// and 'bReg' must be specified + bool parseParams( + llvm::SmallDenseMap &Params, + llvm::SmallDenseSet &Mandatory); + + /// Parameter parse methods corresponding to a ParamType + bool parseUIntParam(uint32_t *X); + bool parseRegister(llvm::hlsl::rootsig::Register *Reg); + + /// Use NumericLiteralParser to convert CurToken.NumSpelling into a unsigned + /// 32-bit integer + bool handleUIntLiteral(uint32_t *X); + /// Invoke the Lexer to consume a token and update CurToken with the result void consumeNextToken() { CurToken = Lexer.ConsumeToken(); } diff --git a/clang/lib/Parse/ParseHLSLRootSignature.cpp b/clang/lib/Parse/ParseHLSLRootSignature.cpp index 33caca5fa1c82..62d29baea49d3 100644 --- a/clang/lib/Parse/ParseHLSLRootSignature.cpp +++ b/clang/lib/Parse/ParseHLSLRootSignature.cpp @@ -8,6 +8,8 @@ #include "clang/Parse/ParseHLSLRootSignature.h" +#include "clang/Lex/LiteralSupport.h" + #include "llvm/Support/raw_ostream.h" using namespace llvm::hlsl::rootsig; @@ -39,12 +41,11 @@ bool RootSignatureParser::parse() { break; } - if (!tryConsumeExpectedToken(TokenKind::end_of_stream)) { -getDiags().Report(CurToken.TokLoc, diag::err_hlsl_unexpected_end_of_params) -<< /*expected=*/TokenKind::end_of_stream -<< /*param of=*/TokenKind::kw_RootSignature; + if (consumeExpectedToken(TokenKind::end_of_stream, + diag::err_hlsl_unexpected_end_of_params, + /*param of=*
[llvm-branch-commits] compiler-rt: Introduce runtime functions for emulated PAC. (PR #133530)
https://github.com/llvm-beanz requested changes to this pull request. We cannot introduce BSD-licensed code to compiler-rt. Please see [my comment for more details](https://github.com/llvm/llvm-project/pull/133530#discussion_r2021952691). https://github.com/llvm/llvm-project/pull/133530 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] [Sanitizers][Darwin][Test] XFAIL malloc_zone.cpp (PR #133832)
https://github.com/wrotki created https://github.com/llvm/llvm-project/pull/133832 The malloc_zone.cpp test currently fails on Darwin hosts, in SanitizerCommon tests with lsan enabled. Need to XFAIL this test to buy time to investigate this failure. Also we're trying to bring the number of test failing on Darwin bots to 0, to get clearer signal of any new failures. rdar://145873843 Co-authored-by: Mariusz Borsa (cherry picked from commit 02837acaaf2cfdfcbf77e4a7f6629575edb6ffb4) >From 3a1a3656305a7116b85156570bc5fb5d784f455d Mon Sep 17 00:00:00 2001 From: Mariusz Borsa Date: Mon, 31 Mar 2025 17:06:41 -0700 Subject: [PATCH] [Sanitizers][Darwin][Test] XFAIL malloc_zone.cpp The malloc_zone.cpp test currently fails on Darwin hosts, in SanitizerCommon tests with lsan enabled. Need to XFAIL this test to buy time to investigate this failure. Also we're trying to bring the number of test failing on Darwin bots to 0, to get clearer signal of any new failures. rdar://145873843 Co-authored-by: Mariusz Borsa (cherry picked from commit 02837acaaf2cfdfcbf77e4a7f6629575edb6ffb4) --- .../test/sanitizer_common/TestCases/Darwin/malloc_zone.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compiler-rt/test/sanitizer_common/TestCases/Darwin/malloc_zone.cpp b/compiler-rt/test/sanitizer_common/TestCases/Darwin/malloc_zone.cpp index fd6ef03629438..5aa087fb4ca12 100644 --- a/compiler-rt/test/sanitizer_common/TestCases/Darwin/malloc_zone.cpp +++ b/compiler-rt/test/sanitizer_common/TestCases/Darwin/malloc_zone.cpp @@ -17,6 +17,8 @@ // UBSan does not install a malloc zone. // XFAIL: ubsan // +// Currently fails on darwin/lsan +// XFAIL: darwin && lsan #include #include ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] llvm-reduce: Reduce global variable code model (PR #133865)
llvmbot wrote: @llvm/pr-subscribers-llvm-ir Author: Matt Arsenault (arsenm) Changes The current API doesn't have a way to unset it. The query returns an optional, but the set doesn't. Alternatively I could switch the set to also use optional. --- Full diff: https://github.com/llvm/llvm-project/pull/133865.diff 4 Files Affected: - (modified) llvm/include/llvm/IR/GlobalVariable.h (+4) - (modified) llvm/lib/IR/Globals.cpp (+9) - (added) llvm/test/tools/llvm-reduce/reduce-code-model.ll (+18) - (modified) llvm/tools/llvm-reduce/deltas/ReduceGlobalValues.cpp (+2-1) ``diff diff --git a/llvm/include/llvm/IR/GlobalVariable.h b/llvm/include/llvm/IR/GlobalVariable.h index 83e484816d7d4..5ea5d3b11cd9a 100644 --- a/llvm/include/llvm/IR/GlobalVariable.h +++ b/llvm/include/llvm/IR/GlobalVariable.h @@ -289,6 +289,10 @@ class GlobalVariable : public GlobalObject, public ilist_node { /// void setCodeModel(CodeModel::Model CM); + /// Remove the code model for this global. + /// + void clearCodeModel(); + // Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Value *V) { return V->getValueID() == Value::GlobalVariableVal; diff --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp index 8ca44719a3f94..401f8ac58bce8 100644 --- a/llvm/lib/IR/Globals.cpp +++ b/llvm/lib/IR/Globals.cpp @@ -557,6 +557,15 @@ void GlobalVariable::setCodeModel(CodeModel::Model CM) { assert(getCodeModel() == CM && "Code model representation error!"); } +void GlobalVariable::clearCodeModel() { + unsigned CodeModelData = 0; + unsigned OldData = getGlobalValueSubClassData(); + unsigned NewData = (OldData & ~(CodeModelMask << CodeModelShift)) | + (CodeModelData << CodeModelShift); + setGlobalValueSubClassData(NewData); + assert(getCodeModel() == std::nullopt && "Code model representation error!"); +} + //===--===// // GlobalAlias Implementation //===--===// diff --git a/llvm/test/tools/llvm-reduce/reduce-code-model.ll b/llvm/test/tools/llvm-reduce/reduce-code-model.ll new file mode 100644 index 0..898f5995d9826 --- /dev/null +++ b/llvm/test/tools/llvm-reduce/reduce-code-model.ll @@ -0,0 +1,18 @@ +; RUN: llvm-reduce -abort-on-invalid-reduction --delta-passes=global-values --test FileCheck --test-arg --check-prefix=INTERESTING --test-arg %s --test-arg --input-file %s -o %t.0 +; RUN: FileCheck --implicit-check-not=define --check-prefix=RESULT %s < %t.0 + +; INTERESTING: @code_model_large_keep = global i32 0, code_model "large", align 4 +; INTERESTING @code_model_large_drop = global i32 0 + +; RESULT: @code_model_large_keep = global i32 0, code_model "large", align 4{{$}} +; RESULT: @code_model_large_drop = global i32 0, align 4{{$}} +@code_model_large_keep = global i32 0, code_model "large", align 4 +@code_model_large_drop = global i32 0, code_model "large", align 4 + +; INTERESTING: @code_model_tiny_keep = global i32 0, code_model "tiny", align 4 +; INTERESTING @code_model_tiny_drop = global i32 0 + +; RESULT: @code_model_tiny_keep = global i32 0, code_model "tiny", align 4{{$}} +; RESULT: @code_model_tiny_drop = global i32 0, align 4{{$}} +@code_model_tiny_keep = global i32 0, code_model "tiny", align 4 +@code_model_tiny_drop = global i32 0, code_model "tiny", align 4 diff --git a/llvm/tools/llvm-reduce/deltas/ReduceGlobalValues.cpp b/llvm/tools/llvm-reduce/deltas/ReduceGlobalValues.cpp index e56876c38032e..659bf8dd23eff 100644 --- a/llvm/tools/llvm-reduce/deltas/ReduceGlobalValues.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceGlobalValues.cpp @@ -70,7 +70,8 @@ void llvm::reduceGlobalValuesDeltaPass(Oracle &O, ReducerWorkItem &Program) { if (GVar->isExternallyInitialized() && !O.shouldKeep()) GVar->setExternallyInitialized(false); - // TODO: Reduce code model + if (GVar->getCodeModel() && !O.shouldKeep()) +GVar->clearCodeModel(); } } } `` https://github.com/llvm/llvm-project/pull/133865 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [mlir][LLVM] Delete `LLVMFixedVectorType` and `LLVMScalableVectorType` (PR #133286)
@@ -911,41 +834,21 @@ llvm::ElementCount mlir::LLVM::getVectorNumElements(Type type) { return llvm::ElementCount::getScalable(ty.getNumElements()); Dinistro wrote: This `TypeSwitch` is also no longer too useful. https://github.com/llvm/llvm-project/pull/133286 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [mlir][LLVM] Delete `LLVMFixedVectorType` and `LLVMScalableVectorType` (PR #133286)
@@ -897,8 +821,7 @@ bool mlir::LLVM::isCompatibleVectorType(Type type) { Type mlir::LLVM::getVectorElementType(Type type) { return llvm::TypeSwitch(type) - .Case( - [](auto ty) { return ty.getElementType(); }) + .Case([](auto ty) { return ty.getElementType(); }) Dinistro wrote: ```suggestion .Case([](VectorType ty) { return ty.getElementType(); }) ``` Nit: Or maybe remove the switch altogether? https://github.com/llvm/llvm-project/pull/133286 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] compiler-rt: Introduce runtime functions for emulated PAC. (PR #133530)
@@ -0,0 +1,115 @@ +#include pcc wrote: Correct, I forgot to add one. Will add. https://github.com/llvm/llvm-project/pull/133530 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] 0de37ec - Revert "[HLSL][RootSignature] Implement parsing of a DescriptorTable with emp…"
Author: Finn Plummer Date: 2025-03-31T13:17:55-07:00 New Revision: 0de37ec26159a6840c93e6595975445ac6c0e642 URL: https://github.com/llvm/llvm-project/commit/0de37ec26159a6840c93e6595975445ac6c0e642 DIFF: https://github.com/llvm/llvm-project/commit/0de37ec26159a6840c93e6595975445ac6c0e642.diff LOG: Revert "[HLSL][RootSignature] Implement parsing of a DescriptorTable with emp…" This reverts commit e4b9486056fab7a262fdafbe70acf393c9767d12. Added: Modified: clang/include/clang/Basic/DiagnosticParseKinds.td clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def clang/include/clang/Lex/LexHLSLRootSignature.h clang/lib/Parse/CMakeLists.txt clang/unittests/CMakeLists.txt clang/unittests/Lex/LexHLSLRootSignatureTest.cpp Removed: clang/include/clang/Parse/ParseHLSLRootSignature.h clang/lib/Parse/ParseHLSLRootSignature.cpp clang/unittests/Parse/CMakeLists.txt clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index 2582e1e5ef0f6..86c361b4dbcf7 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -1830,8 +1830,4 @@ def err_hlsl_virtual_function def err_hlsl_virtual_inheritance : Error<"virtual inheritance is unsupported in HLSL">; -// HLSL Root Siganture diagnostic messages -def err_hlsl_unexpected_end_of_params -: Error<"expected %0 to denote end of parameters, or, another valid parameter of %1">; - } // end of Parser diagnostics diff --git a/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def b/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def index c514d3456146a..e6df763920430 100644 --- a/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def +++ b/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def @@ -14,16 +14,16 @@ //===--===// #ifndef TOK -#define TOK(X, SPELLING) +#define TOK(X) #endif #ifndef PUNCTUATOR -#define PUNCTUATOR(X,Y) TOK(pu_ ## X, Y) +#define PUNCTUATOR(X,Y) TOK(pu_ ## X) #endif #ifndef KEYWORD -#define KEYWORD(X) TOK(kw_ ## X, #X) +#define KEYWORD(X) TOK(kw_ ## X) #endif #ifndef ENUM -#define ENUM(NAME, LIT) TOK(en_ ## NAME, LIT) +#define ENUM(NAME, LIT) TOK(en_ ## NAME) #endif // Defines the various types of enum @@ -49,15 +49,15 @@ #endif // General Tokens: -TOK(invalid, "invalid identifier") -TOK(end_of_stream, "end of stream") -TOK(int_literal, "integer literal") +TOK(invalid) +TOK(end_of_stream) +TOK(int_literal) // Register Tokens: -TOK(bReg, "b register") -TOK(tReg, "t register") -TOK(uReg, "u register") -TOK(sReg, "s register") +TOK(bReg) +TOK(tReg) +TOK(uReg) +TOK(sReg) // Punctuators: PUNCTUATOR(l_paren, '(') @@ -69,7 +69,6 @@ PUNCTUATOR(plus,'+') PUNCTUATOR(minus, '-') // RootElement Keywords: -KEYWORD(RootSignature) // used only for diagnostic messaging KEYWORD(DescriptorTable) // DescriptorTable Keywords: diff --git a/clang/include/clang/Lex/LexHLSLRootSignature.h b/clang/include/clang/Lex/LexHLSLRootSignature.h index a7e1f782b767f..21c44e0351d9e 100644 --- a/clang/include/clang/Lex/LexHLSLRootSignature.h +++ b/clang/include/clang/Lex/LexHLSLRootSignature.h @@ -13,7 +13,6 @@ #ifndef LLVM_CLANG_LEX_LEXHLSLROOTSIGNATURE_H #define LLVM_CLANG_LEX_LEXHLSLROOTSIGNATURE_H -#include "clang/Basic/Diagnostic.h" #include "clang/Basic/SourceLocation.h" #include "llvm/ADT/SmallVector.h" @@ -25,7 +24,7 @@ namespace hlsl { struct RootSignatureToken { enum Kind { -#define TOK(X, SPELLING) X, +#define TOK(X) X, #include "clang/Lex/HLSLRootSignatureTokenKinds.def" }; @@ -44,18 +43,6 @@ struct RootSignatureToken { }; using TokenKind = enum RootSignatureToken::Kind; -inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, - const TokenKind Kind) { - switch (Kind) { -#define TOK(X, SPELLING) \ - case TokenKind::X: \ -DB << SPELLING; \ -break; -#include "clang/Lex/HLSLRootSignatureTokenKinds.def" - } - return DB; -} - class RootSignatureLexer { public: RootSignatureLexer(StringRef Signature, clang::SourceLocation SourceLoc) diff --git a/clang/include/clang/Parse/ParseHLSLRootSignature.h b/clang/include/clang/Parse/ParseHLSLRootSignature.h deleted file mode 100644 index 43b41315b88b5..0 --- a/clang/include/clang/Parse/ParseHLSLRootSignature.h +++ /dev/null @@ -1,107 +0,0 @@ -//===--- ParseHLSLRootSignature.h ---*- C++ -*-===// -// -// Part of the LLVM Project, under the Apach
[llvm-branch-commits] [clang] [HLSL] Define the HLSLRootSignature Attr (PR #123985)
https://github.com/inbelic closed https://github.com/llvm/llvm-project/pull/123985 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/20.x: [workflows] Add missing -y option to apt-get for abi tests (#133337) (PR #133813)
https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/133813 Backport 7793bae97d2bad36d870c6df438a6fc034f15112 Requested by: @tstellar >From 2f6c5807ca7e8263c634eee22a8a353994011dc9 Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Mon, 31 Mar 2025 15:30:05 -0700 Subject: [PATCH] [workflows] Add missing -y option to apt-get for abi tests (#17) (cherry picked from commit 7793bae97d2bad36d870c6df438a6fc034f15112) --- .github/workflows/libclang-abi-tests.yml | 4 ++-- .github/workflows/llvm-tests.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/libclang-abi-tests.yml b/.github/workflows/libclang-abi-tests.yml index ff8f38b43098e..65cffccff776f 100644 --- a/.github/workflows/libclang-abi-tests.yml +++ b/.github/workflows/libclang-abi-tests.yml @@ -104,7 +104,7 @@ jobs: - name: Install abi-compliance-checker run: | sudo apt-get update - sudo apt-get install abi-dumper autoconf pkg-config + sudo apt-get install -y abi-dumper autoconf pkg-config - name: Install universal-ctags run: | git clone https://github.com/universal-ctags/ctags.git @@ -157,7 +157,7 @@ jobs: - name: Install abi-compliance-checker run: | sudo apt-get update - sudo apt-get install abi-compliance-checker + sudo apt-get install -y abi-compliance-checker - name: Compare ABI run: | for lib in ${{ needs.abi-dump-setup.outputs.ABI_LIBS }}; do diff --git a/.github/workflows/llvm-tests.yml b/.github/workflows/llvm-tests.yml index 92debf2a8a269..e2ca2ff44890e 100644 --- a/.github/workflows/llvm-tests.yml +++ b/.github/workflows/llvm-tests.yml @@ -92,7 +92,7 @@ jobs: - name: Install abi-compliance-checker run: | sudo apt-get update - sudo apt-get install abi-dumper autoconf pkg-config + sudo apt-get -y install abi-dumper autoconf pkg-config - name: Install universal-ctags run: | git clone https://github.com/universal-ctags/ctags.git @@ -166,7 +166,7 @@ jobs: - name: Install abi-compliance-checker run: | sudo apt-get update - sudo apt-get install abi-compliance-checker + sudo apt-get -y install abi-compliance-checker - name: Compare ABI run: | if [ -s symbol-list/llvm.symbols ]; then ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/20.x: [workflows] Add missing -y option to apt-get for abi tests (#133337) (PR #133813)
llvmbot wrote: @boomanaiden154 What do you think about merging this PR to the release branch? https://github.com/llvm/llvm-project/pull/133813 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] Backport/20.x: [LoongArch] Fix the type of tls-le symbols (PR #133027)
zhaoqi5 wrote: > LGTM. > > Note: test/CodeGen is probably not the best place for such tests. > `test/MC/CSKY/relocation-specifier.s` contains a nice example and tests > multiple relocations at the same time. Modified in https://github.com/llvm/llvm-project/pull/133839, thanks. https://github.com/llvm/llvm-project/pull/133027 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] llvm-reduce: Add test for token handling in operands-skip (PR #133857)
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.dev/github/pr/llvm/llvm-project/133857?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#133857** https://app.graphite.dev/github/pr/llvm/llvm-project/133857?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/133857?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#133855** https://app.graphite.dev/github/pr/llvm/llvm-project/133855?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/133857 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] llvm-reduce: Add test for token handling in operands-skip (PR #133857)
https://github.com/arsenm ready_for_review https://github.com/llvm/llvm-project/pull/133857 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] llvm-reduce: Add test for token handling in operands-skip (PR #133857)
https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/133857 Seems to work correctly but wasn't tested. >From 4182da49f37add4eff4c2e3acd32a609ef985338 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Tue, 1 Apr 2025 11:48:22 +0700 Subject: [PATCH] llvm-reduce: Add test for token handling in operands-skip Seems to work correctly but wasn't tested. --- .../llvm-reduce/reduce-operands-skip-token.ll | 27 +++ 1 file changed, 27 insertions(+) create mode 100644 llvm/test/tools/llvm-reduce/reduce-operands-skip-token.ll diff --git a/llvm/test/tools/llvm-reduce/reduce-operands-skip-token.ll b/llvm/test/tools/llvm-reduce/reduce-operands-skip-token.ll new file mode 100644 index 0..1202974333b5b --- /dev/null +++ b/llvm/test/tools/llvm-reduce/reduce-operands-skip-token.ll @@ -0,0 +1,27 @@ +; Check token values are correctly handled by operands-skip + +; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=operands-skip --test FileCheck --test-arg --check-prefix=INTERESTING --test-arg %s --test-arg --input-file %s -o %t +; RUN: FileCheck -check-prefix=RESULT %s < %t + +; INTERESTING-LABEL: define void @tokens( +; INTERESTING: call void @llvm.token.consumer + +; RESULT-LABEL: define void @tokens(ptr %ptr) { +; RESULT-NEXT: %token = call token @llvm.token.producer() +; RESULT-NEXT:store i32 0, ptr %ptr, align 4 +; RESULT-NEXT:%chain = call token @llvm.token.chain(token %token) +; RESULT-NEXT:call void @llvm.token.consumer(token %token) +; RESULT-NEXT:store i32 1, ptr %ptr, align 4 +; RESULT-NEXT:ret void +define void @tokens(ptr %ptr) { + %token = call token @llvm.token.producer() + store i32 0, ptr %ptr + %chain = call token @llvm.token.chain(token %token) + call void @llvm.token.consumer(token %chain) ; -> rewrite to use %token directly + store i32 1, ptr %ptr + ret void +} + +declare token @llvm.token.producer() +declare token @llvm.token.chain(token) +declare void @llvm.token.consumer(token) ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [SDAG] Introduce inbounds flag for pointer arithmetic (PR #131862)
efriedma-quic wrote: If we have PTRADD without a corresponding pointer type, the operand of the PTRADD is implicitly an inttoptr, which causes the problems we're discussing. Which... the IR layer doesn't really properly preserve inttoptr operations in all circumstances, but we're trying to fix that, so I don't want to make the problem worse. https://github.com/llvm/llvm-project/pull/131862 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/20.x: [workflows] Add missing -y option to apt-get for abi tests (#133337) (PR #133813)
https://github.com/boomanaiden154 approved this pull request. https://github.com/llvm/llvm-project/pull/133813 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] llvm-reduce: Fix overly conservative operands-to-args user restriction (PR #133854)
https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/133854 I assume this was a leftover from typed pointers. It's easier to replace the non-callee uses, they are just replacable pointer values. >From 83ba71fe5eff72cd5f08b41a848c44b93dea3de9 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Tue, 1 Apr 2025 10:19:10 +0700 Subject: [PATCH] llvm-reduce: Fix overly conservative operands-to-args user restriction I assume this was a leftover from typed pointers. It's easier to replace the non-callee uses, they are just replacable pointer values. --- llvm/test/tools/llvm-reduce/operands-to-args.ll | 6 +++--- .../llvm-reduce/deltas/ReduceOperandsToArgs.cpp | 16 +++- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/llvm/test/tools/llvm-reduce/operands-to-args.ll b/llvm/test/tools/llvm-reduce/operands-to-args.ll index 3378f15e58936..1765ffc25ae5f 100644 --- a/llvm/test/tools/llvm-reduce/operands-to-args.ll +++ b/llvm/test/tools/llvm-reduce/operands-to-args.ll @@ -77,7 +77,7 @@ define void @f(ptr %a) { @gv_init_use = global [1 x ptr] [ptr @has_global_init_user] ; INTERESTING-LABEL: define void @has_global_init_user( -; REDUCED-LABEL: define void @has_global_init_user() { +; REDUCED-LABEL: define void @has_global_init_user(ptr %Local) { define void @has_global_init_user() { %Local = alloca i32, align 4 store i32 42, ptr %Local, align 4 @@ -85,7 +85,7 @@ define void @has_global_init_user() { } ; INTERESTING-LABEL: define void @has_callee_and_arg_user( -; REDUCED-LABEL: define void @has_callee_and_arg_user(ptr %orig.arg) { +; REDUCED-LABEL: define void @has_callee_and_arg_user(ptr %orig.arg, ptr %Local) { define void @has_callee_and_arg_user(ptr %orig.arg) { %Local = alloca i32, align 4 store i32 42, ptr %Local, align 4 @@ -96,7 +96,7 @@ declare void @ptr_user(ptr) ; INTERESTING-LABEL: define void @calls_and_passes_func( ; REDUCED-LABEL: define void @calls_and_passes_func(ptr %has_callee_and_arg_user) { -; REDUCED: call void @has_callee_and_arg_user(ptr %has_callee_and_arg_user) +; REDUCED: call void @has_callee_and_arg_user(ptr %has_callee_and_arg_user, ptr null) define void @calls_and_passes_func() { call void @has_callee_and_arg_user(ptr @has_callee_and_arg_user) ret void diff --git a/llvm/tools/llvm-reduce/deltas/ReduceOperandsToArgs.cpp b/llvm/tools/llvm-reduce/deltas/ReduceOperandsToArgs.cpp index 3548130d3276a..af873791b0abe 100644 --- a/llvm/tools/llvm-reduce/deltas/ReduceOperandsToArgs.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceOperandsToArgs.cpp @@ -19,12 +19,9 @@ using namespace llvm; -static bool canReplaceFunction(Function *F) { - return all_of(F->uses(), [](Use &Op) { -if (auto *CI = dyn_cast(Op.getUser())) - return &CI->getCalledOperandUse() == &Op; -return false; - }); +static bool canReplaceFunction(const Function &F) { + // TODO: Add controls to avoid ABI breaks (e.g. don't break main) + return true; } static bool canReduceUse(Use &Op) { @@ -59,8 +56,9 @@ static bool canReduceUse(Use &Op) { static void replaceFunctionCalls(Function *OldF, Function *NewF) { SmallVector Callers; for (Use &U : OldF->uses()) { -auto *CI = cast(U.getUser()); -assert(&U == &CI->getCalledOperandUse()); +auto *CI = dyn_cast(U.getUser()); +if (!CI || !CI->isCallee(&U)) // RAUW can handle these fine. + continue; Function *CalledF = CI->getCalledFunction(); if (CalledF == OldF) { @@ -209,7 +207,7 @@ void llvm::reduceOperandsToArgsDeltaPass(Oracle &O, ReducerWorkItem &WorkItem) { SmallVector OperandsToReduce; for (Function &F : make_early_inc_range(Program.functions())) { -if (!canReplaceFunction(&F)) +if (!canReplaceFunction(F)) continue; OperandsToReduce.clear(); for (Instruction &I : instructions(&F)) { ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] bc65196 - update test due to https://github.com/llvm/llvm-project/pull/126880 not being backported
Author: Lei Huang Date: 2025-03-31T12:51:21-07:00 New Revision: bc65196c0919f337e7efcaaa1c7fb20ac988b3d4 URL: https://github.com/llvm/llvm-project/commit/bc65196c0919f337e7efcaaa1c7fb20ac988b3d4 DIFF: https://github.com/llvm/llvm-project/commit/bc65196c0919f337e7efcaaa1c7fb20ac988b3d4.diff LOG: update test due to https://github.com/llvm/llvm-project/pull/126880 not being backported Added: Modified: llvm/test/CodeGen/PowerPC/f128-conv.ll Removed: diff --git a/llvm/test/CodeGen/PowerPC/f128-conv.ll b/llvm/test/CodeGen/PowerPC/f128-conv.ll index f8b2861156db4..1a51ca64177a0 100644 --- a/llvm/test/CodeGen/PowerPC/f128-conv.ll +++ b/llvm/test/CodeGen/PowerPC/f128-conv.ll @@ -1365,7 +1365,7 @@ define half @trunc(fp128 %a) nounwind { ; CHECK-P8-NEXT:bl __trunckfhf2 ; CHECK-P8-NEXT:nop ; CHECK-P8-NEXT:clrldi r3, r3, 48 -; CHECK-P8-NEXT:bl __extendhfsf2 +; CHECK-P8-NEXT:bl __gnu_h2f_ieee ; CHECK-P8-NEXT:nop ; CHECK-P8-NEXT:addi r1, r1, 32 ; CHECK-P8-NEXT:ld r0, 16(r1) ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/20.x: [LoongArch][MC] Add relocation support for fld fst [x]vld [x]vst (PR #133836)
https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/133836 Backport 725a7b664b92cd2e884806de5a08900b43d43cce d055e58334a91dcbaee22eb87bcdae85a1f33cd4 Requested by: @SixWeining >From e7f024dd3ae770af9f766e4b86a43b2df9e6dc1a Mon Sep 17 00:00:00 2001 From: wanglei Date: Fri, 28 Mar 2025 10:21:23 +0800 Subject: [PATCH 1/2] [LoongArch] Pre-commit test for #133225 Reviewed By: SixWeining Pull Request: https://github.com/llvm/llvm-project/pull/133224 (cherry picked from commit 725a7b664b92cd2e884806de5a08900b43d43cce) --- .../MC/LoongArch/Relocations/relocations.s| 25 +++ 1 file changed, 25 insertions(+) diff --git a/llvm/test/MC/LoongArch/Relocations/relocations.s b/llvm/test/MC/LoongArch/Relocations/relocations.s index 091dce200b7de..f6d2cc149cc0c 100644 --- a/llvm/test/MC/LoongArch/Relocations/relocations.s +++ b/llvm/test/MC/LoongArch/Relocations/relocations.s @@ -3,6 +3,9 @@ # RUN: llvm-mc --filetype=obj --triple=loongarch64 < %s \ # RUN: | llvm-readobj -r - | FileCheck --check-prefix=RELOC %s +# RUN: not llvm-mc --triple=loongarch64 --defsym=FIXME=1 < %s 2>&1 \ +# RUN: | FileCheck --check-prefix=ERROR %s + ## Check prefixes: ## RELOC - Check the relocation in the object. ## FIXUP - Check the fixup on the instruction. @@ -308,3 +311,25 @@ pcaddi $t1, %desc_pcrel_20(foo) # RELOC: R_LARCH_TLS_DESC_PCREL20_S2 foo 0x0 # INSTR: pcaddi $t1, %desc_pcrel_20(foo) # FIXUP: fixup A - offset: 0, value: %desc_pcrel_20(foo), kind: FK_NONE + +.ifdef FIXME + +fld.s $ft1, $a0, %pc_lo12(foo) +# ERROR: :[[#@LINE-1]]:18: error: immediate must be an integer in the range [-2048, 2047] + +fst.d $ft1, $a0, %pc_lo12(foo) +# ERROR: :[[#@LINE-1]]:18: error: immediate must be an integer in the range [-2048, 2047] + +vld $vr9, $a0, %pc_lo12(foo) +# ERROR: :[[#@LINE-1]]:16: error: immediate must be an integer in the range [-2048, 2047] + +vst $vr9, $a0, %pc_lo12(foo) +# ERROR: :[[#@LINE-1]]:16: error: immediate must be an integer in the range [-2048, 2047] + +xvld $xr9, $a0, %pc_lo12(foo) +# ERROR: :[[#@LINE-1]]:17: error: immediate must be an integer in the range [-2048, 2047] + +xvst $xr9, $a0, %pc_lo12(foo) +# ERROR: :[[#@LINE-1]]:17: error: immediate must be an integer in the range [-2048, 2047] + +.endif >From 88936f7abe98ce6feb58a54ae147b2fed5d88bcc Mon Sep 17 00:00:00 2001 From: wanglei Date: Fri, 28 Mar 2025 11:20:17 +0800 Subject: [PATCH 2/2] [LoongArch][MC] Add relocation support for fld fst [x]vld [x]vst This also fixes errors when using Clang with step-by-step compilation. Because the optimization will pass relocation information to memory access instructions. For example: t.c: ``` float f = 0.1; float foo() { return f;} ``` ``` clang --target=loongarch64 -O2 -c t.c --save-temps ``` Reviewed By: tangaac, SixWeining Pull Request: https://github.com/llvm/llvm-project/pull/133225 (cherry picked from commit d055e58334a91dcbaee22eb87bcdae85a1f33cd4) --- .../LoongArch/LoongArchFloatInstrFormats.td | 4 +-- .../LoongArch/LoongArchLASXInstrInfo.td | 4 +-- .../Target/LoongArch/LoongArchLSXInstrInfo.td | 4 +-- .../MC/LoongArch/Relocations/relocations.s| 31 +++ llvm/test/MC/LoongArch/lasx/invalid-imm.s | 12 +++ llvm/test/MC/LoongArch/lsx/invalid-imm.s | 12 +++ 6 files changed, 36 insertions(+), 31 deletions(-) diff --git a/llvm/lib/Target/LoongArch/LoongArchFloatInstrFormats.td b/llvm/lib/Target/LoongArch/LoongArchFloatInstrFormats.td index f66f620ca8b26..ce42236895c76 100644 --- a/llvm/lib/Target/LoongArch/LoongArchFloatInstrFormats.td +++ b/llvm/lib/Target/LoongArch/LoongArchFloatInstrFormats.td @@ -206,7 +206,7 @@ class FP_LOAD_3R op, RegisterClass rc = FPR32> : FPFmtMEM; class FP_LOAD_2RI12 op, RegisterClass rc = FPR32> -: FPFmt2RI12; } // hasSideEffects = 0, mayLoad = 1, mayStore = 0 @@ -215,7 +215,7 @@ class FP_STORE_3R op, RegisterClass rc = FPR32> : FPFmtMEM; class FP_STORE_2RI12 op, RegisterClass rc = FPR32> -: FPFmt2RI12; } // hasSideEffects = 0, mayLoad = 0, mayStore = 1 diff --git a/llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td b/llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td index 24b5ed5a9344f..7022fddf34100 100644 --- a/llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td +++ b/llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td @@ -186,10 +186,10 @@ class LASX2RI10_Load op, Operand ImmOpnd = simm10_lsl2> class LASX2RI11_Load op, Operand ImmOpnd = simm11_lsl1> : Fmt2RI11_XRI; -class LASX2RI12_Load op, Operand ImmOpnd = simm12> +class LASX2RI12_Load op, Operand ImmOpnd = simm12_addlike> : Fmt2RI12_XRI; -class LASX2RI12_Store op, Operand ImmOpnd = simm12> +class LASX2RI12_Store op, Operand ImmOpnd = simm12_addlike> : Fmt2RI12_XRI; diff --git a/llvm/lib/Target/LoongArch/LoongArchLSXInstrInfo.td b/llvm/lib/Target/LoongArch/LoongArchLSXInstrInfo.td index d2063a8aaae9b..e37de4f545a2a 100644 --- a/llvm/lib/Target/LoongArch/LoongA
[llvm-branch-commits] [compiler-rt] release/20.x: XFAIL malloc_zone.cpp for darwin/lsan (#131234) (PR #133006)
https://github.com/wrotki closed https://github.com/llvm/llvm-project/pull/133006 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] [Sanitizers][Darwin][Test] XFAIL malloc_zone.cpp (PR #133832)
https://github.com/wrotki updated https://github.com/llvm/llvm-project/pull/133832 >From ca129ea5996c2f2b99868bccd2246690a65b6c9e Mon Sep 17 00:00:00 2001 From: Mariusz Borsa Date: Mon, 31 Mar 2025 17:06:41 -0700 Subject: [PATCH] [Sanitizers][Darwin][Test] XFAIL malloc_zone.cpp The malloc_zone.cpp test currently fails on Darwin hosts, in SanitizerCommon tests with lsan enabled. Need to XFAIL this test to buy time to investigate this failure. Also we're trying to bring the number of test failing on Darwin bots to 0, to get clearer signal of any new failures. rdar://145873843 Co-authored-by: Mariusz Borsa (cherry picked from commit 02837acaaf2cfdfcbf77e4a7f6629575edb6ffb4) --- .../test/sanitizer_common/TestCases/Darwin/malloc_zone.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compiler-rt/test/sanitizer_common/TestCases/Darwin/malloc_zone.cpp b/compiler-rt/test/sanitizer_common/TestCases/Darwin/malloc_zone.cpp index fd6ef03629438..5aa087fb4ca12 100644 --- a/compiler-rt/test/sanitizer_common/TestCases/Darwin/malloc_zone.cpp +++ b/compiler-rt/test/sanitizer_common/TestCases/Darwin/malloc_zone.cpp @@ -17,6 +17,8 @@ // UBSan does not install a malloc zone. // XFAIL: ubsan // +// Currently fails on darwin/lsan +// XFAIL: darwin && lsan #include #include ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] release/20.x: [Sanitizers][Darwin][Test] XFAIL malloc_zone.cpp (PR #133832)
https://github.com/wrotki edited https://github.com/llvm/llvm-project/pull/133832 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/20.x: [ARM] Speedups for CombineBaseUpdate. (#129725) (PR #130035)
https://github.com/tstellar closed https://github.com/llvm/llvm-project/pull/130035 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [PowerPC] Support conversion between f16 and f128 (#130158) (PR #133279)
https://github.com/tstellar closed https://github.com/llvm/llvm-project/pull/133279 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [PowerPC] Support conversion between f16 and f128 (#130158) (PR #133279)
github-actions[bot] wrote: @lei137 (or anyone else). If you would like to add a note about this fix in the release notes (completely optional). Please reply to this comment with a one or two sentence description of the fix. When you are done, please add the release:note label to this PR. https://github.com/llvm/llvm-project/pull/133279 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [PowerPC] Support conversion between f16 and f128 (#130158) (PR #133279)
https://github.com/tstellar updated https://github.com/llvm/llvm-project/pull/133279 >From bc65196c0919f337e7efcaaa1c7fb20ac988b3d4 Mon Sep 17 00:00:00 2001 From: Lei Huang Date: Thu, 27 Mar 2025 17:27:45 + Subject: [PATCH] update test due to https://github.com/llvm/llvm-project/pull/126880 not being backported --- llvm/test/CodeGen/PowerPC/f128-conv.ll | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/test/CodeGen/PowerPC/f128-conv.ll b/llvm/test/CodeGen/PowerPC/f128-conv.ll index f8b2861156db4..1a51ca64177a0 100644 --- a/llvm/test/CodeGen/PowerPC/f128-conv.ll +++ b/llvm/test/CodeGen/PowerPC/f128-conv.ll @@ -1365,7 +1365,7 @@ define half @trunc(fp128 %a) nounwind { ; CHECK-P8-NEXT:bl __trunckfhf2 ; CHECK-P8-NEXT:nop ; CHECK-P8-NEXT:clrldi r3, r3, 48 -; CHECK-P8-NEXT:bl __extendhfsf2 +; CHECK-P8-NEXT:bl __gnu_h2f_ieee ; CHECK-P8-NEXT:nop ; CHECK-P8-NEXT:addi r1, r1, 32 ; CHECK-P8-NEXT:ld r0, 16(r1) ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/20.x: [ARM] Speedups for CombineBaseUpdate. (#129725) (PR #130035)
https://github.com/llvmbot updated https://github.com/llvm/llvm-project/pull/130035 >From d6d1dbf221814b2a28cb234e72c7d81730ff26e7 Mon Sep 17 00:00:00 2001 From: David Green Date: Thu, 6 Mar 2025 09:35:12 + Subject: [PATCH] [ARM] Speedups for CombineBaseUpdate. (#129725) This attempts to put limits onto CombineBaseUpdate for degenerate cases like #127477. The biggest change is to add a limit to the number of base updates to check in CombineBaseUpdate. 64 is hopefully plenty high enough for most runtime unrolled loops to generate postinc where they are beneficial. It also moves the check for isValidBaseUpdate later so that it only happens if we will generate a valid instruction. The 1024 limit to hasPredecessorHelper comes from the X86 backend, which uses the same limit. I haven't added a test case as it would need to be very big and my attempts at generating a smaller version did not show anything useful. Fixes #127477. (cherry picked from commit 86cf4ed7e9510a6828e95e8b36893eec116c9cf9) --- llvm/lib/Target/ARM/ARMISelLowering.cpp | 67 ++--- 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/llvm/lib/Target/ARM/ARMISelLowering.cpp b/llvm/lib/Target/ARM/ARMISelLowering.cpp index bd8d6079e1ba8..d20115c84ea89 100644 --- a/llvm/lib/Target/ARM/ARMISelLowering.cpp +++ b/llvm/lib/Target/ARM/ARMISelLowering.cpp @@ -149,6 +149,11 @@ MVEMaxSupportedInterleaveFactor("mve-max-interleave-factor", cl::Hidden, cl::desc("Maximum interleave factor for MVE VLDn to generate."), cl::init(2)); +cl::opt ArmMaxBaseUpdatesToCheck( +"arm-max-base-updates-to-check", cl::Hidden, +cl::desc("Maximum number of base-updates to check generating postindex."), +cl::init(64)); + /// Value type used for "flags" operands / results (either CPSR or FPSCR_NZCV). constexpr MVT FlagsVT = MVT::i32; @@ -15842,6 +15847,22 @@ struct BaseUpdateUser { unsigned ConstInc; }; +static bool isValidBaseUpdate(SDNode *N, SDNode *User) { + // Check that the add is independent of the load/store. + // Otherwise, folding it would create a cycle. Search through Addr + // as well, since the User may not be a direct user of Addr and + // only share a base pointer. + SmallPtrSet Visited; + SmallVector Worklist; + Worklist.push_back(N); + Worklist.push_back(User); + const unsigned MaxSteps = 1024; + if (SDNode::hasPredecessorHelper(N, Visited, Worklist, MaxSteps) || + SDNode::hasPredecessorHelper(User, Visited, Worklist, MaxSteps)) +return false; + return true; +} + static bool TryCombineBaseUpdate(struct BaseUpdateTarget &Target, struct BaseUpdateUser &User, bool SimpleConstIncOnly, @@ -16043,6 +16064,9 @@ static bool TryCombineBaseUpdate(struct BaseUpdateTarget &Target, if (SimpleConstIncOnly && User.ConstInc != NumBytes) return false; + if (!isValidBaseUpdate(N, User.N)) +return false; + // OK, we found an ADD we can fold into the base update. // Now, create a _UPD node, taking care of not breaking alignment. @@ -16191,21 +16215,6 @@ static bool findPointerConstIncrement(SDNode *N, SDValue *Ptr, SDValue *CInc) { } } -static bool isValidBaseUpdate(SDNode *N, SDNode *User) { - // Check that the add is independent of the load/store. - // Otherwise, folding it would create a cycle. Search through Addr - // as well, since the User may not be a direct user of Addr and - // only share a base pointer. - SmallPtrSet Visited; - SmallVector Worklist; - Worklist.push_back(N); - Worklist.push_back(User); - if (SDNode::hasPredecessorHelper(N, Visited, Worklist) || - SDNode::hasPredecessorHelper(User, Visited, Worklist)) -return false; - return true; -} - /// CombineBaseUpdate - Target-specific DAG combine function for VLDDUP, /// NEON load/store intrinsics, and generic vector load/stores, to merge /// base address updates. @@ -16219,6 +16228,10 @@ static SDValue CombineBaseUpdate(SDNode *N, const unsigned AddrOpIdx = ((isIntrinsic || isStore) ? 2 : 1); BaseUpdateTarget Target = {N, isIntrinsic, isStore, AddrOpIdx}; + // Limit the number of possible base-updates we look at to prevent degenerate + // cases. + unsigned MaxBaseUpdates = ArmMaxBaseUpdatesToCheck; + SDValue Addr = N->getOperand(AddrOpIdx); SmallVector BaseUpdates; @@ -16233,8 +16246,11 @@ static SDValue CombineBaseUpdate(SDNode *N, unsigned ConstInc = getPointerConstIncrement(User->getOpcode(), Addr, Inc, DCI.DAG); -if (ConstInc || User->getOpcode() == ISD::ADD) +if (ConstInc || User->getOpcode() == ISD::ADD) { BaseUpdates.push_back({User, Inc, ConstInc}); + if (BaseUpdates.size() >= MaxBaseUpdates) +break; +} } // If the address is a constant pointer increment itself, find @@ -16261,27 +16277,19 @@ static SDValue CombineBaseUpdate(SDNode *N, unsigned NewConstInc = UserOffset - Offset; SDValue NewInc = DCI.DAG.get
[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add infastructure to parse parameters (PR #133800)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff HEAD~1 HEAD --extensions h,cpp -- clang/include/clang/Parse/ParseHLSLRootSignature.h clang/lib/Parse/ParseHLSLRootSignature.cpp clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h `` View the diff from clang-format here. ``diff diff --git a/clang/lib/Parse/ParseHLSLRootSignature.cpp b/clang/lib/Parse/ParseHLSLRootSignature.cpp index 62d29baea..27b53aa79 100644 --- a/clang/lib/Parse/ParseHLSLRootSignature.cpp +++ b/clang/lib/Parse/ParseHLSLRootSignature.cpp @@ -136,7 +136,9 @@ bool RootSignatureParser::parseDescriptorTableClause() { } // Helper struct defined to use the overloaded notation of std::visit. -template struct ParseMethods : Ts... { using Ts::operator()...; }; +template struct ParseMethods : Ts... { + using Ts::operator()...; +}; template ParseMethods(Ts...) -> ParseMethods; bool RootSignatureParser::parseParam(ParamType Ref) { `` https://github.com/llvm/llvm-project/pull/133800 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] ELF: Add support for R_AARCH64_INST32 relocation. (PR #133534)
pcc wrote: > Apologies for the delay in responding, just come back from vacation. Not had > a chance to look through the Discourse posts yet, will do so this week. > > While it may seem a bit premature, would you be able to open an issue in the > AArch64 ABI (https://github.com/ARM-software/abi-aa/issues) with a request to > add a new relocation directive, citing the Discourse posts and PRs? Sure, created https://github.com/ARM-software/abi-aa/issues/317 https://github.com/llvm/llvm-project/pull/133534 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [Metadata] Preserve MD_prof when merging instructions when one is missing. (PR #132433)
https://github.com/snehasish updated https://github.com/llvm/llvm-project/pull/132433 >From 4680029efc3f4e350f7a07033088a9925b9300d7 Mon Sep 17 00:00:00 2001 From: Snehasish Kumar Date: Fri, 21 Mar 2025 17:00:38 + Subject: [PATCH] Update tests, apply clang-tidy suggestions --- llvm/lib/Transforms/Utils/Local.cpp | 19 -- ...rect-call-branch-weights-preserve-hoist.ll | 62 ++ ...irect-call-branch-weights-preserve-sink.ll | 63 +++ 3 files changed, 138 insertions(+), 6 deletions(-) create mode 100644 llvm/test/Transforms/SimplifyCFG/merge-direct-call-branch-weights-preserve-hoist.ll create mode 100644 llvm/test/Transforms/SimplifyCFG/merge-direct-call-branch-weights-preserve-sink.ll diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index edec0e7a94422..c136825d47b9c 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -3355,9 +3355,10 @@ static void combineMetadata(Instruction *K, const Instruction *J, case LLVMContext::MD_invariant_group: // Preserve !invariant.group in K. break; - // Keep empty cases for mmra, memprof, and callsite to prevent them from - // being removed as unknown metadata. The actual merging is handled + // Keep empty cases for prof, mmra, memprof, and callsite to prevent them + // from being removed as unknown metadata. The actual merging is handled // separately below. + case LLVMContext::MD_prof: case LLVMContext::MD_mmra: case LLVMContext::MD_memprof: case LLVMContext::MD_callsite: @@ -3386,10 +3387,6 @@ static void combineMetadata(Instruction *K, const Instruction *J, if (!AAOnly) K->setMetadata(Kind, JMD); break; - case LLVMContext::MD_prof: -if (!AAOnly && DoesKMove) - K->setMetadata(Kind, MDNode::getMergedProfMetadata(KMD, JMD, K, J)); -break; case LLVMContext::MD_noalias_addrspace: if (DoesKMove) K->setMetadata(Kind, @@ -3436,6 +3433,16 @@ static void combineMetadata(Instruction *K, const Instruction *J, K->setMetadata(LLVMContext::MD_callsite, MDNode::getMergedCallsiteMetadata(KCallSite, JCallSite)); } + + // Merge prof metadata. + // Handle separately to support cases where only one instruction has the + // metadata. + auto *JProf = J->getMetadata(LLVMContext::MD_prof); + auto *KProf = K->getMetadata(LLVMContext::MD_prof); + if (!AAOnly && (JProf || KProf)) { +K->setMetadata(LLVMContext::MD_prof, + MDNode::getMergedProfMetadata(KProf, JProf, K, J)); + } } void llvm::combineMetadataForCSE(Instruction *K, const Instruction *J, diff --git a/llvm/test/Transforms/SimplifyCFG/merge-direct-call-branch-weights-preserve-hoist.ll b/llvm/test/Transforms/SimplifyCFG/merge-direct-call-branch-weights-preserve-hoist.ll new file mode 100644 index 0..d6058134f5285 --- /dev/null +++ b/llvm/test/Transforms/SimplifyCFG/merge-direct-call-branch-weights-preserve-hoist.ll @@ -0,0 +1,62 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals --version 2 +; RUN: opt < %s -passes='simplifycfg' -simplifycfg-require-and-preserve-domtree=1 -S | FileCheck %s --check-prefix=HOIST + +; Test case based on C++ code with manualy annotated !prof metadata. +; This is to test that when calls to 'func1' from 'if.then' block +; and 'if.else' block are hoisted, the branch_weights are merged and +; attached to merged call rather than dropped. +; +; int func1(int a, int b) ; +; int func2(int a, int b) ; + +; int func(int a, int b, bool c) { +;int sum= 0; +;if(c) { +;sum += func1(a, b); +;} else { +;sum += func1(a, b); +;sum -= func2(a, b); +;} +;return sum; +; } +define i32 @_Z4funciib(i32 %a, i32 %b, i1 %c) { +; HOIST-LABEL: define i32 @_Z4funciib +; HOIST-SAME: (i32 [[A:%.*]], i32 [[B:%.*]], i1 [[C:%.*]]) { +; HOIST-NEXT: entry: +; HOIST-NEXT:[[CALL:%.*]] = tail call i32 @_Z5func1ii(i32 [[A]], i32 [[B]]), !prof [[PROF0:![0-9]+]] +; HOIST-NEXT:br i1 [[C]], label [[IF_END:%.*]], label [[IF_ELSE:%.*]] +; HOIST: if.else: +; HOIST-NEXT:[[CALL3:%.*]] = tail call i32 @_Z5func2ii(i32 [[A]], i32 [[B]]) +; HOIST-NEXT:[[SUB:%.*]] = sub i32 [[CALL]], [[CALL3]] +; HOIST-NEXT:br label [[IF_END]] +; HOIST: if.end: +; HOIST-NEXT:[[SUM_0:%.*]] = phi i32 [ [[SUB]], [[IF_ELSE]] ], [ [[CALL]], [[ENTRY:%.*]] ] +; HOIST-NEXT:ret i32 [[SUM_0]] +; +entry: + br i1 %c, label %if.then, label %if.else + +if.then: ; preds = %entry + %call = tail call i32 @_Z5func1ii(i32 %a, i32 %b) + br label %if.end + +if.else: ; preds = %entry + %call1 = tail call i32 @_Z5func1ii(i32 %a, i32 %b), !prof !0 + %call3 = tail call i32 @_Z5func2ii(i32 %a, i32 %b) + %
[llvm-branch-commits] [llvm] [Metadata] Preserve MD_prof when merging instructions when one is missing. (PR #132433)
https://github.com/snehasish updated https://github.com/llvm/llvm-project/pull/132433 >From 4680029efc3f4e350f7a07033088a9925b9300d7 Mon Sep 17 00:00:00 2001 From: Snehasish Kumar Date: Fri, 21 Mar 2025 17:00:38 + Subject: [PATCH] Update tests, apply clang-tidy suggestions --- llvm/lib/Transforms/Utils/Local.cpp | 19 -- ...rect-call-branch-weights-preserve-hoist.ll | 62 ++ ...irect-call-branch-weights-preserve-sink.ll | 63 +++ 3 files changed, 138 insertions(+), 6 deletions(-) create mode 100644 llvm/test/Transforms/SimplifyCFG/merge-direct-call-branch-weights-preserve-hoist.ll create mode 100644 llvm/test/Transforms/SimplifyCFG/merge-direct-call-branch-weights-preserve-sink.ll diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index edec0e7a94422..c136825d47b9c 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -3355,9 +3355,10 @@ static void combineMetadata(Instruction *K, const Instruction *J, case LLVMContext::MD_invariant_group: // Preserve !invariant.group in K. break; - // Keep empty cases for mmra, memprof, and callsite to prevent them from - // being removed as unknown metadata. The actual merging is handled + // Keep empty cases for prof, mmra, memprof, and callsite to prevent them + // from being removed as unknown metadata. The actual merging is handled // separately below. + case LLVMContext::MD_prof: case LLVMContext::MD_mmra: case LLVMContext::MD_memprof: case LLVMContext::MD_callsite: @@ -3386,10 +3387,6 @@ static void combineMetadata(Instruction *K, const Instruction *J, if (!AAOnly) K->setMetadata(Kind, JMD); break; - case LLVMContext::MD_prof: -if (!AAOnly && DoesKMove) - K->setMetadata(Kind, MDNode::getMergedProfMetadata(KMD, JMD, K, J)); -break; case LLVMContext::MD_noalias_addrspace: if (DoesKMove) K->setMetadata(Kind, @@ -3436,6 +3433,16 @@ static void combineMetadata(Instruction *K, const Instruction *J, K->setMetadata(LLVMContext::MD_callsite, MDNode::getMergedCallsiteMetadata(KCallSite, JCallSite)); } + + // Merge prof metadata. + // Handle separately to support cases where only one instruction has the + // metadata. + auto *JProf = J->getMetadata(LLVMContext::MD_prof); + auto *KProf = K->getMetadata(LLVMContext::MD_prof); + if (!AAOnly && (JProf || KProf)) { +K->setMetadata(LLVMContext::MD_prof, + MDNode::getMergedProfMetadata(KProf, JProf, K, J)); + } } void llvm::combineMetadataForCSE(Instruction *K, const Instruction *J, diff --git a/llvm/test/Transforms/SimplifyCFG/merge-direct-call-branch-weights-preserve-hoist.ll b/llvm/test/Transforms/SimplifyCFG/merge-direct-call-branch-weights-preserve-hoist.ll new file mode 100644 index 0..d6058134f5285 --- /dev/null +++ b/llvm/test/Transforms/SimplifyCFG/merge-direct-call-branch-weights-preserve-hoist.ll @@ -0,0 +1,62 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals --version 2 +; RUN: opt < %s -passes='simplifycfg' -simplifycfg-require-and-preserve-domtree=1 -S | FileCheck %s --check-prefix=HOIST + +; Test case based on C++ code with manualy annotated !prof metadata. +; This is to test that when calls to 'func1' from 'if.then' block +; and 'if.else' block are hoisted, the branch_weights are merged and +; attached to merged call rather than dropped. +; +; int func1(int a, int b) ; +; int func2(int a, int b) ; + +; int func(int a, int b, bool c) { +;int sum= 0; +;if(c) { +;sum += func1(a, b); +;} else { +;sum += func1(a, b); +;sum -= func2(a, b); +;} +;return sum; +; } +define i32 @_Z4funciib(i32 %a, i32 %b, i1 %c) { +; HOIST-LABEL: define i32 @_Z4funciib +; HOIST-SAME: (i32 [[A:%.*]], i32 [[B:%.*]], i1 [[C:%.*]]) { +; HOIST-NEXT: entry: +; HOIST-NEXT:[[CALL:%.*]] = tail call i32 @_Z5func1ii(i32 [[A]], i32 [[B]]), !prof [[PROF0:![0-9]+]] +; HOIST-NEXT:br i1 [[C]], label [[IF_END:%.*]], label [[IF_ELSE:%.*]] +; HOIST: if.else: +; HOIST-NEXT:[[CALL3:%.*]] = tail call i32 @_Z5func2ii(i32 [[A]], i32 [[B]]) +; HOIST-NEXT:[[SUB:%.*]] = sub i32 [[CALL]], [[CALL3]] +; HOIST-NEXT:br label [[IF_END]] +; HOIST: if.end: +; HOIST-NEXT:[[SUM_0:%.*]] = phi i32 [ [[SUB]], [[IF_ELSE]] ], [ [[CALL]], [[ENTRY:%.*]] ] +; HOIST-NEXT:ret i32 [[SUM_0]] +; +entry: + br i1 %c, label %if.then, label %if.else + +if.then: ; preds = %entry + %call = tail call i32 @_Z5func1ii(i32 %a, i32 %b) + br label %if.end + +if.else: ; preds = %entry + %call1 = tail call i32 @_Z5func1ii(i32 %a, i32 %b), !prof !0 + %call3 = tail call i32 @_Z5func2ii(i32 %a, i32 %b) + %
[llvm-branch-commits] [llvm] [SDAG] Introduce inbounds flag for pointer arithmetic (PR #131862)
https://github.com/ritter-x2a updated https://github.com/llvm/llvm-project/pull/131862 >From ee21919269e84f95b07c65c90937cc13d25202ad Mon Sep 17 00:00:00 2001 From: Fabian Ritter Date: Mon, 17 Mar 2025 06:51:16 -0400 Subject: [PATCH] [SDAG] Introduce inbounds flag for pointer arithmetic This patch introduces an inbounds SDNodeFlag, to show that a pointer addition SDNode implements an inbounds getelementptr operation (i.e., the pointer operand is in bounds wrt. the allocated object it is based on, and the arithmetic does not change that). The flag is set in the DAG construction when lowering inbounds GEPs. Inbounds information is useful in the ISel when selecting memory instructions that perform address computations whose intermediate steps must be in the same memory region as the final result. A follow-up patch will start using it for AMDGPU's flat memory instructions, where the immediate offset must not affect the memory aperture of the address. A similar patch for gMIR and GlobalISel will follow. For SWDEV-516125. --- llvm/include/llvm/CodeGen/SelectionDAGNodes.h| 9 +++-- llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp| 3 +++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp | 3 +++ .../CodeGen/X86/merge-store-partially-alias-loads.ll | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h index 2283f99202e2f..13ac65f5d731c 100644 --- a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h +++ b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h @@ -415,12 +415,15 @@ struct SDNodeFlags { Unpredictable = 1 << 13, // Compare instructions which may carry the samesign flag. SameSign = 1 << 14, +// Pointer arithmetic instructions that remain in bounds, e.g., implementing +// an inbounds GEP. +InBounds = 1 << 15, // NOTE: Please update LargestValue in LLVM_DECLARE_ENUM_AS_BITMASK below // the class definition when adding new flags. PoisonGeneratingFlags = NoUnsignedWrap | NoSignedWrap | Exact | Disjoint | -NonNeg | NoNaNs | NoInfs | SameSign, +NonNeg | NoNaNs | NoInfs | SameSign | InBounds, FastMathFlags = NoNaNs | NoInfs | NoSignedZeros | AllowReciprocal | AllowContract | ApproximateFuncs | AllowReassociation, }; @@ -455,6 +458,7 @@ struct SDNodeFlags { void setAllowReassociation(bool b) { setFlag(b); } void setNoFPExcept(bool b) { setFlag(b); } void setUnpredictable(bool b) { setFlag(b); } + void setInBounds(bool b) { setFlag(b); } // These are accessors for each flag. bool hasNoUnsignedWrap() const { return Flags & NoUnsignedWrap; } @@ -472,6 +476,7 @@ struct SDNodeFlags { bool hasAllowReassociation() const { return Flags & AllowReassociation; } bool hasNoFPExcept() const { return Flags & NoFPExcept; } bool hasUnpredictable() const { return Flags & Unpredictable; } + bool hasInBounds() const { return Flags & InBounds; } bool operator==(const SDNodeFlags &Other) const { return Flags == Other.Flags; @@ -481,7 +486,7 @@ struct SDNodeFlags { }; LLVM_DECLARE_ENUM_AS_BITMASK(decltype(SDNodeFlags::None), - SDNodeFlags::SameSign); + SDNodeFlags::InBounds); inline SDNodeFlags operator|(SDNodeFlags LHS, SDNodeFlags RHS) { LHS |= RHS; diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index 89793c30f3710..32973be608937 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -4283,6 +4283,7 @@ void SelectionDAGBuilder::visitGetElementPtr(const User &I) { if (NW.hasNoUnsignedWrap() || (int64_t(Offset) >= 0 && NW.hasNoUnsignedSignedWrap())) Flags |= SDNodeFlags::NoUnsignedWrap; +Flags.setInBounds(NW.isInBounds()); N = DAG.getNode(ISD::ADD, dl, N.getValueType(), N, DAG.getConstant(Offset, dl, N.getValueType()), Flags); @@ -4326,6 +4327,7 @@ void SelectionDAGBuilder::visitGetElementPtr(const User &I) { if (NW.hasNoUnsignedWrap() || (Offs.isNonNegative() && NW.hasNoUnsignedSignedWrap())) Flags.setNoUnsignedWrap(true); +Flags.setInBounds(NW.isInBounds()); OffsVal = DAG.getSExtOrTrunc(OffsVal, dl, N.getValueType()); @@ -4388,6 +4390,7 @@ void SelectionDAGBuilder::visitGetElementPtr(const User &I) { // pointer index type (add nuw). SDNodeFlags AddFlags; AddFlags.setNoUnsignedWrap(NW.hasNoUnsignedWrap()); + AddFlags.setInBounds(NW.isInBounds()); N = DAG.getNode(ISD::ADD, dl, N.getValueType(), N, IdxN, AddFlags); } diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp ind
[llvm-branch-commits] [llvm] [LoopInterchange] Improve profitability check for vectorization (PR #133672)
kasuga-fj wrote: Depends on #133667 https://github.com/llvm/llvm-project/pull/133672 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] release/20.x: [flang] Fix missed case of symbol renaming in module file generation (#132475) (PR #133223)
https://github.com/eugeneepshteyn approved this pull request. https://github.com/llvm/llvm-project/pull/133223 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] release/20.x: [flang] Fix missed case of symbol renaming in module file generation (#132475) (PR #133223)
https://github.com/pawosm-arm updated https://github.com/llvm/llvm-project/pull/133223 >From 78b0eb25e001071d7793bd8f253c3d2efc5cbf0a Mon Sep 17 00:00:00 2001 From: Peter Klausler Date: Wed, 26 Mar 2025 12:09:38 -0700 Subject: [PATCH] [flang] Fix missed case of symbol renaming in module file generation (#132475) The map of symbols requiring new local aliases for USE association needs to use the symbols' ultimate resolutions to avoid missing cases that can arise in convoluted codes with lots of confusing renamings. Fixes https://github.com/llvm/llvm-project/issues/132435. (cherry picked from commit 6df27dd42d827a2468dcf4b4b1ee1a8e8af1a408) --- flang/lib/Evaluate/formatting.cpp | 3 +- flang/lib/Semantics/mod-file.cpp | 2 +- flang/test/Semantics/bug132435.f90 | 85 ++ 3 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 flang/test/Semantics/bug132435.f90 diff --git a/flang/lib/Evaluate/formatting.cpp b/flang/lib/Evaluate/formatting.cpp index f3a53c1f983df..cf0b43bc94c36 100644 --- a/flang/lib/Evaluate/formatting.cpp +++ b/flang/lib/Evaluate/formatting.cpp @@ -129,7 +129,8 @@ llvm::raw_ostream &Constant>::AsFortran( llvm::raw_ostream &EmitVar(llvm::raw_ostream &o, const Symbol &symbol, std::optional name = std::nullopt) { const auto &renamings{symbol.owner().context().moduleFileOutputRenamings()}; - if (auto iter{renamings.find(&symbol)}; iter != renamings.end()) { + if (auto iter{renamings.find(&symbol.GetUltimate())}; + iter != renamings.end()) { return o << iter->second.ToString(); } else if (name) { return o << name->ToString(); diff --git a/flang/lib/Semantics/mod-file.cpp b/flang/lib/Semantics/mod-file.cpp index b45f1c060da2f..ea3eae8468b50 100644 --- a/flang/lib/Semantics/mod-file.cpp +++ b/flang/lib/Semantics/mod-file.cpp @@ -346,7 +346,7 @@ void ModFileWriter::PrepareRenamings(const Scope &scope) { uses_ << DEREF(sMod->symbol()).name() << ",only:"; if (rename != s->name()) { uses_ << rename << "=>"; - renamings.emplace(&*s, rename); + renamings.emplace(&s->GetUltimate(), rename); } uses_ << s->name() << '\n'; useExtraAttrs_ << "private::" << rename << '\n'; diff --git a/flang/test/Semantics/bug132435.f90 b/flang/test/Semantics/bug132435.f90 new file mode 100644 index 0..be8b661fcf6cc --- /dev/null +++ b/flang/test/Semantics/bug132435.f90 @@ -0,0 +1,85 @@ +! RUN: %python %S/test_modfile.py %s %flang_fc1 +module m1 + type foo +integer :: c1 = 123 + end type +end + +module m2 + use m1, only: foo + type baz +type(foo) :: d = foo() + end type + type bar +type(baz) :: e = baz() + end type +end + +module m3 + use m1, only: m1foo => foo + type foo +type(m1foo), private :: c2 = m1foo() + end type +end + +module m4 + use m2, only: m3foo => foo + type foo +type(m3foo), private :: c3 = m3foo() + end type +end + +module m5 + use m2, only: m2bar => bar + use m4, only: foo + type blah +type(m2bar) :: f = m2bar() + end type +end + +!Expect: m1.mod +!module m1 +!type::foo +!integer(4)::c1=123_4 +!end type +!end + +!Expect: m2.mod +!module m2 +!use m1,only:foo +!type::baz +!type(foo)::d=foo(c1=123_4) +!end type +!type::bar +!type(baz)::e=baz(d=foo(c1=123_4)) +!end type +!end + +!Expect: m3.mod +!module m3 +!use m1,only:m1foo=>foo +!type::foo +!type(m1foo),private::c2=m1foo(c1=123_4) +!end type +!end + +!Expect: m4.mod +!module m4 +!use m2,only:m3foo=>foo +!type::foo +!type(m3foo),private::c3=m3foo(c1=123_4) +!end type +!end + +!Expect: m5.mod +!module m5 +!use m2,only:m2$foo=>foo +!use m2,only:baz +!use m2,only:m2bar=>bar +!use m4,only:foo +!private::m2$foo +!private::baz +!type::blah +!type(m2bar)::f=m2bar(e=baz(d=m2$foo(c1=123_4))) +!end type +!end ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [PowerPC] Support conversion between f16 and f128 (#130158) (PR #133279)
https://github.com/lei137 updated https://github.com/llvm/llvm-project/pull/133279 >From 9cb7ed36484774b012b8e17c79fccc161c36d116 Mon Sep 17 00:00:00 2001 From: Lei Huang Date: Thu, 27 Mar 2025 17:27:45 + Subject: [PATCH] update test due to https://github.com/llvm/llvm-project/pull/126880 not being backported --- llvm/test/CodeGen/PowerPC/f128-conv.ll | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/test/CodeGen/PowerPC/f128-conv.ll b/llvm/test/CodeGen/PowerPC/f128-conv.ll index f8b2861156db4..1a51ca64177a0 100644 --- a/llvm/test/CodeGen/PowerPC/f128-conv.ll +++ b/llvm/test/CodeGen/PowerPC/f128-conv.ll @@ -1365,7 +1365,7 @@ define half @trunc(fp128 %a) nounwind { ; CHECK-P8-NEXT:bl __trunckfhf2 ; CHECK-P8-NEXT:nop ; CHECK-P8-NEXT:clrldi r3, r3, 48 -; CHECK-P8-NEXT:bl __extendhfsf2 +; CHECK-P8-NEXT:bl __gnu_h2f_ieee ; CHECK-P8-NEXT:nop ; CHECK-P8-NEXT:addi r1, r1, 32 ; CHECK-P8-NEXT:ld r0, 16(r1) ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/20.x: [ARM] Speedups for CombineBaseUpdate. (#129725) (PR #130035)
https://github.com/DanielKristofKiss approved this pull request. LGMT https://github.com/llvm/llvm-project/pull/130035 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [LoopInterchange] Fix the vectorizable check for a loop (PR #133667)
kasuga-fj wrote: Depends on #133665 https://github.com/llvm/llvm-project/pull/133667 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] llvm-reduce: Preserve uselistorder when writing thinlto bitcode (PR #133369)
https://github.com/teresajohnson approved this pull request. lgtm but please remove the FIXME for the reason noted below https://github.com/llvm/llvm-project/pull/133369 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [LV] Reduce register usage for scaled reductions (PR #133090)
https://github.com/SamTebbs33 updated https://github.com/llvm/llvm-project/pull/133090 >From 6193c2c846710472c7e604ef33a15cda18771328 Mon Sep 17 00:00:00 2001 From: Samuel Tebbs Date: Wed, 26 Mar 2025 14:01:59 + Subject: [PATCH 1/3] [LV] Reduce register usage for scaled reductions --- .../Transforms/Vectorize/LoopVectorize.cpp| 24 +- .../Transforms/Vectorize/VPRecipeBuilder.h| 3 +- llvm/lib/Transforms/Vectorize/VPlan.h | 14 +- .../partial-reduce-dot-product-neon.ll| 60 ++- .../AArch64/partial-reduce-dot-product.ll | 414 ++ 5 files changed, 495 insertions(+), 20 deletions(-) diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index c9f314c0ba481..da701ef9ff1a2 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -5026,10 +5026,23 @@ calculateRegisterUsage(VPlan &Plan, ArrayRef VFs, // even in the scalar case. RegUsage[ClassID] += 1; } else { +// The output from scaled phis and scaled reductions actually have +// fewer lanes than the VF. +auto VF = VFs[J]; +if (auto *ReductionR = dyn_cast(R)) + VF = VF.divideCoefficientBy(ReductionR->getVFScaleFactor()); +else if (auto *PartialReductionR = + dyn_cast(R)) + VF = VF.divideCoefficientBy(PartialReductionR->getScaleFactor()); +if (VF != VFs[J]) + LLVM_DEBUG(dbgs() << "LV(REG): Scaled down VF from " << VFs[J] +<< " to " << VF << " for "; + R->dump();); + for (VPValue *DefV : R->definedValues()) { Type *ScalarTy = TypeInfo.inferScalarType(DefV); unsigned ClassID = TTI.getRegisterClassForType(true, ScalarTy); - RegUsage[ClassID] += GetRegUsage(ScalarTy, VFs[J]); + RegUsage[ClassID] += GetRegUsage(ScalarTy, VF); } } } @@ -8963,8 +8976,8 @@ VPRecipeBase *VPRecipeBuilder::tryToCreateWidenRecipe( if (isa(Instr) || isa(Instr)) return tryToWidenMemory(Instr, Operands, Range); - if (getScalingForReduction(Instr)) -return tryToCreatePartialReduction(Instr, Operands); + if (auto ScaleFactor = getScalingForReduction(Instr)) +return tryToCreatePartialReduction(Instr, Operands, ScaleFactor.value()); if (!shouldWiden(Instr, Range)) return nullptr; @@ -8988,7 +9001,8 @@ VPRecipeBase *VPRecipeBuilder::tryToCreateWidenRecipe( VPRecipeBase * VPRecipeBuilder::tryToCreatePartialReduction(Instruction *Reduction, - ArrayRef Operands) { + ArrayRef Operands, + unsigned ScaleFactor) { assert(Operands.size() == 2 && "Unexpected number of operands for partial reduction"); @@ -9021,7 +9035,7 @@ VPRecipeBuilder::tryToCreatePartialReduction(Instruction *Reduction, BinOp = Builder.createSelect(Mask, BinOp, Zero, Reduction->getDebugLoc()); } return new VPPartialReductionRecipe(ReductionOpcode, BinOp, Accumulator, - Reduction); + ScaleFactor, Reduction); } void LoopVectorizationPlanner::buildVPlansWithVPRecipes(ElementCount MinVF, diff --git a/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h b/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h index 334cfbad8bd7c..fd0064a34c4c9 100644 --- a/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h +++ b/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h @@ -178,7 +178,8 @@ class VPRecipeBuilder { /// Create and return a partial reduction recipe for a reduction instruction /// along with binary operation and reduction phi operands. VPRecipeBase *tryToCreatePartialReduction(Instruction *Reduction, -ArrayRef Operands); +ArrayRef Operands, +unsigned ScaleFactor); /// Set the recipe created for given ingredient. void setRecipe(Instruction *I, VPRecipeBase *R) { diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h index 80b3d2a760293..d84efb1bd6850 100644 --- a/llvm/lib/Transforms/Vectorize/VPlan.h +++ b/llvm/lib/Transforms/Vectorize/VPlan.h @@ -2001,6 +2001,8 @@ class VPReductionPHIRecipe : public VPHeaderPHIRecipe, /// Generate the phi/select nodes. void execute(VPTransformState &State) override; + unsigned getVFScaleFactor() const { return VFScaleFactor; } + #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) /// Print the recipe. void print(raw_ostream &O, const Twine &Indent, @@ -2031,17 +2033,19 @@ class VPReductionPHIRecipe : public VPHeaderPHIRecipe, /// scalar value. class VPPartialR
[llvm-branch-commits] [llvm] [AMDGPU][SDAG] Only fold flat offsets if they are inbounds (PR #132353)
https://github.com/ritter-x2a updated https://github.com/llvm/llvm-project/pull/132353 >From a8155cf5b7847a041be8d4252b20cae01d305404 Mon Sep 17 00:00:00 2001 From: Fabian Ritter Date: Fri, 21 Mar 2025 03:33:02 -0400 Subject: [PATCH] [AMDGPU][SDAG] Only fold flat offsets if they are inbounds For flat memory instructions where the address is supplied as a base address register with an immediate offset, the memory aperture test ignores the immediate offset. Currently, ISel does not respect that, which leads to miscompilations where valid input programs crash when the address computation relies on the immediate offset to get the base address in the proper memory aperture. Global or scratch instructions are not affected. This patch only selects flat instructions with immediate offsets from address computations with the inbounds flag: If the address computation does not leave the bounds of the allocated object, it cannot leave the bounds of the memory aperture and is therefore safe to handle with an immediate offset. It also adds the inbounds flag to DAG nodes resulting from transformations: - Address computations resulting from getObjectPtrOffset. As far as I can tell, this function is only used to compute addresses within accessed memory ranges, e.g., for loads and stores that are split during legalization. - Reassociated inbounds adds. If both involved operations are inbounds, then so are operations after the transformation. - Address computations in the SelectionDAG lowering of the memcpy/move/set intrinsics. Base and result of the address arithmetic there are accessed, so the operation must be inbounds. It might make sense to separate these changes into their own PR, but I don't see a way to test them without adding a use of the inbounds SDAG flag. Affected tests: - CodeGen/AMDGPU/fold-gep-offset.ll: Offsets are no longer wrongly folded, added new positive tests where we still do fold them. - Transforms/InferAddressSpaces/AMDGPU/flat_atomic.ll: Offset folding doesn't seem integral to this test, so the test is not changed to make offset folding still happen. - CodeGen/AMDGPU/loop-prefetch-data.ll: loop-reduce prefers to base addresses on the potentially OOB addresses used for prefetching for memory accesses, that might be a separate issue to look into. - Added memset tests to CodeGen/AMDGPU/memintrinsic-unroll.ll to make sure that offsets in the memset DAG lowering are still folded properly. A similar patch for GlobalISel will follow. Fixes SWDEV-516125. --- llvm/include/llvm/CodeGen/SelectionDAG.h | 12 +- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 9 +- .../lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 12 +- llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp | 140 --- llvm/test/CodeGen/AMDGPU/fold-gep-offset.ll | 374 +- .../test/CodeGen/AMDGPU/loop-prefetch-data.ll | 17 +- .../CodeGen/AMDGPU/memintrinsic-unroll.ll | 241 +++ .../InferAddressSpaces/AMDGPU/flat_atomic.ll | 6 +- 8 files changed, 717 insertions(+), 94 deletions(-) diff --git a/llvm/include/llvm/CodeGen/SelectionDAG.h b/llvm/include/llvm/CodeGen/SelectionDAG.h index 15a2370e5d8b8..aa3668d3e9aae 100644 --- a/llvm/include/llvm/CodeGen/SelectionDAG.h +++ b/llvm/include/llvm/CodeGen/SelectionDAG.h @@ -1069,7 +1069,8 @@ class SelectionDAG { SDValue EVL); /// Returns sum of the base pointer and offset. - /// Unlike getObjectPtrOffset this does not set NoUnsignedWrap by default. + /// Unlike getObjectPtrOffset this does not set NoUnsignedWrap and InBounds by + /// default. SDValue getMemBasePlusOffset(SDValue Base, TypeSize Offset, const SDLoc &DL, const SDNodeFlags Flags = SDNodeFlags()); SDValue getMemBasePlusOffset(SDValue Base, SDValue Offset, const SDLoc &DL, @@ -1077,15 +1078,18 @@ class SelectionDAG { /// Create an add instruction with appropriate flags when used for /// addressing some offset of an object. i.e. if a load is split into multiple - /// components, create an add nuw from the base pointer to the offset. + /// components, create an add nuw inbounds from the base pointer to the + /// offset. SDValue getObjectPtrOffset(const SDLoc &SL, SDValue Ptr, TypeSize Offset) { -return getMemBasePlusOffset(Ptr, Offset, SL, SDNodeFlags::NoUnsignedWrap); +return getMemBasePlusOffset( +Ptr, Offset, SL, SDNodeFlags::NoUnsignedWrap | SDNodeFlags::InBounds); } SDValue getObjectPtrOffset(const SDLoc &SL, SDValue Ptr, SDValue Offset) { // The object itself can't wrap around the address space, so it shouldn't be // possible for the adds of the offsets to the split parts to overflow. -return getMemBasePlusOffset(Ptr, Offset, SL, SDNodeFlags::NoUnsignedWrap); +return getMemBasePlusOffset( +Ptr, Offset, SL, SDNodeFlags::NoUnsignedWrap | SDNodeFlags::InBounds); } /// Return a new CALLSEQ_START node, that starts new call fram
[llvm-branch-commits] [llvm] [SDAG] Introduce inbounds flag for pointer arithmetic (PR #131862)
https://github.com/ritter-x2a updated https://github.com/llvm/llvm-project/pull/131862 >From ee21919269e84f95b07c65c90937cc13d25202ad Mon Sep 17 00:00:00 2001 From: Fabian Ritter Date: Mon, 17 Mar 2025 06:51:16 -0400 Subject: [PATCH] [SDAG] Introduce inbounds flag for pointer arithmetic This patch introduces an inbounds SDNodeFlag, to show that a pointer addition SDNode implements an inbounds getelementptr operation (i.e., the pointer operand is in bounds wrt. the allocated object it is based on, and the arithmetic does not change that). The flag is set in the DAG construction when lowering inbounds GEPs. Inbounds information is useful in the ISel when selecting memory instructions that perform address computations whose intermediate steps must be in the same memory region as the final result. A follow-up patch will start using it for AMDGPU's flat memory instructions, where the immediate offset must not affect the memory aperture of the address. A similar patch for gMIR and GlobalISel will follow. For SWDEV-516125. --- llvm/include/llvm/CodeGen/SelectionDAGNodes.h| 9 +++-- llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp| 3 +++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp | 3 +++ .../CodeGen/X86/merge-store-partially-alias-loads.ll | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h index 2283f99202e2f..13ac65f5d731c 100644 --- a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h +++ b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h @@ -415,12 +415,15 @@ struct SDNodeFlags { Unpredictable = 1 << 13, // Compare instructions which may carry the samesign flag. SameSign = 1 << 14, +// Pointer arithmetic instructions that remain in bounds, e.g., implementing +// an inbounds GEP. +InBounds = 1 << 15, // NOTE: Please update LargestValue in LLVM_DECLARE_ENUM_AS_BITMASK below // the class definition when adding new flags. PoisonGeneratingFlags = NoUnsignedWrap | NoSignedWrap | Exact | Disjoint | -NonNeg | NoNaNs | NoInfs | SameSign, +NonNeg | NoNaNs | NoInfs | SameSign | InBounds, FastMathFlags = NoNaNs | NoInfs | NoSignedZeros | AllowReciprocal | AllowContract | ApproximateFuncs | AllowReassociation, }; @@ -455,6 +458,7 @@ struct SDNodeFlags { void setAllowReassociation(bool b) { setFlag(b); } void setNoFPExcept(bool b) { setFlag(b); } void setUnpredictable(bool b) { setFlag(b); } + void setInBounds(bool b) { setFlag(b); } // These are accessors for each flag. bool hasNoUnsignedWrap() const { return Flags & NoUnsignedWrap; } @@ -472,6 +476,7 @@ struct SDNodeFlags { bool hasAllowReassociation() const { return Flags & AllowReassociation; } bool hasNoFPExcept() const { return Flags & NoFPExcept; } bool hasUnpredictable() const { return Flags & Unpredictable; } + bool hasInBounds() const { return Flags & InBounds; } bool operator==(const SDNodeFlags &Other) const { return Flags == Other.Flags; @@ -481,7 +486,7 @@ struct SDNodeFlags { }; LLVM_DECLARE_ENUM_AS_BITMASK(decltype(SDNodeFlags::None), - SDNodeFlags::SameSign); + SDNodeFlags::InBounds); inline SDNodeFlags operator|(SDNodeFlags LHS, SDNodeFlags RHS) { LHS |= RHS; diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index 89793c30f3710..32973be608937 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -4283,6 +4283,7 @@ void SelectionDAGBuilder::visitGetElementPtr(const User &I) { if (NW.hasNoUnsignedWrap() || (int64_t(Offset) >= 0 && NW.hasNoUnsignedSignedWrap())) Flags |= SDNodeFlags::NoUnsignedWrap; +Flags.setInBounds(NW.isInBounds()); N = DAG.getNode(ISD::ADD, dl, N.getValueType(), N, DAG.getConstant(Offset, dl, N.getValueType()), Flags); @@ -4326,6 +4327,7 @@ void SelectionDAGBuilder::visitGetElementPtr(const User &I) { if (NW.hasNoUnsignedWrap() || (Offs.isNonNegative() && NW.hasNoUnsignedSignedWrap())) Flags.setNoUnsignedWrap(true); +Flags.setInBounds(NW.isInBounds()); OffsVal = DAG.getSExtOrTrunc(OffsVal, dl, N.getValueType()); @@ -4388,6 +4390,7 @@ void SelectionDAGBuilder::visitGetElementPtr(const User &I) { // pointer index type (add nuw). SDNodeFlags AddFlags; AddFlags.setNoUnsignedWrap(NW.hasNoUnsignedWrap()); + AddFlags.setInBounds(NW.isInBounds()); N = DAG.getNode(ISD::ADD, dl, N.getValueType(), N, IdxN, AddFlags); } diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp ind
[llvm-branch-commits] [llvm] [BOLT] Gadget scanner: Detect address materialization and arithmetics (PR #132540)
@@ -587,6 +587,22 @@ class MCPlusBuilder { return getNoRegister(); } + virtual MCPhysReg getSafelyMaterializedAddressReg(const MCInst &Inst) const { +llvm_unreachable("not implemented"); +return getNoRegister(); + } kbeyls wrote: I think that "safely materialized address register" is not a common term and different people seeing it are likely to have somewhat different guesses at what it might mean. Therefore, this method probably needs a comment that explains what a "safely materialized address register" is. https://github.com/llvm/llvm-project/pull/132540 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Gadget scanner: Detect address materialization and arithmetics (PR #132540)
@@ -335,6 +335,50 @@ class PacRetAnalysis }); } + BitVector getClobberedRegs(const MCInst &Point) const { +BitVector Clobbered(NumRegs, false); +// Assume a call can clobber all registers, including callee-saved +// registers. There's a good chance that callee-saved registers will be +// saved on the stack at some point during execution of the callee. +// Therefore they should also be considered as potentially modified by an +// attacker/written to. +// Also, not all functions may respect the AAPCS ABI rules about +// caller/callee-saved registers. +if (BC.MIB->isCall(Point)) + Clobbered.set(); +else + BC.MIB->getClobberedRegs(Point, Clobbered); +return Clobbered; + } + + // Returns all registers that can be treated as if they are written by an + // authentication instruction. + SmallVector getAuthenticatedRegs(const MCInst &Point, kbeyls wrote: Since this function is being changed to no longer return strictly only the registers that are authenticated by the instruction in `Point`, I think it would be best to adjust the name of this function accordingly. I'm not sure I can easily come up with a better name. Would any of the following names be better? - `getSafeToDerefRegs` - `getNonAttackerControlledRegs` or maybe - `getSafeRegsWrittenBy` (since this method only returns registers written by `Point`?) https://github.com/llvm/llvm-project/pull/132540 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Gadget scanner: Detect address materialization and arithmetics (PR #132540)
@@ -587,6 +587,22 @@ class MCPlusBuilder { return getNoRegister(); } + virtual MCPhysReg getSafelyMaterializedAddressReg(const MCInst &Inst) const { +llvm_unreachable("not implemented"); +return getNoRegister(); + } + + /// Analyzes if this instruction can safely perform address arithmetics. kbeyls wrote: Similar here, I think a definition is needed for what "safely performing address arithmetics" means here. I'm assuming that "safe" here is in the context of a particular threat model. Different threat models may require different definitions of "safe". In other words, what is "safe" under one threat model, might not be safe under another threat model. I think that the threat model should be described as accurately as possible in at least the comment documenting these methods. Is my guess correct that roughly the threat model is "The assumption is that values stored in data memory are 'unsafe', because the attackers under our threat model (question: can we point to a written up threat model somewhere?) are assumed to be able to change values in writeable data memory. In contrast, values in code memory or in registers are assumed to not be changeable by an attacker". https://github.com/llvm/llvm-project/pull/132540 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Gadget scanner: Detect address materialization and arithmetics (PR #132540)
@@ -1,7 +1,8 @@ if "AArch64" not in config.root.targets: config.unsupported = True -flags = "--target=aarch64-linux-gnu -nostartfiles -nostdlib -ffreestanding" +# -Wl,--no-relax prevents converting ADRP+ADD pairs into NOP+ADR. +flags = "--target=aarch64-linux-gnu -nostartfiles -nostdlib -ffreestanding -Wl,--no-relax" kbeyls wrote: I'm not entirely sure, but maybe we should only add `-Wl,--no-relax` to test case gs-pauth-address-materialization.s (and other test cases that require it in the future)? If we add too many special flags to the default flags for all the binary analysis test cases, we might end up running all test cases accidentally under some flags that are too far removed from the typical flags used to build production software? https://github.com/llvm/llvm-project/pull/132540 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Gadget scanner: Detect address materialization and arithmetics (PR #132540)
@@ -355,37 +399,39 @@ class PacRetAnalysis return State(); } +// First, compute various properties of the instruction, taking the state +// before its execution into account, if necessary. + +BitVector Clobbered = getClobberedRegs(Point); +// Compute the set of registers that can be considered as written by +// an authentication instruction. This includes operations that are +// *strictly better* than authentication, such as materializing a +// PC-relative constant. kbeyls wrote: See my comment above, I hope we can come up with a better name than `AuthenticatedOrBetter`. https://github.com/llvm/llvm-project/pull/132540 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] ELF: Add support for R_AARCH64_INST32 relocation. (PR #133534)
smithp35 wrote: Apologies for the delay in responding, just come back from vacation. Not had a chance to look through the Discourse posts yet, will do so this week. While it may seem a bit premature, would you be able to open an issue in the AArch64 ABI (https://github.com/ARM-software/abi-aa/issues) with a request to add a new relocation directive, citing the Discourse posts and PRs? https://github.com/llvm/llvm-project/pull/133534 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [LV] Reduce register usage for scaled reductions (PR #133090)
@@ -5026,10 +5026,23 @@ calculateRegisterUsage(VPlan &Plan, ArrayRef VFs, // even in the scalar case. RegUsage[ClassID] += 1; } else { +// The output from scaled phis and scaled reductions actually have +// fewer lanes than the VF. +auto VF = VFs[J]; +if (auto *ReductionR = dyn_cast(R)) + VF = VF.divideCoefficientBy(ReductionR->getVFScaleFactor()); +else if (auto *PartialReductionR = + dyn_cast(R)) + VF = VF.divideCoefficientBy(PartialReductionR->getScaleFactor()); +if (VF != VFs[J]) SamTebbs33 wrote: Done. https://github.com/llvm/llvm-project/pull/133090 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [clang-tools-extra] [libcxx] [clang] improved preservation of template keyword (PR #133610)
mizvekov wrote: @zwuis thanks for finding these. I removed that assertion because it was not relevant anymore at that point where it existed. However, we should still not have an ElaboratedType in a NestedNameSpecifier, although this patch moves us in the direction where that will not be the case anymore. https://github.com/llvm/llvm-project/pull/133610 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Gadget scanner: analyze functions without CFG information (PR #133461)
https://github.com/atrosinenko updated https://github.com/llvm/llvm-project/pull/133461 >From 4572e7635d2cd9a7d00c3d0f332eec6c35cdf10b Mon Sep 17 00:00:00 2001 From: Anatoly Trosinenko Date: Wed, 19 Mar 2025 18:58:32 +0300 Subject: [PATCH 1/2] [BOLT] Gadget scanner: analyze functions without CFG information Support simple analysis of the functions for which BOLT is unable to reconstruct the CFG. This patch is inspired by the approach implemented by Kristof Beyls in the original prototype of gadget scanner, but a CFG-unaware counterpart of the data-flow analysis is implemented instead of separate version of gadget detector, as multiple gadget kinds are detected now. --- bolt/include/bolt/Core/BinaryFunction.h | 13 + bolt/include/bolt/Passes/PAuthGadgetScanner.h | 24 + bolt/lib/Passes/PAuthGadgetScanner.cpp| 266 +--- .../AArch64/gs-pacret-autiasp.s | 15 + .../binary-analysis/AArch64/gs-pauth-calls.s | 594 ++ 5 files changed, 835 insertions(+), 77 deletions(-) diff --git a/bolt/include/bolt/Core/BinaryFunction.h b/bolt/include/bolt/Core/BinaryFunction.h index a92cb466c5992..b57fe1e4d35d9 100644 --- a/bolt/include/bolt/Core/BinaryFunction.h +++ b/bolt/include/bolt/Core/BinaryFunction.h @@ -793,6 +793,19 @@ class BinaryFunction { return iterator_range(cie_begin(), cie_end()); } + /// Iterate over instructions (only if CFG is unavailable or not built yet). + iterator_range instrs() { +assert(!hasCFG() && "Iterate over basic blocks instead"); +return make_range(Instructions.begin(), Instructions.end()); + } + iterator_range instrs() const { +assert(!hasCFG() && "Iterate over basic blocks instead"); +return make_range(Instructions.begin(), Instructions.end()); + } + + /// Returns whether there are any labels at Offset. + bool hasLabelAt(unsigned Offset) const { return Labels.count(Offset) != 0; } + /// Iterate over all jump tables associated with this function. iterator_range::const_iterator> jumpTables() const { diff --git a/bolt/include/bolt/Passes/PAuthGadgetScanner.h b/bolt/include/bolt/Passes/PAuthGadgetScanner.h index 622e6721dea55..aa44f8c565639 100644 --- a/bolt/include/bolt/Passes/PAuthGadgetScanner.h +++ b/bolt/include/bolt/Passes/PAuthGadgetScanner.h @@ -67,6 +67,14 @@ struct MCInstInBFReference { uint64_t Offset; MCInstInBFReference(BinaryFunction *BF, uint64_t Offset) : BF(BF), Offset(Offset) {} + + static MCInstInBFReference get(const MCInst *Inst, BinaryFunction &BF) { +for (auto &I : BF.instrs()) + if (Inst == &I.second) +return MCInstInBFReference(&BF, I.first); +return {}; + } + MCInstInBFReference() : BF(nullptr), Offset(0) {} bool operator==(const MCInstInBFReference &RHS) const { return BF == RHS.BF && Offset == RHS.Offset; @@ -106,6 +114,12 @@ struct MCInstReference { MCInstReference(BinaryFunction *BF, uint32_t Offset) : MCInstReference(MCInstInBFReference(BF, Offset)) {} + static MCInstReference get(const MCInst *Inst, BinaryFunction &BF) { +if (BF.hasCFG()) + return MCInstInBBReference::get(Inst, BF); +return MCInstInBFReference::get(Inst, BF); + } + bool operator<(const MCInstReference &RHS) const { if (ParentKind != RHS.ParentKind) return ParentKind < RHS.ParentKind; @@ -140,6 +154,16 @@ struct MCInstReference { llvm_unreachable(""); } + operator bool() const { +switch (ParentKind) { +case BasicBlockParent: + return U.BBRef.BB != nullptr; +case FunctionParent: + return U.BFRef.BF != nullptr; +} +llvm_unreachable(""); + } + uint64_t getAddress() const { switch (ParentKind) { case BasicBlockParent: diff --git a/bolt/lib/Passes/PAuthGadgetScanner.cpp b/bolt/lib/Passes/PAuthGadgetScanner.cpp index 86897937c95fe..bce279a4beed9 100644 --- a/bolt/lib/Passes/PAuthGadgetScanner.cpp +++ b/bolt/lib/Passes/PAuthGadgetScanner.cpp @@ -124,6 +124,27 @@ class TrackedRegisters { } }; +// Without CFG, we reset gadget scanning state when encountering an +// unconditional branch. Note that BC.MIB->isUnconditionalBranch neither +// considers indirect branches nor annotated tail calls as unconditional. +static bool isStateTrackingBoundary(const BinaryContext &BC, +const MCInst &Inst) { + const MCInstrDesc &Desc = BC.MII->get(Inst.getOpcode()); + // Adapted from llvm::MCInstrDesc::isUnconditionalBranch(). + return Desc.isBranch() && Desc.isBarrier(); +} + +template static void iterateOverInstrs(BinaryFunction &BF, T Fn) { + if (BF.hasCFG()) { +for (BinaryBasicBlock &BB : BF) + for (int64_t I = 0, E = BB.size(); I < E; ++I) +Fn(MCInstInBBReference(&BB, I)); + } else { +for (auto I : BF.instrs()) + Fn(MCInstInBFReference(&BF, I.first)); + } +} + // The security property that is checked is: // When a register is used as the address to jump to in a return instruction, // that register mus
[llvm-branch-commits] [llvm] [BOLT] Gadget scanner: analyze functions without CFG information (PR #133461)
https://github.com/atrosinenko updated https://github.com/llvm/llvm-project/pull/133461 >From 4572e7635d2cd9a7d00c3d0f332eec6c35cdf10b Mon Sep 17 00:00:00 2001 From: Anatoly Trosinenko Date: Wed, 19 Mar 2025 18:58:32 +0300 Subject: [PATCH 1/2] [BOLT] Gadget scanner: analyze functions without CFG information Support simple analysis of the functions for which BOLT is unable to reconstruct the CFG. This patch is inspired by the approach implemented by Kristof Beyls in the original prototype of gadget scanner, but a CFG-unaware counterpart of the data-flow analysis is implemented instead of separate version of gadget detector, as multiple gadget kinds are detected now. --- bolt/include/bolt/Core/BinaryFunction.h | 13 + bolt/include/bolt/Passes/PAuthGadgetScanner.h | 24 + bolt/lib/Passes/PAuthGadgetScanner.cpp| 266 +--- .../AArch64/gs-pacret-autiasp.s | 15 + .../binary-analysis/AArch64/gs-pauth-calls.s | 594 ++ 5 files changed, 835 insertions(+), 77 deletions(-) diff --git a/bolt/include/bolt/Core/BinaryFunction.h b/bolt/include/bolt/Core/BinaryFunction.h index a92cb466c5992..b57fe1e4d35d9 100644 --- a/bolt/include/bolt/Core/BinaryFunction.h +++ b/bolt/include/bolt/Core/BinaryFunction.h @@ -793,6 +793,19 @@ class BinaryFunction { return iterator_range(cie_begin(), cie_end()); } + /// Iterate over instructions (only if CFG is unavailable or not built yet). + iterator_range instrs() { +assert(!hasCFG() && "Iterate over basic blocks instead"); +return make_range(Instructions.begin(), Instructions.end()); + } + iterator_range instrs() const { +assert(!hasCFG() && "Iterate over basic blocks instead"); +return make_range(Instructions.begin(), Instructions.end()); + } + + /// Returns whether there are any labels at Offset. + bool hasLabelAt(unsigned Offset) const { return Labels.count(Offset) != 0; } + /// Iterate over all jump tables associated with this function. iterator_range::const_iterator> jumpTables() const { diff --git a/bolt/include/bolt/Passes/PAuthGadgetScanner.h b/bolt/include/bolt/Passes/PAuthGadgetScanner.h index 622e6721dea55..aa44f8c565639 100644 --- a/bolt/include/bolt/Passes/PAuthGadgetScanner.h +++ b/bolt/include/bolt/Passes/PAuthGadgetScanner.h @@ -67,6 +67,14 @@ struct MCInstInBFReference { uint64_t Offset; MCInstInBFReference(BinaryFunction *BF, uint64_t Offset) : BF(BF), Offset(Offset) {} + + static MCInstInBFReference get(const MCInst *Inst, BinaryFunction &BF) { +for (auto &I : BF.instrs()) + if (Inst == &I.second) +return MCInstInBFReference(&BF, I.first); +return {}; + } + MCInstInBFReference() : BF(nullptr), Offset(0) {} bool operator==(const MCInstInBFReference &RHS) const { return BF == RHS.BF && Offset == RHS.Offset; @@ -106,6 +114,12 @@ struct MCInstReference { MCInstReference(BinaryFunction *BF, uint32_t Offset) : MCInstReference(MCInstInBFReference(BF, Offset)) {} + static MCInstReference get(const MCInst *Inst, BinaryFunction &BF) { +if (BF.hasCFG()) + return MCInstInBBReference::get(Inst, BF); +return MCInstInBFReference::get(Inst, BF); + } + bool operator<(const MCInstReference &RHS) const { if (ParentKind != RHS.ParentKind) return ParentKind < RHS.ParentKind; @@ -140,6 +154,16 @@ struct MCInstReference { llvm_unreachable(""); } + operator bool() const { +switch (ParentKind) { +case BasicBlockParent: + return U.BBRef.BB != nullptr; +case FunctionParent: + return U.BFRef.BF != nullptr; +} +llvm_unreachable(""); + } + uint64_t getAddress() const { switch (ParentKind) { case BasicBlockParent: diff --git a/bolt/lib/Passes/PAuthGadgetScanner.cpp b/bolt/lib/Passes/PAuthGadgetScanner.cpp index 86897937c95fe..bce279a4beed9 100644 --- a/bolt/lib/Passes/PAuthGadgetScanner.cpp +++ b/bolt/lib/Passes/PAuthGadgetScanner.cpp @@ -124,6 +124,27 @@ class TrackedRegisters { } }; +// Without CFG, we reset gadget scanning state when encountering an +// unconditional branch. Note that BC.MIB->isUnconditionalBranch neither +// considers indirect branches nor annotated tail calls as unconditional. +static bool isStateTrackingBoundary(const BinaryContext &BC, +const MCInst &Inst) { + const MCInstrDesc &Desc = BC.MII->get(Inst.getOpcode()); + // Adapted from llvm::MCInstrDesc::isUnconditionalBranch(). + return Desc.isBranch() && Desc.isBarrier(); +} + +template static void iterateOverInstrs(BinaryFunction &BF, T Fn) { + if (BF.hasCFG()) { +for (BinaryBasicBlock &BB : BF) + for (int64_t I = 0, E = BB.size(); I < E; ++I) +Fn(MCInstInBBReference(&BB, I)); + } else { +for (auto I : BF.instrs()) + Fn(MCInstInBFReference(&BF, I.first)); + } +} + // The security property that is checked is: // When a register is used as the address to jump to in a return instruction, // that register mus
[llvm-branch-commits] [llvm] [BOLT] Make DataflowAnalysis::getStateBefore() const (NFC) (PR #133308)
https://github.com/atrosinenko updated https://github.com/llvm/llvm-project/pull/133308 >From 12d4a200bee45399a64fdeaee37f6edd5eee4bfd Mon Sep 17 00:00:00 2001 From: Anatoly Trosinenko Date: Thu, 27 Mar 2025 21:06:55 +0300 Subject: [PATCH] [BOLT] Make DataflowAnalysis::getStateBefore() const (NFC) --- bolt/include/bolt/Passes/DataflowAnalysis.h | 11 +++ bolt/lib/Passes/PAuthGadgetScanner.cpp | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/bolt/include/bolt/Passes/DataflowAnalysis.h b/bolt/include/bolt/Passes/DataflowAnalysis.h index 2afaa6d3043a6..f6ca39cf6f860 100644 --- a/bolt/include/bolt/Passes/DataflowAnalysis.h +++ b/bolt/include/bolt/Passes/DataflowAnalysis.h @@ -292,14 +292,17 @@ class DataflowAnalysis { /// Relies on a ptr map to fetch the previous instruction and then retrieve /// state. WARNING: Watch out for invalidated pointers. Do not use this /// function if you invalidated pointers after the analysis has been completed - ErrorOr getStateBefore(const MCInst &Point) { -return getStateAt(PrevPoint[&Point]); + ErrorOr getStateBefore(const MCInst &Point) const { +auto It = PrevPoint.find(&Point); +if (It == PrevPoint.end()) + return make_error_code(std::errc::result_out_of_range); +return getStateAt(It->getSecond()); } - ErrorOr getStateBefore(ProgramPoint Point) { + ErrorOr getStateBefore(ProgramPoint Point) const { if (Point.isBB()) return getStateAt(*Point.getBB()); -return getStateAt(PrevPoint[Point.getInst()]); +return getStateBefore(*Point.getInst()); } /// Remove any state annotations left by this analysis diff --git a/bolt/lib/Passes/PAuthGadgetScanner.cpp b/bolt/lib/Passes/PAuthGadgetScanner.cpp index 16da08551a34d..86897937c95fe 100644 --- a/bolt/lib/Passes/PAuthGadgetScanner.cpp +++ b/bolt/lib/Passes/PAuthGadgetScanner.cpp @@ -448,7 +448,7 @@ class PacRetAnalysis public: std::vector getLastClobberingInsts(const MCInst &Inst, BinaryFunction &BF, - const ArrayRef UsedDirtyRegs) { + const ArrayRef UsedDirtyRegs) const { if (RegsToTrackInstsFor.empty()) return {}; auto MaybeState = getStateBefore(Inst); ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [BOLT] Gadget scanner: Detect address materialization and arithmetics (PR #132540)
https://github.com/atrosinenko updated https://github.com/llvm/llvm-project/pull/132540 >From c975f5b73958d2aeadf82c0a7b736e713d8798ae Mon Sep 17 00:00:00 2001 From: Anatoly Trosinenko Date: Thu, 20 Mar 2025 20:15:07 +0300 Subject: [PATCH 1/2] [BOLT] Gadget scanner: Detect address materialization and arithmetics In addition to authenticated pointers, consider the contents of a register safe if it was * written by PC-relative address computation * updated by an arithmetic instruction whose input address is safe --- bolt/include/bolt/Core/MCPlusBuilder.h| 16 ++ bolt/lib/Passes/PAuthGadgetScanner.cpp| 92 +-- .../Target/AArch64/AArch64MCPlusBuilder.cpp | 30 +++ .../AArch64/gs-pacret-autiasp.s | 15 -- .../gs-pauth-address-materialization.s| 228 ++ .../binary-analysis/AArch64/lit.local.cfg | 3 +- 6 files changed, 345 insertions(+), 39 deletions(-) create mode 100644 bolt/test/binary-analysis/AArch64/gs-pauth-address-materialization.s diff --git a/bolt/include/bolt/Core/MCPlusBuilder.h b/bolt/include/bolt/Core/MCPlusBuilder.h index 8b6dc14121480..e94f82d00349a 100644 --- a/bolt/include/bolt/Core/MCPlusBuilder.h +++ b/bolt/include/bolt/Core/MCPlusBuilder.h @@ -587,6 +587,22 @@ class MCPlusBuilder { return getNoRegister(); } + virtual MCPhysReg getSafelyMaterializedAddressReg(const MCInst &Inst) const { +llvm_unreachable("not implemented"); +return getNoRegister(); + } + + /// Analyzes if this instruction can safely perform address arithmetics. + /// + /// If the first element of the returned pair is no-register, this instruction + /// is considered unknown. Otherwise, (output, input) pair is returned, + /// so that output is as trusted as input is. + virtual std::pair + analyzeSafeAddressArithmetics(const MCInst &Inst) const { +llvm_unreachable("not implemented"); +return std::make_pair(getNoRegister(), getNoRegister()); + } + virtual bool isTerminator(const MCInst &Inst) const; virtual bool isNoop(const MCInst &Inst) const { diff --git a/bolt/lib/Passes/PAuthGadgetScanner.cpp b/bolt/lib/Passes/PAuthGadgetScanner.cpp index a3b320c545734..16da08551a34d 100644 --- a/bolt/lib/Passes/PAuthGadgetScanner.cpp +++ b/bolt/lib/Passes/PAuthGadgetScanner.cpp @@ -335,6 +335,50 @@ class PacRetAnalysis }); } + BitVector getClobberedRegs(const MCInst &Point) const { +BitVector Clobbered(NumRegs, false); +// Assume a call can clobber all registers, including callee-saved +// registers. There's a good chance that callee-saved registers will be +// saved on the stack at some point during execution of the callee. +// Therefore they should also be considered as potentially modified by an +// attacker/written to. +// Also, not all functions may respect the AAPCS ABI rules about +// caller/callee-saved registers. +if (BC.MIB->isCall(Point)) + Clobbered.set(); +else + BC.MIB->getClobberedRegs(Point, Clobbered); +return Clobbered; + } + + // Returns all registers that can be treated as if they are written by an + // authentication instruction. + SmallVector getAuthenticatedRegs(const MCInst &Point, + const State &Cur) const { +SmallVector Regs; +const MCPhysReg NoReg = BC.MIB->getNoRegister(); + +// A signed pointer can be authenticated, or +ErrorOr AutReg = BC.MIB->getAuthenticatedReg(Point); +if (AutReg && *AutReg != NoReg) + Regs.push_back(*AutReg); + +// ... a safe address can be materialized, or +MCPhysReg NewAddrReg = BC.MIB->getSafelyMaterializedAddressReg(Point); +if (NewAddrReg != NoReg) + Regs.push_back(NewAddrReg); + +// ... an address can be updated in a safe manner, producing the result +// which is as trusted as the input address. +MCPhysReg ArithResult, ArithSrc; +std::tie(ArithResult, ArithSrc) = +BC.MIB->analyzeSafeAddressArithmetics(Point); +if (ArithResult != NoReg && Cur.SafeToDerefRegs[ArithSrc]) + Regs.push_back(ArithResult); + +return Regs; + } + State computeNext(const MCInst &Point, const State &Cur) { PacStatePrinter P(BC); LLVM_DEBUG({ @@ -355,19 +399,20 @@ class PacRetAnalysis return State(); } +// First, compute various properties of the instruction, taking the state +// before its execution into account, if necessary. + +BitVector Clobbered = getClobberedRegs(Point); +// Compute the set of registers that can be considered as written by +// an authentication instruction. This includes operations that are +// *strictly better* than authentication, such as materializing a +// PC-relative constant. +SmallVector AuthenticatedOrBetter = +getAuthenticatedRegs(Point, Cur); + +// Then, compute the state after this instruction is executed. State Next = Cur; -BitVector Clobbered(NumRegs, false); -// Assume a call can
[llvm-branch-commits] [llvm] llvm-reduce: Preserve uselistorder when writing thinlto bitcode (PR #133369)
https://github.com/teresajohnson edited https://github.com/llvm/llvm-project/pull/133369 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits