[llvm-branch-commits] [llvm] [BOLT] Gadget scanner: do not crash on debug-printing CFI instructions (PR #136151)

2025-04-17 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-bolt

Author: Anatoly Trosinenko (atrosinenko)


Changes

Some instruction-printing code used under LLVM_DEBUG does not handle CFI
instructions well. While CFI instructions seem to be harmless for the
correctness of the analysis results, they do not convey any useful
information to the analysis either, so skip them early.

---
Full diff: https://github.com/llvm/llvm-project/pull/136151.diff


2 Files Affected:

- (modified) bolt/lib/Passes/PAuthGadgetScanner.cpp (+16) 
- (modified) bolt/test/binary-analysis/AArch64/gs-pauth-debug-output.s (+32) 


``diff
diff --git a/bolt/lib/Passes/PAuthGadgetScanner.cpp 
b/bolt/lib/Passes/PAuthGadgetScanner.cpp
index f12354390c3f3..2d2126bf05ae1 100644
--- a/bolt/lib/Passes/PAuthGadgetScanner.cpp
+++ b/bolt/lib/Passes/PAuthGadgetScanner.cpp
@@ -433,6 +433,9 @@ class SrcSafetyAnalysis {
   }
 
   SrcState computeNext(const MCInst &Point, const SrcState &Cur) {
+if (BC.MIB->isCFI(Point))
+  return Cur;
+
 SrcStatePrinter P(BC);
 LLVM_DEBUG({
   dbgs() << "  SrcSafetyAnalysis::ComputeNext(";
@@ -674,6 +677,8 @@ class CFGUnawareSrcSafetyAnalysis : public 
SrcSafetyAnalysis {
 SrcState S = createEntryState();
 for (auto &I : BF.instrs()) {
   MCInst &Inst = I.second;
+  if (BC.MIB->isCFI(Inst))
+continue;
 
   // If there is a label before this instruction, it is possible that it
   // can be jumped-to, thus conservatively resetting S. As an exception,
@@ -952,6 +957,9 @@ class DstSafetyAnalysis {
   }
 
   DstState computeNext(const MCInst &Point, const DstState &Cur) {
+if (BC.MIB->isCFI(Point))
+  return Cur;
+
 DstStatePrinter P(BC);
 LLVM_DEBUG({
   dbgs() << "  DstSafetyAnalysis::ComputeNext(";
@@ -1130,6 +1138,8 @@ class CFGUnawareDstSafetyAnalysis : public 
DstSafetyAnalysis {
 DstState S = createUnsafeState();
 for (auto &I : llvm::reverse(BF.instrs())) {
   MCInst &Inst = I.second;
+  if (BC.MIB->isCFI(Inst))
+continue;
 
   // If Inst can change the control flow, we cannot be sure that the next
   // instruction (to be executed in analyzed program) is the one processed
@@ -1326,6 +1336,9 @@ void FunctionAnalysis::findUnsafeUses(
   });
 
   iterateOverInstrs(BF, [&](MCInstReference Inst) {
+if (BC.MIB->isCFI(Inst))
+  return;
+
 const SrcState &S = Analysis->getStateBefore(Inst);
 
 // If non-empty state was never propagated from the entry basic block
@@ -1387,6 +1400,9 @@ void FunctionAnalysis::findUnsafeDefs(
   });
 
   iterateOverInstrs(BF, [&](MCInstReference Inst) {
+if (BC.MIB->isCFI(Inst))
+  return;
+
 const DstState &S = Analysis->getStateAfter(Inst);
 
 if (auto Report = shouldReportAuthOracle(BC, Inst, S))
diff --git a/bolt/test/binary-analysis/AArch64/gs-pauth-debug-output.s 
b/bolt/test/binary-analysis/AArch64/gs-pauth-debug-output.s
index fd55880921d06..07b61bea77e94 100644
--- a/bolt/test/binary-analysis/AArch64/gs-pauth-debug-output.s
+++ b/bolt/test/binary-analysis/AArch64/gs-pauth-debug-output.s
@@ -329,6 +329,38 @@ auth_oracle:
 // PAUTH-EMPTY:
 // PAUTH-NEXT:   Attaching leakage info to: :  autia   x0, x1 
# DataflowDstSafetyAnalysis: dst-state
 
+// Gadget scanner should not crash on CFI instructions, including when 
debug-printing them.
+// Note that the particular debug output is not checked, but BOLT should be
+// compiled with assertions enabled to support -debug-only argument.
+
+.globl  cfi_inst_df
+.type   cfi_inst_df,@function
+cfi_inst_df:
+.cfi_startproc
+sub sp, sp, #16
+.cfi_def_cfa_offset 16
+add sp, sp, #16
+.cfi_def_cfa_offset 0
+ret
+.size   cfi_inst_df, .-cfi_inst_df
+.cfi_endproc
+
+.globl  cfi_inst_nocfg
+.type   cfi_inst_nocfg,@function
+cfi_inst_nocfg:
+.cfi_startproc
+sub sp, sp, #16
+.cfi_def_cfa_offset 16
+
+adr x0, 1f
+br  x0
+1:
+add sp, sp, #16
+.cfi_def_cfa_offset 0
+ret
+.size   cfi_inst_nocfg, .-cfi_inst_nocfg
+.cfi_endproc
+
 // CHECK-LABEL:Analyzing function main, AllocatorId = 1
 .globl  main
 .type   main,@function

``




https://github.com/llvm/llvm-project/pull/136151
___
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: do not crash on debug-printing CFI instructions (PR #136151)

2025-04-17 Thread Anatoly Trosinenko via llvm-branch-commits

atrosinenko 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/136151?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#136151** https://app.graphite.dev/github/pr/llvm/llvm-project/136151?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/136151?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#135663** https://app.graphite.dev/github/pr/llvm/llvm-project/135663?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#136147** https://app.graphite.dev/github/pr/llvm/llvm-project/136147?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#135662** https://app.graphite.dev/github/pr/llvm/llvm-project/135662?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#135661** https://app.graphite.dev/github/pr/llvm/llvm-project/135661?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134146** https://app.graphite.dev/github/pr/llvm/llvm-project/134146?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133461** https://app.graphite.dev/github/pr/llvm/llvm-project/133461?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#135073** https://app.graphite.dev/github/pr/llvm/llvm-project/135073?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/136151
___
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] [SPARC] Use lzcnt to implement CTLZ when we have VIS3 (PR #135715)

2025-04-17 Thread via llvm-branch-commits

https://github.com/koachan updated 
https://github.com/llvm/llvm-project/pull/135715

>From 6e865810ea2acaf636a4759fd4ffc67aa3dbb848 Mon Sep 17 00:00:00 2001
From: Koakuma 
Date: Thu, 17 Apr 2025 08:24:54 +0700
Subject: [PATCH 1/4] Promote i32 CTLZ when we don't have VIS3 or POPC

Created using spr 1.3.5
---
 llvm/lib/Target/Sparc/SparcISelLowering.cpp |  11 +-
 llvm/test/CodeGen/SPARC/ctlz.ll | 182 +++-
 2 files changed, 35 insertions(+), 158 deletions(-)

diff --git a/llvm/lib/Target/Sparc/SparcISelLowering.cpp 
b/llvm/lib/Target/Sparc/SparcISelLowering.cpp
index fa544916aebb5..e455706b0528f 100644
--- a/llvm/lib/Target/Sparc/SparcISelLowering.cpp
+++ b/llvm/lib/Target/Sparc/SparcISelLowering.cpp
@@ -1755,7 +1755,7 @@ SparcTargetLowering::SparcTargetLowering(const 
TargetMachine &TM,
Subtarget->usePopc() ? Legal : Expand);
 setOperationAction(ISD::CTTZ , MVT::i64, Expand);
 setOperationAction(ISD::CTLZ, MVT::i64,
-   Subtarget->isVIS3() ? Legal : LibCall);
+   Subtarget->isVIS3() ? Legal : Expand);
 setOperationAction(ISD::BSWAP, MVT::i64, Expand);
 setOperationAction(ISD::ROTL , MVT::i64, Expand);
 setOperationAction(ISD::ROTR , MVT::i64, Expand);
@@ -1818,7 +1818,7 @@ SparcTargetLowering::SparcTargetLowering(const 
TargetMachine &TM,
   setOperationAction(ISD::FMA  , MVT::f32, Expand);
   setOperationAction(ISD::CTTZ , MVT::i32, Expand);
   setOperationAction(ISD::CTLZ, MVT::i32,
- Subtarget->isVIS3() ? Promote : LibCall);
+ Subtarget->isVIS3() ? Promote : Expand);
   setOperationAction(ISD::ROTL , MVT::i32, Expand);
   setOperationAction(ISD::ROTR , MVT::i32, Expand);
   setOperationAction(ISD::BSWAP, MVT::i32, Expand);
@@ -1992,6 +1992,13 @@ SparcTargetLowering::SparcTargetLowering(const 
TargetMachine &TM,
   if (Subtarget->isVIS3()) {
 setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i32, Promote);
 setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i64, Legal);
+  } else if (Subtarget->usePopc()) {
+setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i32, Expand);
+setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i64, Expand);
+  } else {
+setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i32,
+   Subtarget->is64Bit() ? Promote : LibCall);
+setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i64, LibCall);
   }
 
   setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom);
diff --git a/llvm/test/CodeGen/SPARC/ctlz.ll b/llvm/test/CodeGen/SPARC/ctlz.ll
index d17b776ca0a72..3391af02e4bc0 100644
--- a/llvm/test/CodeGen/SPARC/ctlz.ll
+++ b/llvm/test/CodeGen/SPARC/ctlz.ll
@@ -6,46 +6,18 @@
 define i32 @i32_nopoison(i32 %x) nounwind {
 ; V9-LABEL: i32_nopoison:
 ; V9:   ! %bb.0:
-; V9-NEXT:cmp %o0, 0
+; V9-NEXT:save %sp, -176, %sp
+; V9-NEXT:cmp %i0, 0
 ; V9-NEXT:be %icc, .LBB0_2
 ; V9-NEXT:nop
 ; V9-NEXT:  ! %bb.1: ! %cond.false
-; V9-NEXT:srl %o0, 1, %o1
-; V9-NEXT:or %o0, %o1, %o0
-; V9-NEXT:srl %o0, 2, %o1
-; V9-NEXT:or %o0, %o1, %o0
-; V9-NEXT:srl %o0, 4, %o1
-; V9-NEXT:or %o0, %o1, %o0
-; V9-NEXT:srl %o0, 8, %o1
-; V9-NEXT:or %o0, %o1, %o0
-; V9-NEXT:srl %o0, 16, %o1
-; V9-NEXT:or %o0, %o1, %o0
-; V9-NEXT:xor %o0, -1, %o0
-; V9-NEXT:srl %o0, 1, %o1
-; V9-NEXT:sethi 1398101, %o2
-; V9-NEXT:or %o2, 341, %o2
-; V9-NEXT:and %o1, %o2, %o1
-; V9-NEXT:sub %o0, %o1, %o0
-; V9-NEXT:sethi 838860, %o1
-; V9-NEXT:or %o1, 819, %o1
-; V9-NEXT:and %o0, %o1, %o2
-; V9-NEXT:srl %o0, 2, %o0
-; V9-NEXT:and %o0, %o1, %o0
-; V9-NEXT:add %o2, %o0, %o0
-; V9-NEXT:srl %o0, 4, %o1
-; V9-NEXT:add %o0, %o1, %o0
-; V9-NEXT:sethi 246723, %o1
-; V9-NEXT:or %o1, 783, %o1
-; V9-NEXT:and %o0, %o1, %o0
-; V9-NEXT:sll %o0, 8, %o1
-; V9-NEXT:add %o0, %o1, %o0
-; V9-NEXT:sll %o0, 16, %o1
-; V9-NEXT:add %o0, %o1, %o0
-; V9-NEXT:retl
-; V9-NEXT:srl %o0, 24, %o0
+; V9-NEXT:call __clzdi2
+; V9-NEXT:sllx %i0, 32, %o0
+; V9-NEXT:ret
+; V9-NEXT:restore %g0, %o0, %o0
 ; V9-NEXT:  .LBB0_2:
-; V9-NEXT:retl
-; V9-NEXT:mov 32, %o0
+; V9-NEXT:ret
+; V9-NEXT:restore %g0, 32, %o0
 ;
 ; POPC-LABEL: i32_nopoison:
 ; POPC:   ! %bb.0:
@@ -90,39 +62,11 @@ define i32 @i32_nopoison(i32 %x) nounwind {
 define i32 @i32_poison(i32 %x) nounwind {
 ; V9-LABEL: i32_poison:
 ; V9:   ! %bb.0:
-; V9-NEXT:srl %o0, 1, %o1
-; V9-NEXT:or %o0, %o1, %o0
-; V9-NEXT:srl %o0, 2, %o1
-; V9-NEXT:or %o0, %o1, %o0
-; V9-NEXT:srl %o0, 4, %o1
-; V9-NEXT:or %o0, %o1, %o0
-; V9-NEXT:srl %o0, 8, %o1
-; V9-NEXT:or %o0, %o1, %o0
-; V9-NEXT:srl %o0, 16, %o1
-; V9-NEXT:or %o0, %o1, %o0
-; V9-NEXT:xor %o0, -1, %o0
-; V9-NEXT:srl %o0, 1, %o1
-; V9-NEXT:sethi 1398101, %o2
-; V9-NEXT:or %o2, 341, %o2
-; V9-NEXT:and %o1, %o2, %o1
-; V9-NEXT:sub %o0, %o1, %o0
-; V

[llvm-branch-commits] [SPARC] Use op-then-neg instructions when we have VIS3 (PR #135717)

2025-04-17 Thread Matt Arsenault via llvm-branch-commits


@@ -0,0 +1,59 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 5
+; RUN: llc -mtriple=sparc64 -mattr=+vis3 < %s | FileCheck %s
+
+define float @fnadds(float %a, float %b) nounwind {
+; CHECK-LABEL: fnadds:
+; CHECK:   ! %bb.0: ! %entry
+; CHECK-NEXT:retl
+; CHECK-NEXT:fnadds %f1, %f3, %f0
+entry:
+  %add = fadd float %a, %b
+  %fneg = fneg float %add
+  ret float %fneg
+}
+
+define double @fnaddd(double %a, double %b) nounwind {
+; CHECK-LABEL: fnaddd:
+; CHECK:   ! %bb.0: ! %entry
+; CHECK-NEXT:retl
+; CHECK-NEXT:fnaddd %f0, %f2, %f0
+entry:
+  %add = fadd double %a, %b
+  %fneg = fneg double %add
+  ret double %fneg
+}
+
+define float @fnmuls(float %a, float %b) nounwind {
+; CHECK-LABEL: fnmuls:
+; CHECK:   ! %bb.0: ! %entry
+; CHECK-NEXT:retl
+; CHECK-NEXT:fnmuls %f1, %f3, %f0
+entry:
+  %mul = fmul float %a, %b
+  %fneg = fneg float %mul
+  ret float %fneg
+}
+
+define double @fnmuld(double %a, double %b) nounwind {
+; CHECK-LABEL: fnmuld:
+; CHECK:   ! %bb.0: ! %entry
+; CHECK-NEXT:retl
+; CHECK-NEXT:fnmuld %f0, %f2, %f0
+entry:
+  %mul = fmul double %a, %b
+  %fneg = fneg double %mul
+  ret double %fneg
+}
+
+define double @fnsmuld(float %a, float %b) nounwind {
+; CHECK-LABEL: fnsmuld:
+; CHECK:   ! %bb.0: ! %entry
+; CHECK-NEXT:retl
+; CHECK-NEXT:fnsmuld %f1, %f3, %f0
+entry:
+  %conv.i = fpext float %a to double
+  %conv1.i = fpext float %b to double
+  %mul = fmul double %conv.i, %conv1.i
+  %fneg = fneg double %mul
+  ret double %fneg
+}

arsenm wrote:

This set of tests doesn't look like it covers all the patterns here. Should you 
also cover vectors to see these patterns still work after scalarization? 

https://github.com/llvm/llvm-project/pull/135717
___
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] [ci] set up llvm-symbolizer environment variable (PR #136156)

2025-04-17 Thread Matheus Izvekov via llvm-branch-commits

https://github.com/mizvekov created 
https://github.com/llvm/llvm-project/pull/136156

Set up llvm-symbolizer environment variable so that its preferred over any 
symbolizer just built, as it can be much slower when built for debugging.

>From ae4da1886cd2af4c6ac0dc283fcf735ad992b566 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Thu, 17 Apr 2025 13:12:46 -0300
Subject: [PATCH] [ci] set up llvm-symbolizer environment variable

Set up llvm-symbolizer environment variable so that its preferred over
any symbolizer just built, as it can be much slower when built for debugging.
---
 .ci/monolithic-linux.sh | 5 +
 1 file changed, 5 insertions(+)

diff --git a/.ci/monolithic-linux.sh b/.ci/monolithic-linux.sh
index 6461c9d40ad59..59a6b22ccb06a 100755
--- a/.ci/monolithic-linux.sh
+++ b/.ci/monolithic-linux.sh
@@ -58,6 +58,11 @@ export PIP_BREAK_SYSTEM_PACKAGES=1
 pip install -q -r "${MONOREPO_ROOT}"/mlir/python/requirements.txt
 pip install -q -r "${MONOREPO_ROOT}"/lldb/test/requirements.txt
 pip install -q -r "${MONOREPO_ROOT}"/.ci/requirements.txt
+
+# Set the system llvm-symbolizer as preferred.
+export LLVM_SYMBOLIZER_PATH=`which llvm-symbolizer`
+[[ ! -f "${LLVM_SYMBOLIZER_PATH}" ]] && echo "llvm-symbolizer not found!"
+
 cmake -S "${MONOREPO_ROOT}"/llvm -B "${BUILD_DIR}" \
   -D LLVM_ENABLE_PROJECTS="${projects}" \
   -G Ninja \

___
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] [SPARC] Promote i32 CTTZ when we have VIS3 (PR #135894)

2025-04-17 Thread via llvm-branch-commits

https://github.com/koachan updated 
https://github.com/llvm/llvm-project/pull/135894


___
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] [SPARC] Promote i32 CTTZ when we have VIS3 (PR #135894)

2025-04-17 Thread via llvm-branch-commits

https://github.com/koachan updated 
https://github.com/llvm/llvm-project/pull/135894


___
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] [SPARC] Use lzcnt to implement CTLZ when we have VIS3 (PR #135715)

2025-04-17 Thread via llvm-branch-commits


@@ -0,0 +1,183 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple=sparcv9 | FileCheck %s -check-prefix=V9
+; RUN: llc < %s -mtriple=sparcv9 -mattr=popc | FileCheck %s -check-prefix=POPC
+; RUN: llc < %s -mtriple=sparcv9 -mattr=vis3 | FileCheck %s -check-prefix=VIS3
+
+define i32 @i32_nopoison(i32 %x) nounwind {
+; V9-LABEL: i32_nopoison:
+; V9:   ! %bb.0:
+; V9-NEXT:save %sp, -176, %sp
+; V9-NEXT:cmp %i0, 0
+; V9-NEXT:be %icc, .LBB0_2
+; V9-NEXT:nop
+; V9-NEXT:  ! %bb.1: ! %cond.false
+; V9-NEXT:call __clzdi2
+; V9-NEXT:sllx %i0, 32, %o0
+; V9-NEXT:ret
+; V9-NEXT:restore %g0, %o0, %o0
+; V9-NEXT:  .LBB0_2:
+; V9-NEXT:ret
+; V9-NEXT:restore %g0, 32, %o0
+;
+; POPC-LABEL: i32_nopoison:
+; POPC:   ! %bb.0:
+; POPC-NEXT:cmp %o0, 0
+; POPC-NEXT:be %icc, .LBB0_2
+; POPC-NEXT:nop
+; POPC-NEXT:  ! %bb.1: ! %cond.false
+; POPC-NEXT:srl %o0, 1, %o1
+; POPC-NEXT:or %o0, %o1, %o0
+; POPC-NEXT:srl %o0, 2, %o1
+; POPC-NEXT:or %o0, %o1, %o0
+; POPC-NEXT:srl %o0, 4, %o1
+; POPC-NEXT:or %o0, %o1, %o0
+; POPC-NEXT:srl %o0, 8, %o1
+; POPC-NEXT:or %o0, %o1, %o0
+; POPC-NEXT:srl %o0, 16, %o1
+; POPC-NEXT:or %o0, %o1, %o0
+; POPC-NEXT:xor %o0, -1, %o0
+; POPC-NEXT:srl %o0, 0, %o0
+; POPC-NEXT:retl
+; POPC-NEXT:popc %o0, %o0
+; POPC-NEXT:  .LBB0_2:
+; POPC-NEXT:retl
+; POPC-NEXT:mov 32, %o0
+;
+; VIS3-LABEL: i32_nopoison:
+; VIS3:   ! %bb.0:
+; VIS3-NEXT:cmp %o0, 0
+; VIS3-NEXT:be %icc, .LBB0_2

koachan wrote:

Those turns out to be controlled by the codegen parameters you mentioned above, 
it seems.

https://github.com/llvm/llvm-project/pull/135715
___
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] [SPARC] Promote i32 CTTZ when we have VIS3 (PR #135894)

2025-04-17 Thread Sergei Barannikov via llvm-branch-commits


@@ -3599,6 +3615,15 @@ bool SparcTargetLowering::isFPImmLegal(const APFloat 
&Imm, EVT VT,
 
 bool SparcTargetLowering::isCtlzFast() const { return Subtarget->isVIS3(); }
 
+bool SparcTargetLowering::isCheapToSpeculateCttz(Type *Ty) const {
+  // We lack native cttz, however,
+  // On 64-bit targets it is cheap to implement it in terms of popc.
+  if (Subtarget->is64Bit() && Subtarget->usePopc())
+return true;
+  // Otherwise, implementing cttz in terms of ctlz is still cheap.
+  return isCheapToSpeculateCtlz(Ty);

s-barannikov wrote:

Not sure where did my comment go, I'll repeat just in case.
Isn't expansion in terms of ctlz cheaper than that in terms of ctpop? (read: 
Shouldn't the comments be swapped?)


https://github.com/llvm/llvm-project/pull/135894
___
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] [SPARC] Promote i32 CTTZ when we have VIS3 (PR #135894)

2025-04-17 Thread Sergei Barannikov via llvm-branch-commits


@@ -3599,6 +3615,15 @@ bool SparcTargetLowering::isFPImmLegal(const APFloat 
&Imm, EVT VT,
 
 bool SparcTargetLowering::isCtlzFast() const { return Subtarget->isVIS3(); }
 
+bool SparcTargetLowering::isCheapToSpeculateCttz(Type *Ty) const {
+  // We lack native cttz, however,
+  // On 64-bit targets it is cheap to implement it in terms of popc.
+  if (Subtarget->is64Bit() && Subtarget->usePopc())
+return true;
+  // Otherwise, implementing cttz in terms of ctlz is still cheap.
+  return isCheapToSpeculateCtlz(Ty);

s-barannikov wrote:

Never mind, I saw it in tests :)

https://github.com/llvm/llvm-project/pull/135894
___
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] [ci] upload any generated clang reproducers as artifacts (PR #136157)

2025-04-17 Thread Matheus Izvekov via llvm-branch-commits

https://github.com/mizvekov created 
https://github.com/llvm/llvm-project/pull/136157

Make sure any generated clang reproducers end up as artifacts.

>From 3f62c811580c82ead2cb227c4af1a6a5df93c576 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Thu, 17 Apr 2025 13:20:07 -0300
Subject: [PATCH] [ci] upload any generated clang reproducers as artifacts

Make sure any generated clang reproducers end up as artifacts.
---
 .ci/monolithic-linux.sh | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/.ci/monolithic-linux.sh b/.ci/monolithic-linux.sh
index 6461c9d40ad59..d2557554cb0bc 100755
--- a/.ci/monolithic-linux.sh
+++ b/.ci/monolithic-linux.sh
@@ -28,10 +28,14 @@ if [[ -n "${CLEAR_CACHE:-}" ]]; then
   ccache --clear
 fi
 
+mkdir -p artifacts/reproducers
+
+# Make sure any clang reproducers will end up as artifacts.
+export CLANG_CRASH_DIAGNOSTICS_DIR=`realpath artifacts/reproducers`
+
 function at-exit {
   retcode=$?
 
-  mkdir -p artifacts
   ccache --print-stats > artifacts/ccache_stats.txt
   cp "${BUILD_DIR}"/.ninja_log artifacts/.ninja_log
 

___
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] [lldb] [llvm] [ci] add dependencies for lldb python binding tests (PR #136158)

2025-04-17 Thread Matheus Izvekov via llvm-branch-commits

https://github.com/mizvekov created 
https://github.com/llvm/llvm-project/pull/136158

Add correct configuration and dependencies for LLDB testing which is actually 
relevant for clang changes.

>From 20f393ed197d31619d169740afa4adae3393d26b Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Thu, 17 Apr 2025 13:31:32 -0300
Subject: [PATCH] [ci] add dependencies for lldb python binding tests

Add correct configuration and dependencies for LLDB testing which
is actually relevant for clang changes.
---
 .ci/monolithic-linux.sh| 8 
 lldb/test/requirements.txt | 2 ++
 2 files changed, 10 insertions(+)

diff --git a/.ci/monolithic-linux.sh b/.ci/monolithic-linux.sh
index 59a6b22ccb06a..653495e45786a 100755
--- a/.ci/monolithic-linux.sh
+++ b/.ci/monolithic-linux.sh
@@ -54,6 +54,7 @@ targets="${2}"
 lit_args="-v --xunit-xml-output ${BUILD_DIR}/test-results.xml 
--use-unique-output-file-name --timeout=1200 --time-tests"
 
 echo "--- cmake"
+
 export PIP_BREAK_SYSTEM_PACKAGES=1
 pip install -q -r "${MONOREPO_ROOT}"/mlir/python/requirements.txt
 pip install -q -r "${MONOREPO_ROOT}"/lldb/test/requirements.txt
@@ -63,9 +64,13 @@ pip install -q -r "${MONOREPO_ROOT}"/.ci/requirements.txt
 export LLVM_SYMBOLIZER_PATH=`which llvm-symbolizer`
 [[ ! -f "${LLVM_SYMBOLIZER_PATH}" ]] && echo "llvm-symbolizer not found!"
 
+# Set up all runtimes either way. libcxx is a dependency of LLDB.
+# If it ends up being unused, not much harm.
 cmake -S "${MONOREPO_ROOT}"/llvm -B "${BUILD_DIR}" \
   -D LLVM_ENABLE_PROJECTS="${projects}" \
+  -D LLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" \
   -G Ninja \
+  -D CMAKE_PREFIX_PATH="${HOME}/.local" \
   -D CMAKE_BUILD_TYPE=Release \
   -D LLVM_ENABLE_ASSERTIONS=ON \
   -D LLVM_BUILD_EXAMPLES=ON \
@@ -74,7 +79,10 @@ cmake -S "${MONOREPO_ROOT}"/llvm -B "${BUILD_DIR}" \
   -D LLVM_ENABLE_LLD=ON \
   -D CMAKE_CXX_FLAGS=-gmlt \
   -D LLVM_CCACHE_BUILD=ON \
+  -D LIBCXX_CXX_ABI=libcxxabi \
   -D MLIR_ENABLE_BINDINGS_PYTHON=ON \
+  -D LLDB_ENABLE_PYTHON=ON \
+  -D LLDB_ENFORCE_STRICT_TEST_REQUIREMENTS=ON \
   -D CMAKE_INSTALL_PREFIX="${INSTALL_DIR}"
 
 echo "--- ninja"
diff --git a/lldb/test/requirements.txt b/lldb/test/requirements.txt
index 708f2327a6a04..c187180697d0b 100644
--- a/lldb/test/requirements.txt
+++ b/lldb/test/requirements.txt
@@ -5,3 +5,5 @@ psutil>=5.9.4
 # See llvm.org/pr22274.
 pexpect>=4.9.0; sys_platform != 'win32'
 packaging
+# Required for python tests
+swig

___
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] [lldb] [llvm] [ci] add dependencies for lldb python binding tests (PR #136158)

2025-04-17 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Matheus Izvekov (mizvekov)


Changes

Add correct configuration and dependencies for LLDB testing which is actually 
relevant for clang changes.

---
Full diff: https://github.com/llvm/llvm-project/pull/136158.diff


2 Files Affected:

- (modified) .ci/monolithic-linux.sh (+8) 
- (modified) lldb/test/requirements.txt (+2) 


``diff
diff --git a/.ci/monolithic-linux.sh b/.ci/monolithic-linux.sh
index 59a6b22ccb06a..653495e45786a 100755
--- a/.ci/monolithic-linux.sh
+++ b/.ci/monolithic-linux.sh
@@ -54,6 +54,7 @@ targets="${2}"
 lit_args="-v --xunit-xml-output ${BUILD_DIR}/test-results.xml 
--use-unique-output-file-name --timeout=1200 --time-tests"
 
 echo "--- cmake"
+
 export PIP_BREAK_SYSTEM_PACKAGES=1
 pip install -q -r "${MONOREPO_ROOT}"/mlir/python/requirements.txt
 pip install -q -r "${MONOREPO_ROOT}"/lldb/test/requirements.txt
@@ -63,9 +64,13 @@ pip install -q -r "${MONOREPO_ROOT}"/.ci/requirements.txt
 export LLVM_SYMBOLIZER_PATH=`which llvm-symbolizer`
 [[ ! -f "${LLVM_SYMBOLIZER_PATH}" ]] && echo "llvm-symbolizer not found!"
 
+# Set up all runtimes either way. libcxx is a dependency of LLDB.
+# If it ends up being unused, not much harm.
 cmake -S "${MONOREPO_ROOT}"/llvm -B "${BUILD_DIR}" \
   -D LLVM_ENABLE_PROJECTS="${projects}" \
+  -D LLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" \
   -G Ninja \
+  -D CMAKE_PREFIX_PATH="${HOME}/.local" \
   -D CMAKE_BUILD_TYPE=Release \
   -D LLVM_ENABLE_ASSERTIONS=ON \
   -D LLVM_BUILD_EXAMPLES=ON \
@@ -74,7 +79,10 @@ cmake -S "${MONOREPO_ROOT}"/llvm -B "${BUILD_DIR}" \
   -D LLVM_ENABLE_LLD=ON \
   -D CMAKE_CXX_FLAGS=-gmlt \
   -D LLVM_CCACHE_BUILD=ON \
+  -D LIBCXX_CXX_ABI=libcxxabi \
   -D MLIR_ENABLE_BINDINGS_PYTHON=ON \
+  -D LLDB_ENABLE_PYTHON=ON \
+  -D LLDB_ENFORCE_STRICT_TEST_REQUIREMENTS=ON \
   -D CMAKE_INSTALL_PREFIX="${INSTALL_DIR}"
 
 echo "--- ninja"
diff --git a/lldb/test/requirements.txt b/lldb/test/requirements.txt
index 708f2327a6a04..c187180697d0b 100644
--- a/lldb/test/requirements.txt
+++ b/lldb/test/requirements.txt
@@ -5,3 +5,5 @@ psutil>=5.9.4
 # See llvm.org/pr22274.
 pexpect>=4.9.0; sys_platform != 'win32'
 packaging
+# Required for python tests
+swig

``




https://github.com/llvm/llvm-project/pull/136158
___
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] [lldb] [lldb][nfc] Split the constructor of ThreadPlanStepOut (PR #136160)

2025-04-17 Thread via llvm-branch-commits

https://github.com/jimingham approved this pull request.

This is also purely mechanical, and looks fine.

https://github.com/llvm/llvm-project/pull/136160
___
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] [MTE] do not tag zero sized globals (PR #136020)

2025-04-17 Thread Florian Mayer via llvm-branch-commits

https://github.com/fmayer updated 
https://github.com/llvm/llvm-project/pull/136020


___
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] [lldb] [lldb] Create ThreadPlanStepOut ctor that never skips frames (PR #136163)

2025-04-17 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Felipe de Azevedo Piovezan (felipepiovezan)


Changes

The function QueueThreadPlanForStepOutNoShouldStop has the semantics of "go 
this parent frame"; ThreadPlanStepOut needs to respect that, not skipping over 
any frames it finds uninteresting. This commit creates a constructor that 
respects such instruction.

---
Full diff: https://github.com/llvm/llvm-project/pull/136163.diff


3 Files Affected:

- (modified) lldb/include/lldb/Target/ThreadPlanStepOut.h (+9) 
- (modified) lldb/source/Target/Thread.cpp (+1-1) 
- (modified) lldb/source/Target/ThreadPlanStepOut.cpp (+22) 


``diff
diff --git a/lldb/include/lldb/Target/ThreadPlanStepOut.h 
b/lldb/include/lldb/Target/ThreadPlanStepOut.h
index f37d09467dda3..bc106380bca5c 100644
--- a/lldb/include/lldb/Target/ThreadPlanStepOut.h
+++ b/lldb/include/lldb/Target/ThreadPlanStepOut.h
@@ -17,12 +17,21 @@ namespace lldb_private {
 
 class ThreadPlanStepOut : public ThreadPlan, public ThreadPlanShouldStopHere {
 public:
+  /// Creates a thread plan to step out from frame_idx, skipping parent frames
+  /// that artificial and hidden frames. Also skips frames without debug info
+  /// based on step_out_avoids_code_without_debug_info.
   ThreadPlanStepOut(Thread &thread, bool stop_others, Vote report_stop_vote,
 Vote report_run_vote, uint32_t frame_idx,
 LazyBool step_out_avoids_code_without_debug_info,
 bool continue_to_next_branch = false,
 bool gather_return_value = true);
 
+  /// Creates a thread plan to step out from frame_idx to frame_idx + 1.
+  ThreadPlanStepOut(Thread &thread, bool stop_others, Vote report_stop_vote,
+Vote report_run_vote, uint32_t frame_idx,
+bool continue_to_next_branch = false,
+bool gather_return_value = true);
+
   ~ThreadPlanStepOut() override;
 
   void GetDescription(Stream *s, lldb::DescriptionLevel level) override;
diff --git a/lldb/source/Target/Thread.cpp b/lldb/source/Target/Thread.cpp
index ddd4315b6cc9e..1d941a3614275 100644
--- a/lldb/source/Target/Thread.cpp
+++ b/lldb/source/Target/Thread.cpp
@@ -1360,7 +1360,7 @@ ThreadPlanSP 
Thread::QueueThreadPlanForStepOutNoShouldStop(
   false; // No need to calculate the return value here.
   ThreadPlanSP thread_plan_sp(new ThreadPlanStepOut(
   *this, stop_other_threads, report_stop_vote, report_run_vote, frame_idx,
-  eLazyBoolNo, continue_to_next_branch, calculate_return_value));
+  continue_to_next_branch, calculate_return_value));
 
   ThreadPlanStepOut *new_plan =
   static_cast(thread_plan_sp.get());
diff --git a/lldb/source/Target/ThreadPlanStepOut.cpp 
b/lldb/source/Target/ThreadPlanStepOut.cpp
index 546405c267601..c7da0e2be89b4 100644
--- a/lldb/source/Target/ThreadPlanStepOut.cpp
+++ b/lldb/source/Target/ThreadPlanStepOut.cpp
@@ -83,6 +83,28 @@ ThreadPlanStepOut::ThreadPlanStepOut(
  frame_idx, continue_to_next_branch);
 }
 
+ThreadPlanStepOut::ThreadPlanStepOut(Thread &thread, bool stop_others,
+ Vote report_stop_vote,
+ Vote report_run_vote, uint32_t frame_idx,
+ bool continue_to_next_branch,
+ bool gather_return_value)
+: ThreadPlan(ThreadPlan::eKindStepOut, "Step out", thread, 
report_stop_vote,
+ report_run_vote),
+  ThreadPlanShouldStopHere(this), m_return_bp_id(LLDB_INVALID_BREAK_ID),
+  m_return_addr(LLDB_INVALID_ADDRESS), m_stop_others(stop_others),
+  m_immediate_step_from_function(nullptr),
+  m_calculate_return_value(gather_return_value) {
+  SetFlagsToDefault();
+  m_step_from_insn = thread.GetRegisterContext()->GetPC(0);
+
+  StackFrameSP return_frame_sp = thread.GetStackFrameAtIndex(frame_idx + 1);
+  StackFrameSP immediate_return_from_sp =
+  thread.GetStackFrameAtIndex(frame_idx);
+
+  SetupReturnAddress(return_frame_sp, immediate_return_from_sp, frame_idx,
+ continue_to_next_branch);
+}
+
 void ThreadPlanStepOut::SetupReturnAddress(
 StackFrameSP return_frame_sp, StackFrameSP immediate_return_from_sp,
 uint32_t frame_idx, bool continue_to_next_branch) {

``




https://github.com/llvm/llvm-project/pull/136163
___
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: improve handling of unreachable basic blocks (PR #136183)

2025-04-17 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-bolt

Author: Anatoly Trosinenko (atrosinenko)


Changes

Instead of refusing to analyze an instruction completely, when it is
unreachable according to the CFG reconstructed by BOLT, pessimistically
assume all registers to be unsafe at the start of basic blocks without
any predecessors. Nevertheless, unreachable basic blocks found in
optimized code likely means imprecise CFG reconstruction, thus report a
warning once per basic block without predecessors.

---
Full diff: https://github.com/llvm/llvm-project/pull/136183.diff


3 Files Affected:

- (modified) bolt/lib/Passes/PAuthGadgetScanner.cpp (+32-14) 
- (modified) bolt/test/binary-analysis/AArch64/gs-pacret-autiasp.s (+1-1) 
- (modified) bolt/test/binary-analysis/AArch64/gs-pauth-calls.s (+57) 


``diff
diff --git a/bolt/lib/Passes/PAuthGadgetScanner.cpp 
b/bolt/lib/Passes/PAuthGadgetScanner.cpp
index 2d2126bf05ae1..f998b8fa0f950 100644
--- a/bolt/lib/Passes/PAuthGadgetScanner.cpp
+++ b/bolt/lib/Passes/PAuthGadgetScanner.cpp
@@ -346,6 +346,12 @@ class SrcSafetyAnalysis {
 return S;
   }
 
+  /// Creates a state with all registers marked unsafe (not to be confused
+  /// with empty state).
+  SrcState createUnsafeState() const {
+return SrcState(NumRegs, RegsToTrackInstsFor.getNumTrackedRegisters());
+  }
+
   BitVector getClobberedRegs(const MCInst &Point) const {
 BitVector Clobbered(NumRegs);
 // Assume a call can clobber all registers, including callee-saved
@@ -585,6 +591,13 @@ class DataflowSrcSafetyAnalysis
 if (BB.isEntryPoint())
   return createEntryState();
 
+// If a basic block without any predecessors is found in an optimized code,
+// this likely means that some CFG edges were not detected. Pessimistically
+// assume all registers to be unsafe before this basic block and warn about
+// this fact in FunctionAnalysis::findUnsafeUses().
+if (BB.pred_empty())
+  return createUnsafeState();
+
 return SrcState();
   }
 
@@ -658,12 +671,6 @@ class CFGUnawareSrcSafetyAnalysis : public 
SrcSafetyAnalysis {
   BC.MIB->removeAnnotation(I.second, StateAnnotationIndex);
   }
 
-  /// Creates a state with all registers marked unsafe (not to be confused
-  /// with empty state).
-  SrcState createUnsafeState() const {
-return SrcState(NumRegs, RegsToTrackInstsFor.getNumTrackedRegisters());
-  }
-
 public:
   CFGUnawareSrcSafetyAnalysis(BinaryFunction &BF,
   MCPlusBuilder::AllocatorIdTy AllocId,
@@ -1335,19 +1342,30 @@ void FunctionAnalysis::findUnsafeUses(
 BF.dump();
   });
 
+  if (BF.hasCFG()) {
+// Warn on basic blocks being unreachable according to BOLT, as this
+// likely means CFG is imprecise.
+for (BinaryBasicBlock &BB : BF) {
+  if (!BB.pred_empty() || BB.isEntryPoint())
+continue;
+  // Arbitrarily attach the report to the first instruction of BB.
+  MCInst *InstToReport = BB.getFirstNonPseudoInstr();
+  if (!InstToReport)
+continue; // BB has no real instructions
+
+  Reports.push_back(
+  make_generic_report(MCInstReference::get(InstToReport, BF),
+  "Warning: no predecessor basic blocks detected "
+  "(possibly incomplete CFG)"));
+}
+  }
+
   iterateOverInstrs(BF, [&](MCInstReference Inst) {
 if (BC.MIB->isCFI(Inst))
   return;
 
 const SrcState &S = Analysis->getStateBefore(Inst);
-
-// If non-empty state was never propagated from the entry basic block
-// to Inst, assume it to be unreachable and report a warning.
-if (S.empty()) {
-  Reports.push_back(
-  make_generic_report(Inst, "Warning: unreachable instruction found"));
-  return;
-}
+assert(!S.empty() && "Instruction has no associated state");
 
 if (auto Report = shouldReportReturnGadget(BC, Inst, S))
   Reports.push_back(*Report);
diff --git a/bolt/test/binary-analysis/AArch64/gs-pacret-autiasp.s 
b/bolt/test/binary-analysis/AArch64/gs-pacret-autiasp.s
index 2193d40131478..a8cc6352de438 100644
--- a/bolt/test/binary-analysis/AArch64/gs-pacret-autiasp.s
+++ b/bolt/test/binary-analysis/AArch64/gs-pacret-autiasp.s
@@ -215,7 +215,7 @@ f_callclobbered_calleesaved:
 .globl  f_unreachable_instruction
 .type   f_unreachable_instruction,@function
 f_unreachable_instruction:
-// CHECK-LABEL: GS-PAUTH: Warning: unreachable instruction found in function 
f_unreachable_instruction, basic block {{[0-9a-zA-Z.]+}}, at address
+// CHECK-LABEL: GS-PAUTH: Warning: no predecessor basic blocks detected 
(possibly incomplete CFG) in function f_unreachable_instruction, basic block 
{{[0-9a-zA-Z.]+}}, at address
 // CHECK-NEXT:The instruction is {{[0-9a-f]+}}:   add x0, x1, 
x2
 b   1f
 add x0, x1, x2
diff --git a/bolt/test/binary-analysis/AArch64/gs-pauth-calls.s 
b/bolt/test/binary-analysis/AArch64/gs-pauth-calls.s
index c79c5926a05cd..c20b

[llvm-branch-commits] [llvm] [BOLT] Gadget scanner: improve handling of unreachable basic blocks (PR #136183)

2025-04-17 Thread Anatoly Trosinenko via llvm-branch-commits

https://github.com/atrosinenko ready_for_review 
https://github.com/llvm/llvm-project/pull/136183
___
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] [ci] skip clang installation and separate configuration for runtimes. (PR #136162)

2025-04-17 Thread Matheus Izvekov via llvm-branch-commits

https://github.com/mizvekov created 
https://github.com/llvm/llvm-project/pull/136162

They will be built with the just built clang either way. This avoids building 
the runtimes twice when LLDB is also tested.

>From cb827a1a19380f47213e5f2bafc32a5a8a9f32fe Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Thu, 17 Apr 2025 13:45:09 -0300
Subject: [PATCH] [ci] skip clang installation and separate configuration for
 runtimes.

They will be built with the just built clang either way.
This avoids building the runtimes twice when LLDB is also tested.
---
 .ci/monolithic-linux.sh | 53 +++--
 1 file changed, 14 insertions(+), 39 deletions(-)

diff --git a/.ci/monolithic-linux.sh b/.ci/monolithic-linux.sh
index 2e4b4e6118efd..1fa72bdcd066d 100755
--- a/.ci/monolithic-linux.sh
+++ b/.ci/monolithic-linux.sh
@@ -18,7 +18,6 @@ set -o pipefail
 
 MONOREPO_ROOT="${MONOREPO_ROOT:="$(git rev-parse --show-toplevel)"}"
 BUILD_DIR="${BUILD_DIR:=${MONOREPO_ROOT}/build}"
-INSTALL_DIR="${BUILD_DIR}/install"
 rm -rf "${BUILD_DIR}"
 
 ccache --zero-stats
@@ -81,69 +80,45 @@ cmake -S "${MONOREPO_ROOT}"/llvm -B "${BUILD_DIR}" \
   -D LIBCXX_CXX_ABI=libcxxabi \
   -D MLIR_ENABLE_BINDINGS_PYTHON=ON \
   -D LLDB_ENABLE_PYTHON=ON \
-  -D LLDB_ENFORCE_STRICT_TEST_REQUIREMENTS=ON \
-  -D CMAKE_INSTALL_PREFIX="${INSTALL_DIR}"
+  -D LLDB_ENFORCE_STRICT_TEST_REQUIREMENTS=ON
 
 echo "--- ninja"
+
 # Targets are not escaped as they are passed as separate arguments.
 ninja -C "${BUILD_DIR}" -k 0 ${targets}
 
 runtimes="${3}"
 runtime_targets="${4}"
 
-# Compiling runtimes with just-built Clang and running their tests
-# as an additional testing for Clang.
+# Run runtimes tests.
+# We don't need to do a clean separate build of runtimes, because runtimes
+# will be built against just built clang, and because LIBCXX_TEST_PARAMS
+# and LIBCXXABI_TEST_PARAMS only affect lit configuration, which successfully
+# propagates without a clean build. Other that those two variables, builds
+# are supposed to be the same.
 if [[ "${runtimes}" != "" ]]; then
   if [[ "${runtime_targets}" == "" ]]; then
 echo "Runtimes to build are specified, but targets are not."
 exit 1
   fi
 
-  echo "--- ninja install-clang"
-
-  ninja -C ${BUILD_DIR} install-clang install-clang-resource-headers
-
-  RUNTIMES_BUILD_DIR="${MONOREPO_ROOT}/build-runtimes"
-  INSTALL_DIR="${BUILD_DIR}/install"
-  mkdir -p ${RUNTIMES_BUILD_DIR}
-
   echo "--- cmake runtimes C++26"
 
-  rm -rf "${RUNTIMES_BUILD_DIR}"
-  cmake -S "${MONOREPO_ROOT}/runtimes" -B "${RUNTIMES_BUILD_DIR}" -GNinja \
-  -D CMAKE_C_COMPILER="${INSTALL_DIR}/bin/clang" \
-  -D CMAKE_CXX_COMPILER="${INSTALL_DIR}/bin/clang++" \
-  -D LLVM_ENABLE_RUNTIMES="${runtimes}" \
-  -D LIBCXX_CXX_ABI=libcxxabi \
-  -D CMAKE_BUILD_TYPE=RelWithDebInfo \
-  -D CMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
+  cmake -S "${MONOREPO_ROOT}"/llvm -B "${BUILD_DIR}" \
   -D LIBCXX_TEST_PARAMS="std=c++26" \
-  -D LIBCXXABI_TEST_PARAMS="std=c++26" \
-  -D LLVM_LIT_ARGS="${lit_args}"
+  -D LIBCXXABI_TEST_PARAMS="std=c++26"
 
   echo "--- ninja runtimes C++26"
 
-  ninja -vC "${RUNTIMES_BUILD_DIR}" ${runtime_targets}
+  ninja -vC "${BUILD_DIR}" ${runtime_targets}
 
   echo "--- cmake runtimes clang modules"
 
-  # We don't need to do a clean build of runtimes, because LIBCXX_TEST_PARAMS
-  # and LIBCXXABI_TEST_PARAMS only affect lit configuration, which successfully
-  # propagates without a clean build. Other that those two variables, builds
-  # are supposed to be the same.
-
-  cmake -S "${MONOREPO_ROOT}/runtimes" -B "${RUNTIMES_BUILD_DIR}" -GNinja \
-  -D CMAKE_C_COMPILER="${INSTALL_DIR}/bin/clang" \
-  -D CMAKE_CXX_COMPILER="${INSTALL_DIR}/bin/clang++" \
-  -D LLVM_ENABLE_RUNTIMES="${runtimes}" \
-  -D LIBCXX_CXX_ABI=libcxxabi \
-  -D CMAKE_BUILD_TYPE=RelWithDebInfo \
-  -D CMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
+  cmake -S "${MONOREPO_ROOT}"/llvm -B "${BUILD_DIR}" \
   -D LIBCXX_TEST_PARAMS="enable_modules=clang" \
-  -D LIBCXXABI_TEST_PARAMS="enable_modules=clang" \
-  -D LLVM_LIT_ARGS="${lit_args}"
+  -D LIBCXXABI_TEST_PARAMS="enable_modules=clang"
 
   echo "--- ninja runtimes clang modules"
 
-  ninja -vC "${RUNTIMES_BUILD_DIR}" ${runtime_targets}
+  ninja -vC "${BUILD_DIR}" ${runtime_targets}
 fi

___
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: improve handling of unreachable basic blocks (PR #136183)

2025-04-17 Thread Anatoly Trosinenko via llvm-branch-commits

https://github.com/atrosinenko created 
https://github.com/llvm/llvm-project/pull/136183

Instead of refusing to analyze an instruction completely, when it is
unreachable according to the CFG reconstructed by BOLT, pessimistically
assume all registers to be unsafe at the start of basic blocks without
any predecessors. Nevertheless, unreachable basic blocks found in
optimized code likely means imprecise CFG reconstruction, thus report a
warning once per basic block without predecessors.

>From b3acb468d096dd3e5e7fdae395cd6a6c60f7e5df Mon Sep 17 00:00:00 2001
From: Anatoly Trosinenko 
Date: Thu, 17 Apr 2025 20:51:16 +0300
Subject: [PATCH] [BOLT] Gadget scanner: improve handling of unreachable basic
 blocks

Instead of refusing to analyze an instruction completely, when it is
unreachable according to the CFG reconstructed by BOLT, pessimistically
assume all registers to be unsafe at the start of basic blocks without
any predecessors. Nevertheless, unreachable basic blocks found in
optimized code likely means imprecise CFG reconstruction, thus report a
warning once per basic block without predecessors.
---
 bolt/lib/Passes/PAuthGadgetScanner.cpp| 46 ++-
 .../AArch64/gs-pacret-autiasp.s   |  2 +-
 .../binary-analysis/AArch64/gs-pauth-calls.s  | 57 +++
 3 files changed, 90 insertions(+), 15 deletions(-)

diff --git a/bolt/lib/Passes/PAuthGadgetScanner.cpp 
b/bolt/lib/Passes/PAuthGadgetScanner.cpp
index 2d2126bf05ae1..f998b8fa0f950 100644
--- a/bolt/lib/Passes/PAuthGadgetScanner.cpp
+++ b/bolt/lib/Passes/PAuthGadgetScanner.cpp
@@ -346,6 +346,12 @@ class SrcSafetyAnalysis {
 return S;
   }
 
+  /// Creates a state with all registers marked unsafe (not to be confused
+  /// with empty state).
+  SrcState createUnsafeState() const {
+return SrcState(NumRegs, RegsToTrackInstsFor.getNumTrackedRegisters());
+  }
+
   BitVector getClobberedRegs(const MCInst &Point) const {
 BitVector Clobbered(NumRegs);
 // Assume a call can clobber all registers, including callee-saved
@@ -585,6 +591,13 @@ class DataflowSrcSafetyAnalysis
 if (BB.isEntryPoint())
   return createEntryState();
 
+// If a basic block without any predecessors is found in an optimized code,
+// this likely means that some CFG edges were not detected. Pessimistically
+// assume all registers to be unsafe before this basic block and warn about
+// this fact in FunctionAnalysis::findUnsafeUses().
+if (BB.pred_empty())
+  return createUnsafeState();
+
 return SrcState();
   }
 
@@ -658,12 +671,6 @@ class CFGUnawareSrcSafetyAnalysis : public 
SrcSafetyAnalysis {
   BC.MIB->removeAnnotation(I.second, StateAnnotationIndex);
   }
 
-  /// Creates a state with all registers marked unsafe (not to be confused
-  /// with empty state).
-  SrcState createUnsafeState() const {
-return SrcState(NumRegs, RegsToTrackInstsFor.getNumTrackedRegisters());
-  }
-
 public:
   CFGUnawareSrcSafetyAnalysis(BinaryFunction &BF,
   MCPlusBuilder::AllocatorIdTy AllocId,
@@ -1335,19 +1342,30 @@ void FunctionAnalysis::findUnsafeUses(
 BF.dump();
   });
 
+  if (BF.hasCFG()) {
+// Warn on basic blocks being unreachable according to BOLT, as this
+// likely means CFG is imprecise.
+for (BinaryBasicBlock &BB : BF) {
+  if (!BB.pred_empty() || BB.isEntryPoint())
+continue;
+  // Arbitrarily attach the report to the first instruction of BB.
+  MCInst *InstToReport = BB.getFirstNonPseudoInstr();
+  if (!InstToReport)
+continue; // BB has no real instructions
+
+  Reports.push_back(
+  make_generic_report(MCInstReference::get(InstToReport, BF),
+  "Warning: no predecessor basic blocks detected "
+  "(possibly incomplete CFG)"));
+}
+  }
+
   iterateOverInstrs(BF, [&](MCInstReference Inst) {
 if (BC.MIB->isCFI(Inst))
   return;
 
 const SrcState &S = Analysis->getStateBefore(Inst);
-
-// If non-empty state was never propagated from the entry basic block
-// to Inst, assume it to be unreachable and report a warning.
-if (S.empty()) {
-  Reports.push_back(
-  make_generic_report(Inst, "Warning: unreachable instruction found"));
-  return;
-}
+assert(!S.empty() && "Instruction has no associated state");
 
 if (auto Report = shouldReportReturnGadget(BC, Inst, S))
   Reports.push_back(*Report);
diff --git a/bolt/test/binary-analysis/AArch64/gs-pacret-autiasp.s 
b/bolt/test/binary-analysis/AArch64/gs-pacret-autiasp.s
index 2193d40131478..a8cc6352de438 100644
--- a/bolt/test/binary-analysis/AArch64/gs-pacret-autiasp.s
+++ b/bolt/test/binary-analysis/AArch64/gs-pacret-autiasp.s
@@ -215,7 +215,7 @@ f_callclobbered_calleesaved:
 .globl  f_unreachable_instruction
 .type   f_unreachable_instruction,@function
 f_unreachable_instruction:
-// CHECK-LABEL: GS-PAUTH: Warning: unreachable ins

[llvm-branch-commits] [lldb] [lldb] Fix SBTarget::ReadInstruction with flavor (PR #136034)

2025-04-17 Thread Nikita Popov via llvm-branch-commits

https://github.com/nikic milestoned 
https://github.com/llvm/llvm-project/pull/136034
___
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] [lldb] [lldb] Create ThreadPlanStepOut ctor that never skips frames (PR #136163)

2025-04-17 Thread Felipe de Azevedo Piovezan via llvm-branch-commits

https://github.com/felipepiovezan updated 
https://github.com/llvm/llvm-project/pull/136163

>From 0a2dc4a280d83ca35bc4458ecb939f96e4dee8af Mon Sep 17 00:00:00 2001
From: Felipe de Azevedo Piovezan 
Date: Thu, 17 Apr 2025 11:34:39 -0700
Subject: [PATCH 1/3] fixup! Run clang-format

---
 lldb/source/Target/ThreadPlanStepOut.cpp | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lldb/source/Target/ThreadPlanStepOut.cpp 
b/lldb/source/Target/ThreadPlanStepOut.cpp
index b3c9a790487d4..f2606403016a6 100644
--- a/lldb/source/Target/ThreadPlanStepOut.cpp
+++ b/lldb/source/Target/ThreadPlanStepOut.cpp
@@ -79,8 +79,8 @@ ThreadPlanStepOut::ThreadPlanStepOut(
   ComputeTargetFrame(thread, frame_idx, m_stepped_past_frames);
   StackFrameSP 
immediate_return_from_sp(thread.GetStackFrameAtIndex(frame_idx));
 
-  SetupReturnAddress(return_frame_sp, immediate_return_from_sp,
- frame_idx, continue_to_next_branch);
+  SetupReturnAddress(return_frame_sp, immediate_return_from_sp, frame_idx,
+ continue_to_next_branch);
 }
 
 void ThreadPlanStepOut::SetupReturnAddress(
@@ -101,8 +101,8 @@ void ThreadPlanStepOut::SetupReturnAddress(
   // First queue a plan that gets us to this inlined frame, and when we get
   // there we'll queue a second plan that walks us out of this frame.
   m_step_out_to_inline_plan_sp = std::make_shared(
-  GetThread(), nullptr, false, m_stop_others, eVoteNoOpinion, 
eVoteNoOpinion,
-  frame_idx - 1, eLazyBoolNo, continue_to_next_branch);
+  GetThread(), nullptr, false, m_stop_others, eVoteNoOpinion,
+  eVoteNoOpinion, frame_idx - 1, eLazyBoolNo, continue_to_next_branch);
   static_cast(m_step_out_to_inline_plan_sp.get())
   ->SetShouldStopHereCallbacks(nullptr, nullptr);
   m_step_out_to_inline_plan_sp->SetPrivate(true);

>From 923f6c73fae39c0f4686a65282c81755fa876b70 Mon Sep 17 00:00:00 2001
From: Felipe de Azevedo Piovezan 
Date: Thu, 17 Apr 2025 09:36:22 -0700
Subject: [PATCH 2/3] [lldb] Create ThreadPlanStepOut ctor that never skips
 frames

The function QueueThreadPlanForStepOutNoShouldStop has the semantics of
"go this parent frame"; ThreadPlanStepOut needs to respect that, not
skipping over any frames it finds uninteresting. This commit creates a
constructor that respects such instruction.
---
 lldb/include/lldb/Target/ThreadPlanStepOut.h |  9 
 lldb/source/Target/Thread.cpp|  5 ++---
 lldb/source/Target/ThreadPlanStepOut.cpp | 22 
 3 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/lldb/include/lldb/Target/ThreadPlanStepOut.h 
b/lldb/include/lldb/Target/ThreadPlanStepOut.h
index e414a6e0a2d49..9a62f6102d368 100644
--- a/lldb/include/lldb/Target/ThreadPlanStepOut.h
+++ b/lldb/include/lldb/Target/ThreadPlanStepOut.h
@@ -17,6 +17,9 @@ namespace lldb_private {
 
 class ThreadPlanStepOut : public ThreadPlan, public ThreadPlanShouldStopHere {
 public:
+  /// Creates a thread plan to step out from frame_idx, skipping parent frames
+  /// that artificial and hidden frames. Also skips frames without debug info
+  /// based on step_out_avoids_code_without_debug_info.
   ThreadPlanStepOut(Thread &thread, SymbolContext *addr_context,
 bool first_insn, bool stop_others, Vote report_stop_vote,
 Vote report_run_vote, uint32_t frame_idx,
@@ -24,6 +27,12 @@ class ThreadPlanStepOut : public ThreadPlan, public 
ThreadPlanShouldStopHere {
 bool continue_to_next_branch = false,
 bool gather_return_value = true);
 
+  /// Creates a thread plan to step out from frame_idx to frame_idx + 1.
+  ThreadPlanStepOut(Thread &thread, bool stop_others, Vote report_stop_vote,
+Vote report_run_vote, uint32_t frame_idx,
+bool continue_to_next_branch = false,
+bool gather_return_value = true);
+
   ~ThreadPlanStepOut() override;
 
   void GetDescription(Stream *s, lldb::DescriptionLevel level) override;
diff --git a/lldb/source/Target/Thread.cpp b/lldb/source/Target/Thread.cpp
index accc4708c24e1..b0e0f1e67c060 100644
--- a/lldb/source/Target/Thread.cpp
+++ b/lldb/source/Target/Thread.cpp
@@ -1360,9 +1360,8 @@ ThreadPlanSP 
Thread::QueueThreadPlanForStepOutNoShouldStop(
   const bool calculate_return_value =
   false; // No need to calculate the return value here.
   ThreadPlanSP thread_plan_sp(new ThreadPlanStepOut(
-  *this, addr_context, first_insn, stop_other_threads, report_stop_vote,
-  report_run_vote, frame_idx, eLazyBoolNo, continue_to_next_branch,
-  calculate_return_value));
+  *this, stop_other_threads, report_stop_vote, report_run_vote, frame_idx,
+  continue_to_next_branch, calculate_return_value));
 
   ThreadPlanStepOut *new_plan =
   static_cast(thread_plan_sp.get());
diff --git a/lldb/source/Target/ThreadPlanStepOut.cpp 
b/lldb/source/Target/ThreadPlanStepOut.c

[llvm-branch-commits] [clang] release/20.x: [clang-format] Fix mismatched break in BlockIndent (#124998) (PR #136238)

2025-04-17 Thread via llvm-branch-commits

llvmbot wrote:

@gedare What do you think about merging this PR to the release branch?

https://github.com/llvm/llvm-project/pull/136238
___
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] release/20.x: [clang-format] Fix mismatched break in BlockIndent (#124998) (PR #136238)

2025-04-17 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: None (llvmbot)


Changes

Backport b8734797a3f605c4aaa37fcb5007baa273565460

Requested by: @owenca

---
Full diff: https://github.com/llvm/llvm-project/pull/136238.diff


2 Files Affected:

- (modified) clang/lib/Format/ContinuationIndenter.cpp (+7) 
- (modified) clang/unittests/Format/FormatTest.cpp (+4) 


``diff
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index c311deaa17bb0..6f7d213c0b559 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -349,6 +349,13 @@ bool ContinuationIndenter::canBreak(const LineState 
&State) {
 }
   }
 
+  // Allow breaking before the right parens with block indentation if there was
+  // a break after the left parens, which is tracked by 
BreakBeforeClosingParen.
+  if (Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent &&
+  Current.is(tok::r_paren)) {
+return CurrentState.BreakBeforeClosingParen;
+  }
+
   // Don't allow breaking before a closing brace of a block-indented braced 
list
   // initializer if there isn't already a break.
   if (Current.is(tok::r_brace) && Current.MatchingParen &&
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 44341fbfe895f..bf3eff129efd5 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -9614,6 +9614,10 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) {
"auto a\n"
") {};",
Style);
+  verifyFormat("(\n"
+   "&b\n"
+   ");",
+   Style);
 }
 
 TEST_F(FormatTest, ParenthesesAndOperandAlignment) {

``




https://github.com/llvm/llvm-project/pull/136238
___
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] release/20.x: [clang-format] Fix mismatched break in BlockIndent (#124998) (PR #136238)

2025-04-17 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/136238
___
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] [lldb] [llvm] [ci] add dependencies for lldb python binding tests (PR #136158)

2025-04-17 Thread Aiden Grossman via llvm-branch-commits


@@ -63,9 +63,13 @@ pip install -q -r "${MONOREPO_ROOT}"/.ci/requirements.txt
 export LLVM_SYMBOLIZER_PATH=`which llvm-symbolizer`
 [[ ! -f "${LLVM_SYMBOLIZER_PATH}" ]] && echo "llvm-symbolizer not found!"
 
+# Set up all runtimes either way. libcxx is a dependency of LLDB.
+# If it ends up being unused, not much harm.

boomanaiden154 wrote:

I would change "not much harm" to explicitly enumerate that we do not end up 
configuring or building it if we we do not explicitly run those check/build 
targets.

https://github.com/llvm/llvm-project/pull/136158
___
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] [lldb] [llvm] [ci] add dependencies for lldb python binding tests (PR #136158)

2025-04-17 Thread Aiden Grossman via llvm-branch-commits


@@ -5,3 +5,5 @@ psutil>=5.9.4
 # See llvm.org/pr22274.
 pexpect>=4.9.0; sys_platform != 'win32'
 packaging
+# Required for python tests
+swig

boomanaiden154 wrote:

This should probably have at least some versioning information tied to it?

https://github.com/llvm/llvm-project/pull/136158
___
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)

2025-04-17 Thread Fangrui Song via llvm-branch-commits

https://github.com/MaskRay commented:

LGTM. As I'm not familiar with z/OS, my review focused on its compatibility 
with the current MC infrastructure. (My internet access will be limited between 
April 20th and May 4th, which may cause delays in my response time.)

Thanks for reimplementing the getPPA1/PPA2 stuff that puzzled me :)

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] [llvm] 9f06475 - Revert "[AMDGPU] Implement vop3p complex pattern optmization for gisel (#130234)"

2025-04-17 Thread via llvm-branch-commits

Author: Shoreshen
Date: 2025-04-18T11:13:53+08:00
New Revision: 9f0647536e893f7ba104dda2ab8895abd6a83c0c

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

LOG: Revert "[AMDGPU] Implement vop3p complex pattern optmization for gisel 
(#130234)"

This reverts commit a04580f71b98bdb12100da66c9975e9a1001b4d6.

Added: 


Modified: 
llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp
llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.h
llvm/test/CodeGen/AMDGPU/GlobalISel/fmul.v2f16.ll
llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.sdot2.ll
llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.udot2.ll
llvm/test/CodeGen/AMDGPU/strict_fsub.f16.ll

Removed: 




diff  --git a/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp
index 87af467ac8f1e..6ef7505ec6f62 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp
@@ -4319,598 +4319,60 @@ 
AMDGPUInstructionSelector::selectVOP3NoMods(MachineOperand &Root) const {
   }};
 }
 
-enum class SrcStatus {
-  IS_SAME,
-  IS_UPPER_HALF,
-  IS_LOWER_HALF,
-  IS_UPPER_HALF_NEG,
-  // This means current op = [op_upper, op_lower] and src = -op_lower.
-  IS_LOWER_HALF_NEG,
-  IS_HI_NEG,
-  // This means current op = [op_upper, op_lower] and src = [op_upper,
-  // -op_lower].
-  IS_LO_NEG,
-  IS_BOTH_NEG,
-  INVALID,
-  NEG_START = IS_UPPER_HALF_NEG,
-  NEG_END = IS_BOTH_NEG,
-  HALF_START = IS_UPPER_HALF,
-  HALF_END = IS_LOWER_HALF_NEG
-};
-
-static bool isTruncHalf(const MachineInstr *MI,
-const MachineRegisterInfo &MRI) {
-  if (MI->getOpcode() != AMDGPU::G_TRUNC)
-return false;
-
-  unsigned DstSize = MRI.getType(MI->getOperand(0).getReg()).getSizeInBits();
-  unsigned SrcSize = MRI.getType(MI->getOperand(1).getReg()).getSizeInBits();
-  return DstSize * 2 == SrcSize;
-}
-
-static bool isLshrHalf(const MachineInstr *MI, const MachineRegisterInfo &MRI) 
{
-  if (MI->getOpcode() != AMDGPU::G_LSHR)
-return false;
-
-  Register ShiftSrc;
-  std::optional ShiftAmt;
-  if (mi_match(MI->getOperand(0).getReg(), MRI,
-   m_GLShr(m_Reg(ShiftSrc), m_GCst(ShiftAmt {
-unsigned SrcSize = MRI.getType(MI->getOperand(1).getReg()).getSizeInBits();
-unsigned Shift = ShiftAmt->Value.getZExtValue();
-return Shift * 2 == SrcSize;
-  }
-  return false;
-}
-
-static bool isShlHalf(const MachineInstr *MI, const MachineRegisterInfo &MRI) {
-  if (MI->getOpcode() != AMDGPU::G_SHL)
-return false;
-
-  Register ShiftSrc;
-  std::optional ShiftAmt;
-  if (mi_match(MI->getOperand(0).getReg(), MRI,
-   m_GShl(m_Reg(ShiftSrc), m_GCst(ShiftAmt {
-unsigned SrcSize = MRI.getType(MI->getOperand(1).getReg()).getSizeInBits();
-unsigned Shift = ShiftAmt->Value.getZExtValue();
-return Shift * 2 == SrcSize;
-  }
-  return false;
-}
-
-static std::optional>
-retOpStat(const MachineOperand *Op, SrcStatus Stat,
-  std::pair &Curr) {
-  if (Stat != SrcStatus::INVALID &&
-  ((Op->isReg() && !(Op->getReg().isPhysical())) || Op->isImm() ||
-   Op->isCImm() || Op->isFPImm())) {
-return std::optional>(
-{Op, Stat});
-  }
-
-  return std::nullopt;
-}
-
-enum class TypeClass { VECTOR_OF_TWO, SCALAR, NONE_OF_LISTED };
-
-static TypeClass isVectorOfTwoOrScalar(const MachineOperand *Op,
-   const MachineRegisterInfo &MRI) {
-  if (!Op->isReg() || Op->getReg().isPhysical())
-return TypeClass::NONE_OF_LISTED;
-  LLT OpTy = MRI.getType(Op->getReg());
-  if (OpTy.isScalar())
-return TypeClass::SCALAR;
-  if (OpTy.isVector() && OpTy.getNumElements() == 2)
-return TypeClass::VECTOR_OF_TWO;
-  return TypeClass::NONE_OF_LISTED;
-}
-
-static SrcStatus getNegStatus(const MachineOperand *Op, SrcStatus S,
-  const MachineRegisterInfo &MRI) {
-  TypeClass NegType = isVectorOfTwoOrScalar(Op, MRI);
-  if (NegType != TypeClass::VECTOR_OF_TWO && NegType != TypeClass::SCALAR)
-return SrcStatus::INVALID;
-
-  switch (S) {
-  case SrcStatus::IS_SAME:
-if (NegType == TypeClass::VECTOR_OF_TWO) {
-  // Vector of 2:
-  // [SrcHi, SrcLo]   = [CurrHi, CurrLo]
-  // [CurrHi, CurrLo] = neg [OpHi, OpLo](2 x Type)
-  // [CurrHi, CurrLo] = [-OpHi, -OpLo](2 x Type)
-  // [SrcHi, SrcLo]   = [-OpHi, -OpLo]
-  return SrcStatus::IS_BOTH_NEG;
-} else if (NegType == TypeClass::SCALAR) {
-  // Scalar:
-  // [SrcHi, SrcLo]   = [CurrHi, CurrLo]
-  // [CurrHi, CurrLo] = neg [OpHi, OpLo](Type)
-  // [CurrHi, CurrLo] = [-OpHi, OpLo](Type)
-  // [SrcHi, SrcLo]   = [-OpHi, OpLo]
-  return SrcStatus::IS_HI_NEG;
-}
-break;
-  case SrcStatus::IS_HI_NEG:

[llvm-branch-commits] [llvm] [ci] upload any generated clang reproducers as artifacts (PR #136157)

2025-04-17 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 approved this pull request.


https://github.com/llvm/llvm-project/pull/136157
___
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] [ci] set up llvm-symbolizer environment variable (PR #136156)

2025-04-17 Thread Aiden Grossman via llvm-branch-commits

https://github.com/boomanaiden154 approved this pull request.


https://github.com/llvm/llvm-project/pull/136156
___
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] c410a82 - Revert "[HLSL][RootSignature] Implement initial parsing of the descriptor tab…"

2025-04-17 Thread via llvm-branch-commits

Author: Finn Plummer
Date: 2025-04-17T20:56:49-07:00
New Revision: c410a82b85a63274f7849de434d133a0f8706269

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

LOG: Revert "[HLSL][RootSignature] Implement initial parsing of the descriptor 
tab…"

This reverts commit 64de8528dbd89cdafe32d754f37cf3da4fb5403e.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Parse/ParseHLSLRootSignature.h
clang/lib/Parse/ParseHLSLRootSignature.cpp
clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp
llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 72e765bcb800d..9975520f4f9ff 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1836,11 +1836,8 @@ def err_hlsl_virtual_function
 def err_hlsl_virtual_inheritance
 : Error<"virtual inheritance is unsupported in HLSL">;
 
-// HLSL Root Signature Parser Diagnostics
+// 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">;
-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 e17d6584622ba..a8dd6b02501ae 100644
--- a/clang/include/clang/Parse/ParseHLSLRootSignature.h
+++ b/clang/include/clang/Parse/ParseHLSLRootSignature.h
@@ -40,31 +40,26 @@ class RootSignatureParser {
 private:
   DiagnosticsEngine &getDiags() { return PP.getDiagnostics(); }
 
-  // All private parse.* methods follow a similar pattern:
+  // All private Parse.* methods follow a similar pattern:
   //   - Each method will start with an assert to denote what the CurToken is
   // expected to be and will parse from that token forward
   //
   //   - Therefore, it is the callers responsibility to ensure that you are
   // at the correct CurToken. This should be done with the pattern of:
   //
-  //  if (tryConsumeExpectedToken(RootSignatureToken::Kind)) {
-  //auto ParsedObject = parse.*();
-  //if (!ParsedObject.has_value())
-  //  return std::nullopt;
-  //...
-  // }
+  //  if (TryConsumeExpectedToken(RootSignatureToken::Kind))
+  //if (Parse.*())
+  //  return true;
   //
   // or,
   //
-  //  if (consumeExpectedToken(RootSignatureToken::Kind, ...))
-  //return std::nullopt;
-  //  auto ParsedObject = parse.*();
-  //  if (!ParsedObject.has_value())
-  //return std::nullopt;
-  //  ...
+  //  if (ConsumeExpectedToken(RootSignatureToken::Kind, ...))
+  //return true;
+  //  if (Parse.*())
+  //return true;
   //
-  //   - All methods return std::nullopt if a parsing error is encountered. It
-  // is the callers responsibility to propogate this error up, or deal with it
+  //   - All methods return true if a parsing error is encountered. It is the
+  // callers responsibility to propogate this error up, or deal with it
   // otherwise
   //
   //   - An error will be raised if the proceeding tokens are not what is
@@ -74,23 +69,6 @@ class RootSignatureParser {
   bool parseDescriptorTable();
   bool parseDescriptorTableClause();
 
-  /// Parameter arguments (eg. `bReg`, `space`, ...) can be specified in any
-  /// order and only exactly once. `ParsedClauseParams` denotes the current
-  /// state of parsed params
-  struct ParsedClauseParams {
-std::optional Register;
-std::optional Space;
-  };
-  std::optional
-  parseDescriptorTableClauseParams(RootSignatureToken::Kind RegType);
-
-  std::optional parseUIntParam();
-  std::optional parseRegister();
-
-  /// Use NumericLiteralParser to convert CurToken.NumSpelling into a unsigned
-  /// 32-bit integer
-  std::optional handleUIntLiteral();
-
   /// 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 a13bee9750e2f..3513ef454f750 100644
--- a/clang/lib/Parse/ParseHLSLRootSignature.cpp
+++ b/clang/lib/Parse/ParseHLSLRootSignature.cpp
@@ -8,8 +8,6 @@
 
 #include "clang/Parse/ParseHLSLRootSignature.h"
 
-#include "clang/Lex/LiteralSupport.h"
-
 #include "llvm/Support/raw_ostream.h"
 
 using nam

[llvm-branch-commits] [lldb] [llvm] [ci] add dependencies for lldb python binding tests (PR #136158)

2025-04-17 Thread Jonas Devlieghere via llvm-branch-commits

https://github.com/JDevlieghere approved this pull request.


https://github.com/llvm/llvm-project/pull/136158
___
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] [lldb] [llvm] [ci] add dependencies for lldb python binding tests (PR #136158)

2025-04-17 Thread Matheus Izvekov via llvm-branch-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/136158

>From cfb1035622f1530a2c981a47c49dcae01309b617 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Thu, 17 Apr 2025 13:31:32 -0300
Subject: [PATCH] [ci] add dependencies for lldb python binding tests

Add correct configuration and dependencies for LLDB testing which
is actually relevant for clang changes.
---
 .ci/monolithic-linux.sh| 7 +++
 lldb/test/requirements.txt | 2 ++
 2 files changed, 9 insertions(+)

diff --git a/.ci/monolithic-linux.sh b/.ci/monolithic-linux.sh
index 59a6b22ccb06a..2e4b4e6118efd 100755
--- a/.ci/monolithic-linux.sh
+++ b/.ci/monolithic-linux.sh
@@ -63,9 +63,13 @@ pip install -q -r "${MONOREPO_ROOT}"/.ci/requirements.txt
 export LLVM_SYMBOLIZER_PATH=`which llvm-symbolizer`
 [[ ! -f "${LLVM_SYMBOLIZER_PATH}" ]] && echo "llvm-symbolizer not found!"
 
+# Set up all runtimes either way. libcxx is a dependency of LLDB.
+# If it ends up being unused, not much harm.
 cmake -S "${MONOREPO_ROOT}"/llvm -B "${BUILD_DIR}" \
   -D LLVM_ENABLE_PROJECTS="${projects}" \
+  -D LLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" \
   -G Ninja \
+  -D CMAKE_PREFIX_PATH="${HOME}/.local" \
   -D CMAKE_BUILD_TYPE=Release \
   -D LLVM_ENABLE_ASSERTIONS=ON \
   -D LLVM_BUILD_EXAMPLES=ON \
@@ -74,7 +78,10 @@ cmake -S "${MONOREPO_ROOT}"/llvm -B "${BUILD_DIR}" \
   -D LLVM_ENABLE_LLD=ON \
   -D CMAKE_CXX_FLAGS=-gmlt \
   -D LLVM_CCACHE_BUILD=ON \
+  -D LIBCXX_CXX_ABI=libcxxabi \
   -D MLIR_ENABLE_BINDINGS_PYTHON=ON \
+  -D LLDB_ENABLE_PYTHON=ON \
+  -D LLDB_ENFORCE_STRICT_TEST_REQUIREMENTS=ON \
   -D CMAKE_INSTALL_PREFIX="${INSTALL_DIR}"
 
 echo "--- ninja"
diff --git a/lldb/test/requirements.txt b/lldb/test/requirements.txt
index 708f2327a6a04..c187180697d0b 100644
--- a/lldb/test/requirements.txt
+++ b/lldb/test/requirements.txt
@@ -5,3 +5,5 @@ psutil>=5.9.4
 # See llvm.org/pr22274.
 pexpect>=4.9.0; sys_platform != 'win32'
 packaging
+# Required for python tests
+swig

___
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] [SPARC] Use native bitcast instructions when we have VIS3 (PR #135716)

2025-04-17 Thread via llvm-branch-commits

https://github.com/koachan updated 
https://github.com/llvm/llvm-project/pull/135716


___
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] [LoopVectorizer] Bundle partial reductions inside VPMulAccumulateReductionRecipe (PR #136173)

2025-04-17 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-transforms

Author: Sam Tebbs (SamTebbs33)


Changes

This PR bundles compatible partial reductions into a 
`VPMulAccumulateReductionRecipe` so that the cost of the extends and mul can be 
hidden. Depends on https://github.com/llvm/llvm-project/pull/113903.

At the moment only partial reductions with the same extension type are 
supported as `VPMulAccumulateReductionRecipe` only supports such a scheme.

---

Patch is 206.82 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/136173.diff


10 Files Affected:

- (modified) llvm/include/llvm/Analysis/TargetTransformInfo.h (+2) 
- (modified) llvm/lib/Analysis/TargetTransformInfo.cpp (+13) 
- (modified) llvm/lib/Transforms/Vectorize/LoopVectorize.cpp (+3-5) 
- (modified) llvm/lib/Transforms/Vectorize/VPlan.h (+62-51) 
- (modified) llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp (+19-8) 
- (modified) llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp (+36-4) 
- (modified) 
llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-dot-product-epilogue.ll
 (+83-163) 
- (modified) 
llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-dot-product-neon.ll 
(+261-501) 
- (modified) 
llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-dot-product.ll 
(+93-94) 
- (modified) llvm/test/Transforms/LoopVectorize/AArch64/vplan-printing.ll 
(+154-6) 


``diff
diff --git a/llvm/include/llvm/Analysis/TargetTransformInfo.h 
b/llvm/include/llvm/Analysis/TargetTransformInfo.h
index 99e21aca97631..78ab6d3faaf33 100644
--- a/llvm/include/llvm/Analysis/TargetTransformInfo.h
+++ b/llvm/include/llvm/Analysis/TargetTransformInfo.h
@@ -219,6 +219,8 @@ class TargetTransformInfo {
   /// Get the kind of extension that an instruction represents.
   static PartialReductionExtendKind
   getPartialReductionExtendKind(Instruction *I);
+  static PartialReductionExtendKind
+  getPartialReductionExtendKind(Instruction::CastOps ExtOpcode);
 
   /// Construct a TTI object using a type implementing the \c Concept
   /// API below.
diff --git a/llvm/lib/Analysis/TargetTransformInfo.cpp 
b/llvm/lib/Analysis/TargetTransformInfo.cpp
index 4df551aca30a7..fdef0c484e12a 100644
--- a/llvm/lib/Analysis/TargetTransformInfo.cpp
+++ b/llvm/lib/Analysis/TargetTransformInfo.cpp
@@ -993,6 +993,19 @@ 
TargetTransformInfo::getPartialReductionExtendKind(Instruction *I) {
   return PR_None;
 }
 
+TargetTransformInfo::PartialReductionExtendKind
+TargetTransformInfo::getPartialReductionExtendKind(
+Instruction::CastOps ExtOpcode) {
+  switch (ExtOpcode) {
+  case Instruction::CastOps::ZExt:
+return PR_ZeroExtend;
+  case Instruction::CastOps::SExt:
+return PR_SignExtend;
+  default:
+return PR_None;
+  }
+}
+
 TTI::CastContextHint
 TargetTransformInfo::getCastContextHint(const Instruction *I) {
   if (!I)
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp 
b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 0233a32f99e6f..030bd86847e1c 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -8879,17 +8879,15 @@ 
VPRecipeBuilder::tryToCreatePartialReduction(Instruction *Reduction,
 ReductionOpcode = Instruction::Add;
   }
 
+  VPValue *Cond = nullptr;
   if (CM.blockNeedsPredicationForAnyReason(Reduction->getParent())) {
 assert((ReductionOpcode == Instruction::Add ||
 ReductionOpcode == Instruction::Sub) &&
"Expected an ADD or SUB operation for predicated partial "
"reductions (because the neutral element in the mask is zero)!");
-VPValue *Mask = getBlockInMask(Reduction->getParent());
-VPValue *Zero =
-Plan.getOrAddLiveIn(ConstantInt::get(Reduction->getType(), 0));
-BinOp = Builder.createSelect(Mask, BinOp, Zero, Reduction->getDebugLoc());
+Cond = getBlockInMask(Reduction->getParent());
   }
-  return new VPPartialReductionRecipe(ReductionOpcode, BinOp, Accumulator,
+  return new VPPartialReductionRecipe(ReductionOpcode, Accumulator, BinOp, 
Cond,
   Reduction);
 }
 
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h 
b/llvm/lib/Transforms/Vectorize/VPlan.h
index 1724b12b23d41..660cea629d01d 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -2056,55 +2056,6 @@ class VPReductionPHIRecipe : public VPHeaderPHIRecipe,
   }
 };
 
-/// A recipe for forming partial reductions. In the loop, an accumulator and
-/// vector operand are added together and passed to the next iteration as the
-/// next accumulator. After the loop body, the accumulator is reduced to a
-/// scalar value.
-class VPPartialReductionRecipe : public VPSingleDefRecipe {
-  unsigned Opcode;
-
-public:
-  VPPartialReductionRecipe(Instruction *ReductionInst, VPValue *Op0,
-   VPValue *Op1)
-  : VPPartialReductionRecipe(ReductionInst->getOpcode(), Op0, Op1,
- Red

[llvm-branch-commits] [llvm] [LoopVectorizer] Bundle partial reductions inside VPMulAccumulateReductionRecipe (PR #136173)

2025-04-17 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-vectorizers

Author: Sam Tebbs (SamTebbs33)


Changes

This PR bundles compatible partial reductions into a 
`VPMulAccumulateReductionRecipe` so that the cost of the extends and mul can be 
hidden. Depends on https://github.com/llvm/llvm-project/pull/113903.

At the moment only partial reductions with the same extension type are 
supported as `VPMulAccumulateReductionRecipe` only supports such a scheme.

---

Patch is 206.82 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/136173.diff


10 Files Affected:

- (modified) llvm/include/llvm/Analysis/TargetTransformInfo.h (+2) 
- (modified) llvm/lib/Analysis/TargetTransformInfo.cpp (+13) 
- (modified) llvm/lib/Transforms/Vectorize/LoopVectorize.cpp (+3-5) 
- (modified) llvm/lib/Transforms/Vectorize/VPlan.h (+62-51) 
- (modified) llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp (+19-8) 
- (modified) llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp (+36-4) 
- (modified) 
llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-dot-product-epilogue.ll
 (+83-163) 
- (modified) 
llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-dot-product-neon.ll 
(+261-501) 
- (modified) 
llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-dot-product.ll 
(+93-94) 
- (modified) llvm/test/Transforms/LoopVectorize/AArch64/vplan-printing.ll 
(+154-6) 


``diff
diff --git a/llvm/include/llvm/Analysis/TargetTransformInfo.h 
b/llvm/include/llvm/Analysis/TargetTransformInfo.h
index 99e21aca97631..78ab6d3faaf33 100644
--- a/llvm/include/llvm/Analysis/TargetTransformInfo.h
+++ b/llvm/include/llvm/Analysis/TargetTransformInfo.h
@@ -219,6 +219,8 @@ class TargetTransformInfo {
   /// Get the kind of extension that an instruction represents.
   static PartialReductionExtendKind
   getPartialReductionExtendKind(Instruction *I);
+  static PartialReductionExtendKind
+  getPartialReductionExtendKind(Instruction::CastOps ExtOpcode);
 
   /// Construct a TTI object using a type implementing the \c Concept
   /// API below.
diff --git a/llvm/lib/Analysis/TargetTransformInfo.cpp 
b/llvm/lib/Analysis/TargetTransformInfo.cpp
index 4df551aca30a7..fdef0c484e12a 100644
--- a/llvm/lib/Analysis/TargetTransformInfo.cpp
+++ b/llvm/lib/Analysis/TargetTransformInfo.cpp
@@ -993,6 +993,19 @@ 
TargetTransformInfo::getPartialReductionExtendKind(Instruction *I) {
   return PR_None;
 }
 
+TargetTransformInfo::PartialReductionExtendKind
+TargetTransformInfo::getPartialReductionExtendKind(
+Instruction::CastOps ExtOpcode) {
+  switch (ExtOpcode) {
+  case Instruction::CastOps::ZExt:
+return PR_ZeroExtend;
+  case Instruction::CastOps::SExt:
+return PR_SignExtend;
+  default:
+return PR_None;
+  }
+}
+
 TTI::CastContextHint
 TargetTransformInfo::getCastContextHint(const Instruction *I) {
   if (!I)
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp 
b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 0233a32f99e6f..030bd86847e1c 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -8879,17 +8879,15 @@ 
VPRecipeBuilder::tryToCreatePartialReduction(Instruction *Reduction,
 ReductionOpcode = Instruction::Add;
   }
 
+  VPValue *Cond = nullptr;
   if (CM.blockNeedsPredicationForAnyReason(Reduction->getParent())) {
 assert((ReductionOpcode == Instruction::Add ||
 ReductionOpcode == Instruction::Sub) &&
"Expected an ADD or SUB operation for predicated partial "
"reductions (because the neutral element in the mask is zero)!");
-VPValue *Mask = getBlockInMask(Reduction->getParent());
-VPValue *Zero =
-Plan.getOrAddLiveIn(ConstantInt::get(Reduction->getType(), 0));
-BinOp = Builder.createSelect(Mask, BinOp, Zero, Reduction->getDebugLoc());
+Cond = getBlockInMask(Reduction->getParent());
   }
-  return new VPPartialReductionRecipe(ReductionOpcode, BinOp, Accumulator,
+  return new VPPartialReductionRecipe(ReductionOpcode, Accumulator, BinOp, 
Cond,
   Reduction);
 }
 
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h 
b/llvm/lib/Transforms/Vectorize/VPlan.h
index 1724b12b23d41..660cea629d01d 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -2056,55 +2056,6 @@ class VPReductionPHIRecipe : public VPHeaderPHIRecipe,
   }
 };
 
-/// A recipe for forming partial reductions. In the loop, an accumulator and
-/// vector operand are added together and passed to the next iteration as the
-/// next accumulator. After the loop body, the accumulator is reduced to a
-/// scalar value.
-class VPPartialReductionRecipe : public VPSingleDefRecipe {
-  unsigned Opcode;
-
-public:
-  VPPartialReductionRecipe(Instruction *ReductionInst, VPValue *Op0,
-   VPValue *Op1)
-  : VPPartialReductionRecipe(ReductionInst->getOpcode(), Op0, Op1,
- Reducti

[llvm-branch-commits] [lldb] [lldb] Create ThreadPlanStepOut ctor that never skips frames (PR #136163)

2025-04-17 Thread Felipe de Azevedo Piovezan via llvm-branch-commits

https://github.com/felipepiovezan created 
https://github.com/llvm/llvm-project/pull/136163

The function QueueThreadPlanForStepOutNoShouldStop has the semantics of "go 
this parent frame"; ThreadPlanStepOut needs to respect that, not skipping over 
any frames it finds uninteresting. This commit creates a constructor that 
respects such instruction.

>From bde0158076982b16b3ae8341fa7553e1a22eb33a Mon Sep 17 00:00:00 2001
From: Felipe de Azevedo Piovezan 
Date: Thu, 17 Apr 2025 09:36:22 -0700
Subject: [PATCH] [lldb] Create ThreadPlanStepOut ctor that never skips frames

The function QueueThreadPlanForStepOutNoShouldStop has the semantics of
"go this parent frame"; ThreadPlanStepOut needs to respect that, not
skipping over any frames it finds uninteresting. This commit creates a
constructor that respects such instruction.
---
 lldb/include/lldb/Target/ThreadPlanStepOut.h |  9 
 lldb/source/Target/Thread.cpp|  2 +-
 lldb/source/Target/ThreadPlanStepOut.cpp | 22 
 3 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/lldb/include/lldb/Target/ThreadPlanStepOut.h 
b/lldb/include/lldb/Target/ThreadPlanStepOut.h
index f37d09467dda3..bc106380bca5c 100644
--- a/lldb/include/lldb/Target/ThreadPlanStepOut.h
+++ b/lldb/include/lldb/Target/ThreadPlanStepOut.h
@@ -17,12 +17,21 @@ namespace lldb_private {
 
 class ThreadPlanStepOut : public ThreadPlan, public ThreadPlanShouldStopHere {
 public:
+  /// Creates a thread plan to step out from frame_idx, skipping parent frames
+  /// that artificial and hidden frames. Also skips frames without debug info
+  /// based on step_out_avoids_code_without_debug_info.
   ThreadPlanStepOut(Thread &thread, bool stop_others, Vote report_stop_vote,
 Vote report_run_vote, uint32_t frame_idx,
 LazyBool step_out_avoids_code_without_debug_info,
 bool continue_to_next_branch = false,
 bool gather_return_value = true);
 
+  /// Creates a thread plan to step out from frame_idx to frame_idx + 1.
+  ThreadPlanStepOut(Thread &thread, bool stop_others, Vote report_stop_vote,
+Vote report_run_vote, uint32_t frame_idx,
+bool continue_to_next_branch = false,
+bool gather_return_value = true);
+
   ~ThreadPlanStepOut() override;
 
   void GetDescription(Stream *s, lldb::DescriptionLevel level) override;
diff --git a/lldb/source/Target/Thread.cpp b/lldb/source/Target/Thread.cpp
index ddd4315b6cc9e..1d941a3614275 100644
--- a/lldb/source/Target/Thread.cpp
+++ b/lldb/source/Target/Thread.cpp
@@ -1360,7 +1360,7 @@ ThreadPlanSP 
Thread::QueueThreadPlanForStepOutNoShouldStop(
   false; // No need to calculate the return value here.
   ThreadPlanSP thread_plan_sp(new ThreadPlanStepOut(
   *this, stop_other_threads, report_stop_vote, report_run_vote, frame_idx,
-  eLazyBoolNo, continue_to_next_branch, calculate_return_value));
+  continue_to_next_branch, calculate_return_value));
 
   ThreadPlanStepOut *new_plan =
   static_cast(thread_plan_sp.get());
diff --git a/lldb/source/Target/ThreadPlanStepOut.cpp 
b/lldb/source/Target/ThreadPlanStepOut.cpp
index 546405c267601..c7da0e2be89b4 100644
--- a/lldb/source/Target/ThreadPlanStepOut.cpp
+++ b/lldb/source/Target/ThreadPlanStepOut.cpp
@@ -83,6 +83,28 @@ ThreadPlanStepOut::ThreadPlanStepOut(
  frame_idx, continue_to_next_branch);
 }
 
+ThreadPlanStepOut::ThreadPlanStepOut(Thread &thread, bool stop_others,
+ Vote report_stop_vote,
+ Vote report_run_vote, uint32_t frame_idx,
+ bool continue_to_next_branch,
+ bool gather_return_value)
+: ThreadPlan(ThreadPlan::eKindStepOut, "Step out", thread, 
report_stop_vote,
+ report_run_vote),
+  ThreadPlanShouldStopHere(this), m_return_bp_id(LLDB_INVALID_BREAK_ID),
+  m_return_addr(LLDB_INVALID_ADDRESS), m_stop_others(stop_others),
+  m_immediate_step_from_function(nullptr),
+  m_calculate_return_value(gather_return_value) {
+  SetFlagsToDefault();
+  m_step_from_insn = thread.GetRegisterContext()->GetPC(0);
+
+  StackFrameSP return_frame_sp = thread.GetStackFrameAtIndex(frame_idx + 1);
+  StackFrameSP immediate_return_from_sp =
+  thread.GetStackFrameAtIndex(frame_idx);
+
+  SetupReturnAddress(return_frame_sp, immediate_return_from_sp, frame_idx,
+ continue_to_next_branch);
+}
+
 void ThreadPlanStepOut::SetupReturnAddress(
 StackFrameSP return_frame_sp, StackFrameSP immediate_return_from_sp,
 uint32_t frame_idx, bool continue_to_next_branch) {

___
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] [LoopVectorizer] Bundle partial reductions inside VPMulAccumulateReductionRecipe (PR #136173)

2025-04-17 Thread via llvm-branch-commits

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 56dcd90446b72d182e856cfffb09c31397f01c5e 
89372f1b9283a74b52005c2ec3f3fda520c283a3 --extensions cpp,h -- 
llvm/include/llvm/Analysis/TargetTransformInfo.h 
llvm/lib/Analysis/TargetTransformInfo.cpp 
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp 
llvm/lib/Transforms/Vectorize/VPlan.h 
llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp 
llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h 
b/llvm/lib/Transforms/Vectorize/VPlan.h
index 660cea629d..8f14a37f07 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -2345,7 +2345,8 @@ public:
   FastMathFlags(), ReductionInst,
   ArrayRef({Op0, Op1}), Cond, false, {}),
 Opcode(Opcode) {
-[[maybe_unused]] auto *AccumulatorRecipe = 
getChainOp()->getDefiningRecipe();
+[[maybe_unused]] auto *AccumulatorRecipe =
+getChainOp()->getDefiningRecipe();
 assert((isa(AccumulatorRecipe) ||
 isa(AccumulatorRecipe)) &&
"Unexpected operand order for partial reduction recipe");

``




https://github.com/llvm/llvm-project/pull/136173
___
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] [lldb] [lldb] Create ThreadPlanStepOut ctor that never skips frames (PR #136163)

2025-04-17 Thread via llvm-branch-commits


@@ -17,12 +17,21 @@ namespace lldb_private {
 
 class ThreadPlanStepOut : public ThreadPlan, public ThreadPlanShouldStopHere {
 public:
+  /// Creates a thread plan to step out from frame_idx, skipping parent frames
+  /// that artificial and hidden frames. Also skips frames without debug info

jimingham wrote:

Or maybe "if they are artificial or hidden frames".

https://github.com/llvm/llvm-project/pull/136163
___
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: do not crash on debug-printing CFI instructions (PR #136151)

2025-04-17 Thread Anatoly Trosinenko via llvm-branch-commits

https://github.com/atrosinenko ready_for_review 
https://github.com/llvm/llvm-project/pull/136151
___
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] [lldb] [lldb] Create ThreadPlanStepOut ctor that never skips frames (PR #136163)

2025-04-17 Thread via llvm-branch-commits

https://github.com/jimingham approved this pull request.

This looks right to me.  There needs to be a version of step out that just does 
what it is told to do, and doesn't try to second-guess the agent that queued it.

https://github.com/llvm/llvm-project/pull/136163
___
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] [lldb] [lldb][nfc] Remove unused parameters in ThreadPlanStepOut ctor (PR #136161)

2025-04-17 Thread via llvm-branch-commits

https://github.com/jimingham commented:

Removing the symbol context is fine.  I'm not even sure it's necessary - the 
code that queues up the plan should really be the on to calculate where this 
should go to, and the plan can then just trust the frame_index it got passed.

The first_insn was there to help the unwinder in the case where you stepped 
into code with no debug information and the code you stepped to was stripped so 
we didn't have function bounds.  The "step-in" plan could know that it just 
stepped through an instruction that pushes a frame, so even without function 
bounds it's a pretty good guess this is the first instruction of a function.  
That still seems like a useful piece of information.

https://github.com/llvm/llvm-project/pull/136161
___
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] release/20.x: [clang-format] Fix mismatched break in BlockIndent (#124998) (PR #136238)

2025-04-17 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/136238

Backport b8734797a3f605c4aaa37fcb5007baa273565460

Requested by: @owenca

>From b51a65f8d0ffb7c547fcc514c3ae686adcbf5b6a Mon Sep 17 00:00:00 2001
From: Gedare Bloom 
Date: Thu, 30 Jan 2025 20:38:43 -0700
Subject: [PATCH] [clang-format] Fix mismatched break in BlockIndent (#124998)

Near the ColumnLimit a break could be inserted before a right parens
with BlockIndent without a break after the matching left parens. Avoid
these hanging right parens by disallowing breaks before right parens
unless there was a break after the left parens.

Fixes #103306

(cherry picked from commit b8734797a3f605c4aaa37fcb5007baa273565460)
---
 clang/lib/Format/ContinuationIndenter.cpp | 7 +++
 clang/unittests/Format/FormatTest.cpp | 4 
 2 files changed, 11 insertions(+)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index c311deaa17bb0..6f7d213c0b559 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -349,6 +349,13 @@ bool ContinuationIndenter::canBreak(const LineState 
&State) {
 }
   }
 
+  // Allow breaking before the right parens with block indentation if there was
+  // a break after the left parens, which is tracked by 
BreakBeforeClosingParen.
+  if (Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent &&
+  Current.is(tok::r_paren)) {
+return CurrentState.BreakBeforeClosingParen;
+  }
+
   // Don't allow breaking before a closing brace of a block-indented braced 
list
   // initializer if there isn't already a break.
   if (Current.is(tok::r_brace) && Current.MatchingParen &&
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 44341fbfe895f..bf3eff129efd5 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -9614,6 +9614,10 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) {
"auto a\n"
") {};",
Style);
+  verifyFormat("(\n"
+   "&b\n"
+   ");",
+   Style);
 }
 
 TEST_F(FormatTest, ParenthesesAndOperandAlignment) {

___
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] [SPARC] Use op-then-halve instructions when we have VIS3 (PR #135718)

2025-04-17 Thread via llvm-branch-commits

https://github.com/koachan updated 
https://github.com/llvm/llvm-project/pull/135718


___
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: improve handling of unreachable basic blocks (PR #136183)

2025-04-17 Thread Anatoly Trosinenko via llvm-branch-commits

atrosinenko 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/136183?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#136183** https://app.graphite.dev/github/pr/llvm/llvm-project/136183?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/136183?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#136151** https://app.graphite.dev/github/pr/llvm/llvm-project/136151?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#135663** https://app.graphite.dev/github/pr/llvm/llvm-project/135663?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#136147** https://app.graphite.dev/github/pr/llvm/llvm-project/136147?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#135662** https://app.graphite.dev/github/pr/llvm/llvm-project/135662?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#135661** https://app.graphite.dev/github/pr/llvm/llvm-project/135661?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134146** https://app.graphite.dev/github/pr/llvm/llvm-project/134146?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133461** https://app.graphite.dev/github/pr/llvm/llvm-project/133461?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#135073** https://app.graphite.dev/github/pr/llvm/llvm-project/135073?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/136183
___
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] [SPARC] Use native bitcast instructions when we have VIS3 (PR #135716)

2025-04-17 Thread via llvm-branch-commits

https://github.com/koachan updated 
https://github.com/llvm/llvm-project/pull/135716


___
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] [SPARC] Use op-then-neg instructions when we have VIS3 (PR #135717)

2025-04-17 Thread via llvm-branch-commits

https://github.com/koachan updated 
https://github.com/llvm/llvm-project/pull/135717


___
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] [SPARC] Use op-then-halve instructions when we have VIS3 (PR #135718)

2025-04-17 Thread via llvm-branch-commits

https://github.com/koachan updated 
https://github.com/llvm/llvm-project/pull/135718


___
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] [SPARC] Use lzcnt to implement CTLZ when we have VIS3 (PR #135715)

2025-04-17 Thread via llvm-branch-commits

https://github.com/koachan updated 
https://github.com/llvm/llvm-project/pull/135715

>From 6e865810ea2acaf636a4759fd4ffc67aa3dbb848 Mon Sep 17 00:00:00 2001
From: Koakuma 
Date: Thu, 17 Apr 2025 08:24:54 +0700
Subject: [PATCH 1/3] Promote i32 CTLZ when we don't have VIS3 or POPC

Created using spr 1.3.5
---
 llvm/lib/Target/Sparc/SparcISelLowering.cpp |  11 +-
 llvm/test/CodeGen/SPARC/ctlz.ll | 182 +++-
 2 files changed, 35 insertions(+), 158 deletions(-)

diff --git a/llvm/lib/Target/Sparc/SparcISelLowering.cpp 
b/llvm/lib/Target/Sparc/SparcISelLowering.cpp
index fa544916aebb5..e455706b0528f 100644
--- a/llvm/lib/Target/Sparc/SparcISelLowering.cpp
+++ b/llvm/lib/Target/Sparc/SparcISelLowering.cpp
@@ -1755,7 +1755,7 @@ SparcTargetLowering::SparcTargetLowering(const 
TargetMachine &TM,
Subtarget->usePopc() ? Legal : Expand);
 setOperationAction(ISD::CTTZ , MVT::i64, Expand);
 setOperationAction(ISD::CTLZ, MVT::i64,
-   Subtarget->isVIS3() ? Legal : LibCall);
+   Subtarget->isVIS3() ? Legal : Expand);
 setOperationAction(ISD::BSWAP, MVT::i64, Expand);
 setOperationAction(ISD::ROTL , MVT::i64, Expand);
 setOperationAction(ISD::ROTR , MVT::i64, Expand);
@@ -1818,7 +1818,7 @@ SparcTargetLowering::SparcTargetLowering(const 
TargetMachine &TM,
   setOperationAction(ISD::FMA  , MVT::f32, Expand);
   setOperationAction(ISD::CTTZ , MVT::i32, Expand);
   setOperationAction(ISD::CTLZ, MVT::i32,
- Subtarget->isVIS3() ? Promote : LibCall);
+ Subtarget->isVIS3() ? Promote : Expand);
   setOperationAction(ISD::ROTL , MVT::i32, Expand);
   setOperationAction(ISD::ROTR , MVT::i32, Expand);
   setOperationAction(ISD::BSWAP, MVT::i32, Expand);
@@ -1992,6 +1992,13 @@ SparcTargetLowering::SparcTargetLowering(const 
TargetMachine &TM,
   if (Subtarget->isVIS3()) {
 setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i32, Promote);
 setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i64, Legal);
+  } else if (Subtarget->usePopc()) {
+setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i32, Expand);
+setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i64, Expand);
+  } else {
+setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i32,
+   Subtarget->is64Bit() ? Promote : LibCall);
+setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i64, LibCall);
   }
 
   setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom);
diff --git a/llvm/test/CodeGen/SPARC/ctlz.ll b/llvm/test/CodeGen/SPARC/ctlz.ll
index d17b776ca0a72..3391af02e4bc0 100644
--- a/llvm/test/CodeGen/SPARC/ctlz.ll
+++ b/llvm/test/CodeGen/SPARC/ctlz.ll
@@ -6,46 +6,18 @@
 define i32 @i32_nopoison(i32 %x) nounwind {
 ; V9-LABEL: i32_nopoison:
 ; V9:   ! %bb.0:
-; V9-NEXT:cmp %o0, 0
+; V9-NEXT:save %sp, -176, %sp
+; V9-NEXT:cmp %i0, 0
 ; V9-NEXT:be %icc, .LBB0_2
 ; V9-NEXT:nop
 ; V9-NEXT:  ! %bb.1: ! %cond.false
-; V9-NEXT:srl %o0, 1, %o1
-; V9-NEXT:or %o0, %o1, %o0
-; V9-NEXT:srl %o0, 2, %o1
-; V9-NEXT:or %o0, %o1, %o0
-; V9-NEXT:srl %o0, 4, %o1
-; V9-NEXT:or %o0, %o1, %o0
-; V9-NEXT:srl %o0, 8, %o1
-; V9-NEXT:or %o0, %o1, %o0
-; V9-NEXT:srl %o0, 16, %o1
-; V9-NEXT:or %o0, %o1, %o0
-; V9-NEXT:xor %o0, -1, %o0
-; V9-NEXT:srl %o0, 1, %o1
-; V9-NEXT:sethi 1398101, %o2
-; V9-NEXT:or %o2, 341, %o2
-; V9-NEXT:and %o1, %o2, %o1
-; V9-NEXT:sub %o0, %o1, %o0
-; V9-NEXT:sethi 838860, %o1
-; V9-NEXT:or %o1, 819, %o1
-; V9-NEXT:and %o0, %o1, %o2
-; V9-NEXT:srl %o0, 2, %o0
-; V9-NEXT:and %o0, %o1, %o0
-; V9-NEXT:add %o2, %o0, %o0
-; V9-NEXT:srl %o0, 4, %o1
-; V9-NEXT:add %o0, %o1, %o0
-; V9-NEXT:sethi 246723, %o1
-; V9-NEXT:or %o1, 783, %o1
-; V9-NEXT:and %o0, %o1, %o0
-; V9-NEXT:sll %o0, 8, %o1
-; V9-NEXT:add %o0, %o1, %o0
-; V9-NEXT:sll %o0, 16, %o1
-; V9-NEXT:add %o0, %o1, %o0
-; V9-NEXT:retl
-; V9-NEXT:srl %o0, 24, %o0
+; V9-NEXT:call __clzdi2
+; V9-NEXT:sllx %i0, 32, %o0
+; V9-NEXT:ret
+; V9-NEXT:restore %g0, %o0, %o0
 ; V9-NEXT:  .LBB0_2:
-; V9-NEXT:retl
-; V9-NEXT:mov 32, %o0
+; V9-NEXT:ret
+; V9-NEXT:restore %g0, 32, %o0
 ;
 ; POPC-LABEL: i32_nopoison:
 ; POPC:   ! %bb.0:
@@ -90,39 +62,11 @@ define i32 @i32_nopoison(i32 %x) nounwind {
 define i32 @i32_poison(i32 %x) nounwind {
 ; V9-LABEL: i32_poison:
 ; V9:   ! %bb.0:
-; V9-NEXT:srl %o0, 1, %o1
-; V9-NEXT:or %o0, %o1, %o0
-; V9-NEXT:srl %o0, 2, %o1
-; V9-NEXT:or %o0, %o1, %o0
-; V9-NEXT:srl %o0, 4, %o1
-; V9-NEXT:or %o0, %o1, %o0
-; V9-NEXT:srl %o0, 8, %o1
-; V9-NEXT:or %o0, %o1, %o0
-; V9-NEXT:srl %o0, 16, %o1
-; V9-NEXT:or %o0, %o1, %o0
-; V9-NEXT:xor %o0, -1, %o0
-; V9-NEXT:srl %o0, 1, %o1
-; V9-NEXT:sethi 1398101, %o2
-; V9-NEXT:or %o2, 341, %o2
-; V9-NEXT:and %o1, %o2, %o1
-; V9-NEXT:sub %o0, %o1, %o0
-; V

[llvm-branch-commits] [llvm] [BOLT] Gadget scanner: clarify MCPlusBuilder callbacks interface (PR #136147)

2025-04-17 Thread Anatoly Trosinenko via llvm-branch-commits

https://github.com/atrosinenko created 
https://github.com/llvm/llvm-project/pull/136147

Clarify the semantics of `getAuthenticatedReg` and remove a redundant 
`isAuthenticationOfReg` method, as combined auth+something instructions (such 
as `retaa` on AArch64) should be handled carefully, especially when searching 
for authentication oracles: usually, such instructions cannot be authentication 
oracles and only some of them actually write an authenticated pointer to a 
register (such as "ldra x0, [x1]!").

Use `std::optional` returned type instead of plain MCPhysReg and 
returning `getNoRegister()` as a "not applicable" indication.

Document a few existing methods, add information about preconditions.

>From ff86e1d8b25b443c7b3bb2d26a45d9a280b31d97 Mon Sep 17 00:00:00 2001
From: Anatoly Trosinenko 
Date: Thu, 17 Apr 2025 15:40:05 +0300
Subject: [PATCH] [BOLT] Gadget scanner: clarify MCPlusBuilder callbacks
 interface

Clarify the semantics of `getAuthenticatedReg` and remove a redundant
`isAuthenticationOfReg` method, as combined auth+something instructions
(such as `retaa` on AArch64) should be handled carefully, especially
when searching for authentication oracles: usually, such instructions
cannot be authentication oracles and only some of them actually write
an authenticated pointer to a register (such as "ldra x0, [x1]!").

Use `std::optional` returned type instead of plain MCPhysReg
and returning `getNoRegister()` as a "not applicable" indication.

Document a few existing methods, add information about preconditions.
---
 bolt/include/bolt/Core/MCPlusBuilder.h| 61 ++-
 bolt/lib/Passes/PAuthGadgetScanner.cpp| 64 +---
 .../Target/AArch64/AArch64MCPlusBuilder.cpp   | 76 ---
 .../AArch64/gs-pauth-debug-output.s   |  3 -
 .../AArch64/gs-pauth-signing-oracles.s| 20 +
 5 files changed, 130 insertions(+), 94 deletions(-)

diff --git a/bolt/include/bolt/Core/MCPlusBuilder.h 
b/bolt/include/bolt/Core/MCPlusBuilder.h
index 9d50036b8083b..209d6e88b7fe9 100644
--- a/bolt/include/bolt/Core/MCPlusBuilder.h
+++ b/bolt/include/bolt/Core/MCPlusBuilder.h
@@ -562,30 +562,50 @@ class MCPlusBuilder {
 return {};
   }
 
-  virtual ErrorOr getAuthenticatedReg(const MCInst &Inst) const {
-llvm_unreachable("not implemented");
-return getNoRegister();
-  }
-
-  virtual bool isAuthenticationOfReg(const MCInst &Inst,
- MCPhysReg AuthenticatedReg) const {
+  /// Returns the register where an authenticated pointer is written to by 
Inst,
+  /// or std::nullopt if not authenticating any register.
+  ///
+  /// Sets IsChecked if the instruction always checks authenticated pointer,
+  /// i.e. it either returns a successfully authenticated pointer or terminates
+  /// the program abnormally (such as "ldra x0, [x1]!" on AArch64, which 
crashes
+  /// on authentication failure even if FEAT_FPAC is not implemented).
+  virtual std::optional
+  getWrittenAuthenticatedReg(const MCInst &Inst, bool &IsChecked) const {
 llvm_unreachable("not implemented");
-return false;
+return std::nullopt;
   }
 
-  virtual MCPhysReg getSignedReg(const MCInst &Inst) const {
+  /// Returns the register signed by Inst, or std::nullopt if not signing any
+  /// register.
+  ///
+  /// The returned register is assumed to be both input and output operand,
+  /// as it is done on AArch64.
+  virtual std::optional getSignedReg(const MCInst &Inst) const {
 llvm_unreachable("not implemented");
-return getNoRegister();
+return std::nullopt;
   }
 
-  virtual ErrorOr getRegUsedAsRetDest(const MCInst &Inst) const {
+  /// Returns the register used as a return address. Returns std::nullopt if
+  /// not applicable, such as reading the return address from a system register
+  /// or from the stack.
+  ///
+  /// Sets IsAuthenticatedInternally if the instruction accepts a signed
+  /// pointer as its operand and authenticates it internally.
+  ///
+  /// Should only be called when isReturn(Inst) is true.
+  virtual std::optional
+  getRegUsedAsRetDest(const MCInst &Inst,
+  bool &IsAuthenticatedInternally) const {
 llvm_unreachable("not implemented");
-return getNoRegister();
+return std::nullopt;
   }
 
   /// Returns the register used as the destination of an indirect branch or 
call
   /// instruction. Sets IsAuthenticatedInternally if the instruction accepts
   /// a signed pointer as its operand and authenticates it internally.
+  ///
+  /// Should only be called if isIndirectCall(Inst) or isIndirectBranch(Inst)
+  /// returns true.
   virtual MCPhysReg
   getRegUsedAsIndirectBranchDest(const MCInst &Inst,
  bool &IsAuthenticatedInternally) const {
@@ -602,14 +622,14 @@ class MCPlusBuilder {
   ///controlled, under the Pointer Authentication threat model.
   ///
   /// If the instruction does not write to any register satisfying the above
-  /// two 

[llvm-branch-commits] [llvm] [BOLT] Gadget scanner: detect authentication oracles (PR #135663)

2025-04-17 Thread Anatoly Trosinenko via llvm-branch-commits

https://github.com/atrosinenko edited 
https://github.com/llvm/llvm-project/pull/135663
___
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: clarify MCPlusBuilder callbacks interface (PR #136147)

2025-04-17 Thread Anatoly Trosinenko via llvm-branch-commits

atrosinenko 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/136147?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#135663** https://app.graphite.dev/github/pr/llvm/llvm-project/135663?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#136147** https://app.graphite.dev/github/pr/llvm/llvm-project/136147?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/136147?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#135662** https://app.graphite.dev/github/pr/llvm/llvm-project/135662?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#135661** https://app.graphite.dev/github/pr/llvm/llvm-project/135661?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134146** https://app.graphite.dev/github/pr/llvm/llvm-project/134146?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133461** https://app.graphite.dev/github/pr/llvm/llvm-project/133461?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#135073** https://app.graphite.dev/github/pr/llvm/llvm-project/135073?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/136147
___
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 authentication oracles (PR #135663)

2025-04-17 Thread Anatoly Trosinenko via llvm-branch-commits

atrosinenko wrote:

After testing current mainline version of gadget scanner (with this stack of 
PRs applied) against llvm-test-suite, I spotted false positives for combined 
instructions like `retaa`: they were reported as authentication oracles, 
because `getAuthenticatedReg` returns LR for them, which is not checked 
afterward. As this is quite important issue to resolve before this PR is 
merged, I inserted #136147 before this PR and updated this one accordingly.

https://github.com/llvm/llvm-project/pull/135663
___
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] [SPARC] Promote i32 CTTZ when we have VIS3 (PR #135894)

2025-04-17 Thread via llvm-branch-commits


@@ -3599,6 +3615,15 @@ bool SparcTargetLowering::isFPImmLegal(const APFloat 
&Imm, EVT VT,
 
 bool SparcTargetLowering::isCtlzFast() const { return Subtarget->isVIS3(); }
 
+bool SparcTargetLowering::isCheapToSpeculateCttz(Type *Ty) const {
+  // We lack native cttz, however,
+  // On 64-bit targets it is cheap to implement it in terms of popc.
+  if (Subtarget->is64Bit() && Subtarget->usePopc())
+return true;
+  // Otherwise, implementing cttz in terms of ctlz is still cheap.
+  return isCheapToSpeculateCtlz(Ty);

koachan wrote:

Yes, as far as relative costs go ctpop is cheaper than ctlz, but I see no way 
to indicate such ordering so I'm tagging both as cheap~

https://github.com/llvm/llvm-project/pull/135894
___
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: do not crash on debug-printing CFI instructions (PR #136151)

2025-04-17 Thread Anatoly Trosinenko via llvm-branch-commits

https://github.com/atrosinenko created 
https://github.com/llvm/llvm-project/pull/136151

Some instruction-printing code used under LLVM_DEBUG does not handle CFI
instructions well. While CFI instructions seem to be harmless for the
correctness of the analysis results, they do not convey any useful
information to the analysis either, so skip them early.

>From 08a7baa4a63368f93991753bb47e037ca32702d6 Mon Sep 17 00:00:00 2001
From: Anatoly Trosinenko 
Date: Tue, 15 Apr 2025 21:47:18 +0300
Subject: [PATCH] [BOLT] Gadget scanner: do not crash on debug-printing CFI
 instructions

Some instruction-printing code used under LLVM_DEBUG does not handle CFI
instructions well. While CFI instructions seem to be harmless for the
correctness of the analysis results, they do not convey any useful
information to the analysis either, so skip them early.
---
 bolt/lib/Passes/PAuthGadgetScanner.cpp| 16 ++
 .../AArch64/gs-pauth-debug-output.s   | 32 +++
 2 files changed, 48 insertions(+)

diff --git a/bolt/lib/Passes/PAuthGadgetScanner.cpp 
b/bolt/lib/Passes/PAuthGadgetScanner.cpp
index f12354390c3f3..2d2126bf05ae1 100644
--- a/bolt/lib/Passes/PAuthGadgetScanner.cpp
+++ b/bolt/lib/Passes/PAuthGadgetScanner.cpp
@@ -433,6 +433,9 @@ class SrcSafetyAnalysis {
   }
 
   SrcState computeNext(const MCInst &Point, const SrcState &Cur) {
+if (BC.MIB->isCFI(Point))
+  return Cur;
+
 SrcStatePrinter P(BC);
 LLVM_DEBUG({
   dbgs() << "  SrcSafetyAnalysis::ComputeNext(";
@@ -674,6 +677,8 @@ class CFGUnawareSrcSafetyAnalysis : public 
SrcSafetyAnalysis {
 SrcState S = createEntryState();
 for (auto &I : BF.instrs()) {
   MCInst &Inst = I.second;
+  if (BC.MIB->isCFI(Inst))
+continue;
 
   // If there is a label before this instruction, it is possible that it
   // can be jumped-to, thus conservatively resetting S. As an exception,
@@ -952,6 +957,9 @@ class DstSafetyAnalysis {
   }
 
   DstState computeNext(const MCInst &Point, const DstState &Cur) {
+if (BC.MIB->isCFI(Point))
+  return Cur;
+
 DstStatePrinter P(BC);
 LLVM_DEBUG({
   dbgs() << "  DstSafetyAnalysis::ComputeNext(";
@@ -1130,6 +1138,8 @@ class CFGUnawareDstSafetyAnalysis : public 
DstSafetyAnalysis {
 DstState S = createUnsafeState();
 for (auto &I : llvm::reverse(BF.instrs())) {
   MCInst &Inst = I.second;
+  if (BC.MIB->isCFI(Inst))
+continue;
 
   // If Inst can change the control flow, we cannot be sure that the next
   // instruction (to be executed in analyzed program) is the one processed
@@ -1326,6 +1336,9 @@ void FunctionAnalysis::findUnsafeUses(
   });
 
   iterateOverInstrs(BF, [&](MCInstReference Inst) {
+if (BC.MIB->isCFI(Inst))
+  return;
+
 const SrcState &S = Analysis->getStateBefore(Inst);
 
 // If non-empty state was never propagated from the entry basic block
@@ -1387,6 +1400,9 @@ void FunctionAnalysis::findUnsafeDefs(
   });
 
   iterateOverInstrs(BF, [&](MCInstReference Inst) {
+if (BC.MIB->isCFI(Inst))
+  return;
+
 const DstState &S = Analysis->getStateAfter(Inst);
 
 if (auto Report = shouldReportAuthOracle(BC, Inst, S))
diff --git a/bolt/test/binary-analysis/AArch64/gs-pauth-debug-output.s 
b/bolt/test/binary-analysis/AArch64/gs-pauth-debug-output.s
index fd55880921d06..07b61bea77e94 100644
--- a/bolt/test/binary-analysis/AArch64/gs-pauth-debug-output.s
+++ b/bolt/test/binary-analysis/AArch64/gs-pauth-debug-output.s
@@ -329,6 +329,38 @@ auth_oracle:
 // PAUTH-EMPTY:
 // PAUTH-NEXT:   Attaching leakage info to: :  autia   x0, x1 
# DataflowDstSafetyAnalysis: dst-state
 
+// Gadget scanner should not crash on CFI instructions, including when 
debug-printing them.
+// Note that the particular debug output is not checked, but BOLT should be
+// compiled with assertions enabled to support -debug-only argument.
+
+.globl  cfi_inst_df
+.type   cfi_inst_df,@function
+cfi_inst_df:
+.cfi_startproc
+sub sp, sp, #16
+.cfi_def_cfa_offset 16
+add sp, sp, #16
+.cfi_def_cfa_offset 0
+ret
+.size   cfi_inst_df, .-cfi_inst_df
+.cfi_endproc
+
+.globl  cfi_inst_nocfg
+.type   cfi_inst_nocfg,@function
+cfi_inst_nocfg:
+.cfi_startproc
+sub sp, sp, #16
+.cfi_def_cfa_offset 16
+
+adr x0, 1f
+br  x0
+1:
+add sp, sp, #16
+.cfi_def_cfa_offset 0
+ret
+.size   cfi_inst_nocfg, .-cfi_inst_nocfg
+.cfi_endproc
+
 // CHECK-LABEL:Analyzing function main, AllocatorId = 1
 .globl  main
 .type   main,@function

___
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] [lldb] [lldb][nfc] Remove unused parameters in ThreadPlanStepOut ctor (PR #136161)

2025-04-17 Thread Felipe de Azevedo Piovezan via llvm-branch-commits

https://github.com/felipepiovezan created 
https://github.com/llvm/llvm-project/pull/136161

These have been unused for at least a decade.

>From e668877c091baf943e5030e2f49f4e68015fc477 Mon Sep 17 00:00:00 2001
From: Felipe de Azevedo Piovezan 
Date: Thu, 17 Apr 2025 08:18:13 -0700
Subject: [PATCH] [lldb][nfc] Remove unused parameters in ThreadPlanStepOut
 ctor

These have been unused for at least a decade.
---
 lldb/include/lldb/API/SBThreadPlan.h  |  1 +
 lldb/include/lldb/Target/Thread.h | 35 +++
 lldb/include/lldb/Target/ThreadPlanStepOut.h  |  8 ++---
 lldb/source/API/SBThread.cpp  |  8 ++---
 lldb/source/API/SBThreadPlan.cpp  |  4 +--
 lldb/source/Commands/CommandObjectThread.cpp  |  3 +-
 ...pleThreadPlanStepThroughObjCTrampoline.cpp |  8 ++---
 lldb/source/Target/Thread.cpp | 27 +++---
 .../Target/ThreadPlanCallOnFunctionExit.cpp   |  2 --
 .../Target/ThreadPlanShouldStopHere.cpp   |  4 +--
 .../Target/ThreadPlanStepInstruction.cpp  |  3 +-
 lldb/source/Target/ThreadPlanStepOut.cpp  |  7 ++--
 .../source/Target/ThreadPlanStepOverRange.cpp |  3 +-
 13 files changed, 38 insertions(+), 75 deletions(-)

diff --git a/lldb/include/lldb/API/SBThreadPlan.h 
b/lldb/include/lldb/API/SBThreadPlan.h
index d02ab80f76a76..9b7ac03d8265c 100644
--- a/lldb/include/lldb/API/SBThreadPlan.h
+++ b/lldb/include/lldb/API/SBThreadPlan.h
@@ -100,6 +100,7 @@ class LLDB_API SBThreadPlan {
  lldb::addr_t range_size,
  SBError &error);
 
+  // Note: first_insn is not used.
   SBThreadPlan QueueThreadPlanForStepOut(uint32_t frame_idx_to_step_to,
  bool first_insn = false);
   SBThreadPlan QueueThreadPlanForStepOut(uint32_t frame_idx_to_step_to,
diff --git a/lldb/include/lldb/Target/Thread.h 
b/lldb/include/lldb/Target/Thread.h
index 6ede7fa301a82..1454f2ff4d18a 100644
--- a/lldb/include/lldb/Target/Thread.h
+++ b/lldb/include/lldb/Target/Thread.h
@@ -843,18 +843,6 @@ class Thread : public std::enable_shared_from_this,
   ///this one.
   ///Otherwise this plan will go on the end of the plan stack.
   ///
-  /// \param[in] addr_context
-  ///When dealing with stepping through inlined functions the current PC is
-  ///not enough information to know
-  ///what "step" means.  For instance a series of nested inline functions
-  ///might start at the same address.
-  // The \a addr_context provides the current symbol context the step
-  ///is supposed to be out of.
-  //   FIXME: Currently unused.
-  ///
-  /// \param[in] first_insn
-  /// \b true if this is the first instruction of a function.
-  ///
   /// \param[in] stop_other_threads
   ///\b true if we will stop other threads while we single step this one.
   ///
@@ -876,9 +864,8 @@ class Thread : public std::enable_shared_from_this,
   /// A shared pointer to the newly queued thread plan, or nullptr if the
   /// plan could not be queued.
   virtual lldb::ThreadPlanSP QueueThreadPlanForStepOut(
-  bool abort_other_plans, SymbolContext *addr_context, bool first_insn,
-  bool stop_other_threads, Vote report_stop_vote, Vote report_run_vote,
-  uint32_t frame_idx, Status &status,
+  bool abort_other_plans, bool stop_other_threads, Vote report_stop_vote,
+  Vote report_run_vote, uint32_t frame_idx, Status &status,
   LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate);
 
   /// Queue the plan used to step out of the function at the current PC of
@@ -892,18 +879,6 @@ class Thread : public std::enable_shared_from_this,
   ///this one.
   ///Otherwise this plan will go on the end of the plan stack.
   ///
-  /// \param[in] addr_context
-  ///When dealing with stepping through inlined functions the current PC is
-  ///not enough information to know
-  ///what "step" means.  For instance a series of nested inline functions
-  ///might start at the same address.
-  // The \a addr_context provides the current symbol context the step
-  ///is supposed to be out of.
-  //   FIXME: Currently unused.
-  ///
-  /// \param[in] first_insn
-  /// \b true if this is the first instruction of a function.
-  ///
   /// \param[in] stop_other_threads
   ///\b true if we will stop other threads while we single step this one.
   ///
@@ -940,9 +915,9 @@ class Thread : public std::enable_shared_from_this,
   /// A shared pointer to the newly queued thread plan, or nullptr if the
   /// plan could not be queued.
   virtual lldb::ThreadPlanSP QueueThreadPlanForStepOutNoShouldStop(
-  bool abort_other_plans, SymbolContext *addr_context, bool first_insn,
-  bool stop_other_threads, Vote report_stop_vote, Vote report_run_vote,
-  uint32_t frame_idx, Status &status, bool continue_to_next_branch = 
false);
+  bool abort_other_plans, bool

[llvm-branch-commits] [lldb] [lldb][nfc] Split the constructor of ThreadPlanStepOut (PR #136160)

2025-04-17 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Felipe de Azevedo Piovezan (felipepiovezan)


Changes

A subsequent commit will create a new constructor for ThreadPlanStepOut, which 
needs to reuse much of the same logic of the existing constructor. This commit 
places all of that reusable logic into a separate function.

---
Full diff: https://github.com/llvm/llvm-project/pull/136160.diff


2 Files Affected:

- (modified) lldb/include/lldb/Target/ThreadPlanStepOut.h (+4) 
- (modified) lldb/source/Target/ThreadPlanStepOut.cpp (+8-1) 


``diff
diff --git a/lldb/include/lldb/Target/ThreadPlanStepOut.h 
b/lldb/include/lldb/Target/ThreadPlanStepOut.h
index 013c675afc33d..e414a6e0a2d49 100644
--- a/lldb/include/lldb/Target/ThreadPlanStepOut.h
+++ b/lldb/include/lldb/Target/ThreadPlanStepOut.h
@@ -82,6 +82,10 @@ class ThreadPlanStepOut : public ThreadPlan, public 
ThreadPlanShouldStopHere {
   LazyBool step_out_avoids_code_without_debug_info);
 
   void SetupAvoidNoDebug(LazyBool step_out_avoids_code_without_debug_info);
+
+  void SetupReturnAddress(lldb::StackFrameSP return_frame_sp,
+  lldb::StackFrameSP immediate_return_from_sp,
+  uint32_t frame_idx, bool continue_to_next_branch);
   // Need an appropriate marker for the current stack so we can tell step out
   // from step in.
 
diff --git a/lldb/source/Target/ThreadPlanStepOut.cpp 
b/lldb/source/Target/ThreadPlanStepOut.cpp
index 26c1abe710319..b3c9a790487d4 100644
--- a/lldb/source/Target/ThreadPlanStepOut.cpp
+++ b/lldb/source/Target/ThreadPlanStepOut.cpp
@@ -79,6 +79,13 @@ ThreadPlanStepOut::ThreadPlanStepOut(
   ComputeTargetFrame(thread, frame_idx, m_stepped_past_frames);
   StackFrameSP 
immediate_return_from_sp(thread.GetStackFrameAtIndex(frame_idx));
 
+  SetupReturnAddress(return_frame_sp, immediate_return_from_sp,
+ frame_idx, continue_to_next_branch);
+}
+
+void ThreadPlanStepOut::SetupReturnAddress(
+StackFrameSP return_frame_sp, StackFrameSP immediate_return_from_sp,
+uint32_t frame_idx, bool continue_to_next_branch) {
   if (!return_frame_sp || !immediate_return_from_sp)
 return; // we can't do anything here.  ValidatePlan() will return false.
 
@@ -94,7 +101,7 @@ ThreadPlanStepOut::ThreadPlanStepOut(
   // First queue a plan that gets us to this inlined frame, and when we get
   // there we'll queue a second plan that walks us out of this frame.
   m_step_out_to_inline_plan_sp = std::make_shared(
-  thread, nullptr, false, stop_others, eVoteNoOpinion, eVoteNoOpinion,
+  GetThread(), nullptr, false, m_stop_others, eVoteNoOpinion, 
eVoteNoOpinion,
   frame_idx - 1, eLazyBoolNo, continue_to_next_branch);
   static_cast(m_step_out_to_inline_plan_sp.get())
   ->SetShouldStopHereCallbacks(nullptr, nullptr);

``




https://github.com/llvm/llvm-project/pull/136160
___
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] [lldb] [lldb][nfc] Split the constructor of ThreadPlanStepOut (PR #136160)

2025-04-17 Thread Felipe de Azevedo Piovezan via llvm-branch-commits

https://github.com/felipepiovezan created 
https://github.com/llvm/llvm-project/pull/136160

A subsequent commit will create a new constructor for ThreadPlanStepOut, which 
needs to reuse much of the same logic of the existing constructor. This commit 
places all of that reusable logic into a separate function.

>From 662baea555175e39ca4f0f170f2ef197c53af60d Mon Sep 17 00:00:00 2001
From: Felipe de Azevedo Piovezan 
Date: Thu, 17 Apr 2025 07:52:19 -0700
Subject: [PATCH] [lldb][nfc] Split the constructor of ThreadPlanStepOut

A subsequent commit will create a new constructor for ThreadPlanStepOut,
which needs to reuse much of the same logic of the existing constructor.
This commit places all of that reusable logic into a separate function.
---
 lldb/include/lldb/Target/ThreadPlanStepOut.h | 4 
 lldb/source/Target/ThreadPlanStepOut.cpp | 9 -
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/lldb/include/lldb/Target/ThreadPlanStepOut.h 
b/lldb/include/lldb/Target/ThreadPlanStepOut.h
index 013c675afc33d..e414a6e0a2d49 100644
--- a/lldb/include/lldb/Target/ThreadPlanStepOut.h
+++ b/lldb/include/lldb/Target/ThreadPlanStepOut.h
@@ -82,6 +82,10 @@ class ThreadPlanStepOut : public ThreadPlan, public 
ThreadPlanShouldStopHere {
   LazyBool step_out_avoids_code_without_debug_info);
 
   void SetupAvoidNoDebug(LazyBool step_out_avoids_code_without_debug_info);
+
+  void SetupReturnAddress(lldb::StackFrameSP return_frame_sp,
+  lldb::StackFrameSP immediate_return_from_sp,
+  uint32_t frame_idx, bool continue_to_next_branch);
   // Need an appropriate marker for the current stack so we can tell step out
   // from step in.
 
diff --git a/lldb/source/Target/ThreadPlanStepOut.cpp 
b/lldb/source/Target/ThreadPlanStepOut.cpp
index 26c1abe710319..b3c9a790487d4 100644
--- a/lldb/source/Target/ThreadPlanStepOut.cpp
+++ b/lldb/source/Target/ThreadPlanStepOut.cpp
@@ -79,6 +79,13 @@ ThreadPlanStepOut::ThreadPlanStepOut(
   ComputeTargetFrame(thread, frame_idx, m_stepped_past_frames);
   StackFrameSP 
immediate_return_from_sp(thread.GetStackFrameAtIndex(frame_idx));
 
+  SetupReturnAddress(return_frame_sp, immediate_return_from_sp,
+ frame_idx, continue_to_next_branch);
+}
+
+void ThreadPlanStepOut::SetupReturnAddress(
+StackFrameSP return_frame_sp, StackFrameSP immediate_return_from_sp,
+uint32_t frame_idx, bool continue_to_next_branch) {
   if (!return_frame_sp || !immediate_return_from_sp)
 return; // we can't do anything here.  ValidatePlan() will return false.
 
@@ -94,7 +101,7 @@ ThreadPlanStepOut::ThreadPlanStepOut(
   // First queue a plan that gets us to this inlined frame, and when we get
   // there we'll queue a second plan that walks us out of this frame.
   m_step_out_to_inline_plan_sp = std::make_shared(
-  thread, nullptr, false, stop_others, eVoteNoOpinion, eVoteNoOpinion,
+  GetThread(), nullptr, false, m_stop_others, eVoteNoOpinion, 
eVoteNoOpinion,
   frame_idx - 1, eLazyBoolNo, continue_to_next_branch);
   static_cast(m_step_out_to_inline_plan_sp.get())
   ->SetShouldStopHereCallbacks(nullptr, nullptr);

___
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] [lldb] [lldb][nfc] Split the constructor of ThreadPlanStepOut (PR #136160)

2025-04-17 Thread via llvm-branch-commits

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 -- 
lldb/include/lldb/Target/ThreadPlanStepOut.h 
lldb/source/Target/ThreadPlanStepOut.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lldb/source/Target/ThreadPlanStepOut.cpp 
b/lldb/source/Target/ThreadPlanStepOut.cpp
index b3c9a7904..f26064030 100644
--- a/lldb/source/Target/ThreadPlanStepOut.cpp
+++ b/lldb/source/Target/ThreadPlanStepOut.cpp
@@ -79,8 +79,8 @@ ThreadPlanStepOut::ThreadPlanStepOut(
   ComputeTargetFrame(thread, frame_idx, m_stepped_past_frames);
   StackFrameSP 
immediate_return_from_sp(thread.GetStackFrameAtIndex(frame_idx));
 
-  SetupReturnAddress(return_frame_sp, immediate_return_from_sp,
- frame_idx, continue_to_next_branch);
+  SetupReturnAddress(return_frame_sp, immediate_return_from_sp, frame_idx,
+ continue_to_next_branch);
 }
 
 void ThreadPlanStepOut::SetupReturnAddress(
@@ -101,8 +101,8 @@ void ThreadPlanStepOut::SetupReturnAddress(
   // First queue a plan that gets us to this inlined frame, and when we get
   // there we'll queue a second plan that walks us out of this frame.
   m_step_out_to_inline_plan_sp = std::make_shared(
-  GetThread(), nullptr, false, m_stop_others, eVoteNoOpinion, 
eVoteNoOpinion,
-  frame_idx - 1, eLazyBoolNo, continue_to_next_branch);
+  GetThread(), nullptr, false, m_stop_others, eVoteNoOpinion,
+  eVoteNoOpinion, frame_idx - 1, eLazyBoolNo, continue_to_next_branch);
   static_cast(m_step_out_to_inline_plan_sp.get())
   ->SetShouldStopHereCallbacks(nullptr, nullptr);
   m_step_out_to_inline_plan_sp->SetPrivate(true);

``




https://github.com/llvm/llvm-project/pull/136160
___
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] [lldb] [lldb] Create ThreadPlanStepOut ctor that never skips frames (PR #136163)

2025-04-17 Thread Felipe de Azevedo Piovezan via llvm-branch-commits


@@ -17,12 +17,21 @@ namespace lldb_private {
 
 class ThreadPlanStepOut : public ThreadPlan, public ThreadPlanShouldStopHere {
 public:
+  /// Creates a thread plan to step out from frame_idx, skipping parent frames
+  /// that artificial and hidden frames. Also skips frames without debug info

felipepiovezan wrote:

typo: that ARE*

https://github.com/llvm/llvm-project/pull/136163
___
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] [MTE] do not tag zero sized globals (PR #136020)

2025-04-17 Thread Florian Mayer via llvm-branch-commits

https://github.com/fmayer updated 
https://github.com/llvm/llvm-project/pull/136020


___
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] [lldb] [lldb][nfc] Remove unused parameters in ThreadPlanStepOut ctor (PR #136161)

2025-04-17 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Felipe de Azevedo Piovezan (felipepiovezan)


Changes

These have been unused for at least a decade.

---
Full diff: https://github.com/llvm/llvm-project/pull/136161.diff


13 Files Affected:

- (modified) lldb/include/lldb/API/SBThreadPlan.h (+1) 
- (modified) lldb/include/lldb/Target/Thread.h (+5-30) 
- (modified) lldb/include/lldb/Target/ThreadPlanStepOut.h (+3-5) 
- (modified) lldb/source/API/SBThread.cpp (+4-4) 
- (modified) lldb/source/API/SBThreadPlan.cpp (+2-2) 
- (modified) lldb/source/Commands/CommandObjectThread.cpp (+1-2) 
- (modified) 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp
 (+3-5) 
- (modified) lldb/source/Target/Thread.cpp (+12-15) 
- (modified) lldb/source/Target/ThreadPlanCallOnFunctionExit.cpp (-2) 
- (modified) lldb/source/Target/ThreadPlanShouldStopHere.cpp (+2-2) 
- (modified) lldb/source/Target/ThreadPlanStepInstruction.cpp (+1-2) 
- (modified) lldb/source/Target/ThreadPlanStepOut.cpp (+3-4) 
- (modified) lldb/source/Target/ThreadPlanStepOverRange.cpp (+1-2) 


``diff
diff --git a/lldb/include/lldb/API/SBThreadPlan.h 
b/lldb/include/lldb/API/SBThreadPlan.h
index d02ab80f76a76..9b7ac03d8265c 100644
--- a/lldb/include/lldb/API/SBThreadPlan.h
+++ b/lldb/include/lldb/API/SBThreadPlan.h
@@ -100,6 +100,7 @@ class LLDB_API SBThreadPlan {
  lldb::addr_t range_size,
  SBError &error);
 
+  // Note: first_insn is not used.
   SBThreadPlan QueueThreadPlanForStepOut(uint32_t frame_idx_to_step_to,
  bool first_insn = false);
   SBThreadPlan QueueThreadPlanForStepOut(uint32_t frame_idx_to_step_to,
diff --git a/lldb/include/lldb/Target/Thread.h 
b/lldb/include/lldb/Target/Thread.h
index 6ede7fa301a82..1454f2ff4d18a 100644
--- a/lldb/include/lldb/Target/Thread.h
+++ b/lldb/include/lldb/Target/Thread.h
@@ -843,18 +843,6 @@ class Thread : public std::enable_shared_from_this,
   ///this one.
   ///Otherwise this plan will go on the end of the plan stack.
   ///
-  /// \param[in] addr_context
-  ///When dealing with stepping through inlined functions the current PC is
-  ///not enough information to know
-  ///what "step" means.  For instance a series of nested inline functions
-  ///might start at the same address.
-  // The \a addr_context provides the current symbol context the step
-  ///is supposed to be out of.
-  //   FIXME: Currently unused.
-  ///
-  /// \param[in] first_insn
-  /// \b true if this is the first instruction of a function.
-  ///
   /// \param[in] stop_other_threads
   ///\b true if we will stop other threads while we single step this one.
   ///
@@ -876,9 +864,8 @@ class Thread : public std::enable_shared_from_this,
   /// A shared pointer to the newly queued thread plan, or nullptr if the
   /// plan could not be queued.
   virtual lldb::ThreadPlanSP QueueThreadPlanForStepOut(
-  bool abort_other_plans, SymbolContext *addr_context, bool first_insn,
-  bool stop_other_threads, Vote report_stop_vote, Vote report_run_vote,
-  uint32_t frame_idx, Status &status,
+  bool abort_other_plans, bool stop_other_threads, Vote report_stop_vote,
+  Vote report_run_vote, uint32_t frame_idx, Status &status,
   LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate);
 
   /// Queue the plan used to step out of the function at the current PC of
@@ -892,18 +879,6 @@ class Thread : public std::enable_shared_from_this,
   ///this one.
   ///Otherwise this plan will go on the end of the plan stack.
   ///
-  /// \param[in] addr_context
-  ///When dealing with stepping through inlined functions the current PC is
-  ///not enough information to know
-  ///what "step" means.  For instance a series of nested inline functions
-  ///might start at the same address.
-  // The \a addr_context provides the current symbol context the step
-  ///is supposed to be out of.
-  //   FIXME: Currently unused.
-  ///
-  /// \param[in] first_insn
-  /// \b true if this is the first instruction of a function.
-  ///
   /// \param[in] stop_other_threads
   ///\b true if we will stop other threads while we single step this one.
   ///
@@ -940,9 +915,9 @@ class Thread : public std::enable_shared_from_this,
   /// A shared pointer to the newly queued thread plan, or nullptr if the
   /// plan could not be queued.
   virtual lldb::ThreadPlanSP QueueThreadPlanForStepOutNoShouldStop(
-  bool abort_other_plans, SymbolContext *addr_context, bool first_insn,
-  bool stop_other_threads, Vote report_stop_vote, Vote report_run_vote,
-  uint32_t frame_idx, Status &status, bool continue_to_next_branch = 
false);
+  bool abort_other_plans, bool stop_other_threads, Vote report_stop_vote,
+  Vote report_run_vote, uint32_t frame_idx, St

[llvm-branch-commits] [llvm] [BOLT] Gadget scanner: clarify MCPlusBuilder callbacks interface (PR #136147)

2025-04-17 Thread Anatoly Trosinenko via llvm-branch-commits

https://github.com/atrosinenko ready_for_review 
https://github.com/llvm/llvm-project/pull/136147
___
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 authentication oracles (PR #135663)

2025-04-17 Thread Anatoly Trosinenko via llvm-branch-commits

https://github.com/atrosinenko updated 
https://github.com/llvm/llvm-project/pull/135663

>From cf8c516866e0815b7e93782ca35fa33f6287feac Mon Sep 17 00:00:00 2001
From: Anatoly Trosinenko 
Date: Sat, 5 Apr 2025 14:54:01 +0300
Subject: [PATCH] [BOLT] Gadget scanner: detect authentication oracles

Implement the detection of authentication instructions whose results can
be inspected by an attacker to know whether authentication succeeded.

As the properties of output registers of authentication instructions are
inspected, add a second set of analysis-related classes to iterate over
the instructions in reverse order.
---
 bolt/include/bolt/Passes/PAuthGadgetScanner.h |  12 +
 bolt/lib/Passes/PAuthGadgetScanner.cpp| 541 +
 .../AArch64/gs-pauth-authentication-oracles.s | 723 ++
 .../AArch64/gs-pauth-debug-output.s   |  78 ++
 4 files changed, 1354 insertions(+)
 create mode 100644 
bolt/test/binary-analysis/AArch64/gs-pauth-authentication-oracles.s

diff --git a/bolt/include/bolt/Passes/PAuthGadgetScanner.h 
b/bolt/include/bolt/Passes/PAuthGadgetScanner.h
index 3b6c1f6af94a0..2b923e362941f 100644
--- a/bolt/include/bolt/Passes/PAuthGadgetScanner.h
+++ b/bolt/include/bolt/Passes/PAuthGadgetScanner.h
@@ -261,6 +261,15 @@ class ClobberingInfo : public ExtraInfo {
   void print(raw_ostream &OS, const MCInstReference Location) const override;
 };
 
+class LeakageInfo : public ExtraInfo {
+  SmallVector LeakingInstrs;
+
+public:
+  LeakageInfo(const ArrayRef Instrs) : LeakingInstrs(Instrs) 
{}
+
+  void print(raw_ostream &OS, const MCInstReference Location) const override;
+};
+
 /// A brief version of a report that can be further augmented with the details.
 ///
 /// It is common for a particular type of gadget detector to be tied to some
@@ -302,6 +311,9 @@ class FunctionAnalysis {
   void findUnsafeUses(SmallVector> &Reports);
   void augmentUnsafeUseReports(const ArrayRef> Reports);
 
+  void findUnsafeDefs(SmallVector> &Reports);
+  void augmentUnsafeDefReports(const ArrayRef> Reports);
+
 public:
   FunctionAnalysis(BinaryFunction &BF, MCPlusBuilder::AllocatorIdTy 
AllocatorId,
bool PacRetGadgetsOnly)
diff --git a/bolt/lib/Passes/PAuthGadgetScanner.cpp 
b/bolt/lib/Passes/PAuthGadgetScanner.cpp
index 2e4d8ff933a65..f12354390c3f3 100644
--- a/bolt/lib/Passes/PAuthGadgetScanner.cpp
+++ b/bolt/lib/Passes/PAuthGadgetScanner.cpp
@@ -716,6 +716,461 @@ SrcSafetyAnalysis::create(BinaryFunction &BF,
RegsToTrackInstsFor);
 }
 
+/// A state representing which registers are safe to be used as the destination
+/// operand of an authentication instruction.
+///
+/// Similar to SrcState, it is the analysis that should take register aliasing
+/// into account.
+///
+/// Depending on the implementation, it may be possible that an authentication
+/// instruction returns an invalid pointer on failure instead of terminating
+/// the program immediately (assuming the program will crash as soon as that
+/// pointer is dereferenced). To prevent brute-forcing the correct signature,
+/// it should be impossible for an attacker to test if a pointer is correctly
+/// signed - either the program should be terminated on authentication failure
+/// or it should be impossible to tell whether authentication succeeded or not.
+///
+/// For that reason, a restricted set of operations is allowed on any register
+/// containing a value derived from the result of an authentication instruction
+/// until that register is either wiped or checked not to contain a result of a
+/// failed authentication.
+///
+/// Specifically, the safety property for a register is computed by iterating
+/// the instructions in backward order: the source register Xn of an 
instruction
+/// Inst is safe if at least one of the following is true:
+/// * Inst checks if Xn contains the result of a successful authentication and
+///   terminates the program on failure. Note that Inst can either naturally
+///   dereference Xn (load, branch, return, etc. instructions) or be the first
+///   instruction of an explicit checking sequence.
+/// * Inst performs safe address arithmetic AND both source and result
+///   registers, as well as any temporary registers, must be safe after
+///   execution of Inst (temporaries are not used on AArch64 and thus not
+///   currently supported/allowed).
+///   See MCPlusBuilder::analyzeAddressArithmeticsForPtrAuth for the details.
+/// * Inst fully overwrites Xn with an unrelated value.
+struct DstState {
+  /// The set of registers whose values cannot be inspected by an attacker in
+  /// a way usable as an authentication oracle. The results of authentication
+  /// instructions should be written to such registers.
+  BitVector CannotEscapeUnchecked;
+
+  std::vector> FirstInstLeakingReg;
+
+  /// Construct an empty state.
+  DstState() {}
+
+  DstState(unsigned NumRegs, unsigned NumRegsToTrack)
+  : CannotEscapeUnchecke

[llvm-branch-commits] [SPARC] Promote i32 CTTZ when we have VIS3 (PR #135894)

2025-04-17 Thread via llvm-branch-commits

https://github.com/koachan updated 
https://github.com/llvm/llvm-project/pull/135894


___
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] 6170581 - Revert "[Clang] Bypass TAD during overload resolution if a perfect match exis…"

2025-04-17 Thread via llvm-branch-commits

Author: cor3ntin
Date: 2025-04-17T11:00:23+02:00
New Revision: 61705818e19b6a2e35a4a65f1104d26ce0c1929a

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

LOG: Revert "[Clang] Bypass TAD during overload resolution if a perfect match 
exis…"

This reverts commit 377ec36b323ea99ca316cb5cf79c0a0c93eebc37.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Overload.h
clang/lib/Sema/SemaCodeComplete.cpp
clang/lib/Sema/SemaInit.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp

clang/test/CXX/temp/temp.constr/temp.constr.atomic/constrant-satisfaction-conversions.cpp
clang/test/SemaCUDA/function-overload.cu
clang/test/SemaCXX/implicit-member-functions.cpp
clang/test/SemaTemplate/instantiate-function-params.cpp
clang/test/Templight/templight-empty-entries-fix.cpp

Removed: 
clang/test/SemaCXX/overload-resolution-deferred-templates.cpp



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index fc36962b317e8..4f640697e1817 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -96,12 +96,6 @@ C++ Language Changes
   asm((std::string_view("nop")) ::: (std::string_view("memory")));
 }
 
-- Clang now implements the changes to overload resolution proposed by section 
1 and 2 of
-  `P3606 `_. If a non-template candidate exists in 
an overload set that is
-  a perfect match (all conversion sequences are identity conversions) template 
candidates are not instantiated.
-  Diagnostics that would have resulted from the instantiation of these 
template candidates are no longer
-  produced. This aligns Clang closer to the behavior of GCC, and fixes 
(#GH62096), (#GH74581), and (#GH74581).
-
 C++2c Feature Support
 ^
 

diff  --git a/clang/include/clang/Sema/Overload.h 
b/clang/include/clang/Sema/Overload.h
index e667147bfac7e..6e08762dcc6d7 100644
--- a/clang/include/clang/Sema/Overload.h
+++ b/clang/include/clang/Sema/Overload.h
@@ -407,26 +407,6 @@ class Sema;
  Third == ICK_Identity;
 }
 
-/// A conversion sequence is perfect if it is an identity conversion and
-/// the type of the source is the same as the type of the target.
-bool isPerfect(const ASTContext &C) const {
-  if (!isIdentityConversion())
-return false;
-  // If we are not performing a reference binding, we can skip comparing
-  // the types, which has a noticeable performance impact.
-  if (!ReferenceBinding) {
-// The types might 
diff er if there is an array-to-pointer conversion
-// or lvalue-to-rvalue conversion.
-assert(First || C.hasSameUnqualifiedType(getFromType(), getToType(2)));
-return true;
-  }
-  if (!C.hasSameType(getFromType(), getToType(2)))
-return false;
-  if (BindsToRvalue && IsLvalueReference)
-return false;
-  return true;
-}
-
 ImplicitConversionRank getRank() const;
 NarrowingKind
 getNarrowingKind(ASTContext &Context, const Expr *Converted,
@@ -763,12 +743,6 @@ class Sema;
   Standard.setAllToTypes(T);
 }
 
-/// A conversion sequence is perfect if it is an identity conversion and
-/// the type of the source is the same as the type of the target.
-bool isPerfect(const ASTContext &C) const {
-  return isStandard() && Standard.isPerfect(C);
-}
-
 // True iff this is a conversion sequence from an initializer list to an
 // array or std::initializer.
 bool hasInitializerListContainerType() const {
@@ -965,10 +939,6 @@ class Sema;
 LLVM_PREFERRED_TYPE(CallExpr::ADLCallKind)
 unsigned IsADLCandidate : 1;
 
-/// Whether FinalConversion has been set.
-LLVM_PREFERRED_TYPE(bool)
-unsigned HasFinalConversion : 1;
-
 /// Whether this is a rewritten candidate, and if so, of what kind?
 LLVM_PREFERRED_TYPE(OverloadCandidateRewriteKind)
 unsigned RewriteKind : 2;
@@ -1009,20 +979,6 @@ class Sema;
   return false;
 }
 
-// An overload is a perfect match if the conversion
-// sequences for each argument are perfect.
-bool isPerfectMatch(const ASTContext &Ctx) const {
-  if (!Viable)
-return false;
-  for (const auto &C : Conversions) {
-if (!C.isInitialized() || !C.isPerfect(Ctx))
-  return false;
-  }
-  if (HasFinalConversion)
-return FinalConversion.isPerfect(Ctx);
-  return true;
-}
-
 bool TryToFixBadConversion(unsigned Idx, Sema &S) {
   bool CanFix = Fix.tryToFixConversion(
   Conversions[Idx].Bad.FromExpr,
@@ -1056,67 +1012,8 @@ class Sema;
 : IsSurrogate(false), IgnoreObjectArgument(false),
   TookAddressOfOver

[llvm-branch-commits] [SPARC] Use op-then-neg instructions when we have VIS3 (PR #135717)

2025-04-17 Thread Matt Arsenault via llvm-branch-commits


@@ -316,4 +316,17 @@ def : Pat<(i64 (sext (i32 (bitconvert f32:$src, 
(MOVSTOSW $src)>;
 def : Pat<(f32 (bitconvert i32:$src)), (MOVWTOS $src)>;
 def : Pat<(i64 (bitconvert f64:$src)), (MOVDTOX $src)>;
 def : Pat<(f64 (bitconvert i64:$src)), (MOVXTOD $src)>;
+
+// OP-then-neg FP operations.
+def : Pat<(f32 (fneg (fadd f32:$rs1, f32:$rs2))), (FNADDS $rs1, $rs2)>;
+def : Pat<(f64 (fneg (fadd f64:$rs1, f64:$rs2))), (FNADDD $rs1, $rs2)>;
+def : Pat<(f32 (fneg (fmul f32:$rs1, f32:$rs2))), (FNMULS $rs1, $rs2)>;
+def : Pat<(f32 (fmul (fneg f32:$rs1), f32:$rs2)), (FNMULS $rs1, $rs2)>;
+def : Pat<(f32 (fmul f32:$rs1, (fneg f32:$rs2))), (FNMULS $rs1, $rs2)>;
+def : Pat<(f64 (fneg (fmul f64:$rs1, f64:$rs2))), (FNMULD $rs1, $rs2)>;
+def : Pat<(f64 (fmul (fneg f64:$rs1), f64:$rs2)), (FNMULD $rs1, $rs2)>;
+def : Pat<(f64 (fmul f64:$rs1, (fneg f64:$rs2))), (FNMULD $rs1, $rs2)>;
+def : Pat<(f64 (fneg (fmul (fpextend f32:$rs1), (fpextend f32:$rs2, 
(FNSMULD $rs1, $rs2)>;
+def : Pat<(f64 (fmul (fneg (fpextend f32:$rs1)), (fpextend f32:$rs2))), 
(FNSMULD $rs1, $rs2)>;
+def : Pat<(f64 (fmul (fpextend f32:$rs1), (fneg (fpextend f32:$rs2, 
(FNSMULD $rs1, $rs2)>;

arsenm wrote:

fneg/fabs modifier folding is complex. We have both uses-into-defs and 
defs-into-uses patterns. The generic code has a conservative subset of foldable 
cases handled in getNegatedExpression, mostly dependent on what 
isFNegFree/isFAbsFree report. On AMDGPU we have a much more aggressive set of 
context dependent folds.

In general these are pushed up into the defs 

https://github.com/llvm/llvm-project/pull/135717
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits