[llvm-branch-commits] [llvm] [AMDGPU] Improve StructurizeCFG pass performance by using SSAUpdaterBulk. (PR #135181)

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

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


https://github.com/llvm/llvm-project/pull/135181
___
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] SCEVExpander: Don't look at uses of constants (PR #134691)

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

https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/134691

>From 36377c351008594c2b05c4751a483c3c5565e68e Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Mon, 7 Apr 2025 21:56:00 +0700
Subject: [PATCH] SCEVExpander: Don't look at uses of constants

This could be more relaxed, and look for uses of globals in
the same function but no tests apparently depend on that.
---
 .../Utils/ScalarEvolutionExpander.cpp | 29 ++-
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp 
b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
index 41bf202230e22..e25ec6c3b2a58 100644
--- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
+++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
@@ -111,20 +111,23 @@ Value *SCEVExpander::ReuseOrCreateCast(Value *V, Type *Ty,
 
   Value *Ret = nullptr;
 
-  // Check to see if there is already a cast!
-  for (User *U : V->users()) {
-if (U->getType() != Ty)
-  continue;
-CastInst *CI = dyn_cast(U);
-if (!CI || CI->getOpcode() != Op)
-  continue;
+  if (!isa(V)) {
+// Check to see if there is already a cast!
+for (User *U : V->users()) {
+  if (U->getType() != Ty)
+continue;
+  CastInst *CI = dyn_cast(U);
+  if (!CI || CI->getOpcode() != Op)
+continue;
 
-// Found a suitable cast that is at IP or comes before IP. Use it. Note 
that
-// the cast must also properly dominate the Builder's insertion point.
-if (IP->getParent() == CI->getParent() && &*BIP != CI &&
-(&*IP == CI || CI->comesBefore(&*IP))) {
-  Ret = CI;
-  break;
+  // Found a suitable cast that is at IP or comes before IP. Use it. Note
+  // that the cast must also properly dominate the Builder's insertion
+  // point.
+  if (IP->getParent() == CI->getParent() && &*BIP != CI &&
+  (&*IP == CI || CI->comesBefore(&*IP))) {
+Ret = CI;
+break;
+  }
 }
   }
 

___
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] SimplifyLibCalls: Skip sincospi optimization for ConstantData (PR #134688)

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

https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/134688

>From a59013c053ef9362ca9a15436d31435dec39a5d5 Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Mon, 7 Apr 2025 07:36:45 +0700
Subject: [PATCH] SimplifyLibCalls: Skip sincospi optimization for ConstantData

Avoids looking at the uselist, and it would probably be more
productive to constant fold this.
---
 .../lib/Transforms/Utils/SimplifyLibCalls.cpp |  3 +++
 llvm/test/Transforms/InstCombine/sincospi.ll  | 24 +++
 2 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp 
b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index 2d0027d976019..4e37c587dc975 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -3002,6 +3002,9 @@ Value *LibCallSimplifier::optimizeSinCosPi(CallInst *CI, 
bool IsSin, IRBuilderBa
 return nullptr;
 
   Value *Arg = CI->getArgOperand(0);
+  if (isa(Arg))
+return nullptr;
+
   SmallVector SinCalls;
   SmallVector CosCalls;
   SmallVector SinCosCalls;
diff --git a/llvm/test/Transforms/InstCombine/sincospi.ll 
b/llvm/test/Transforms/InstCombine/sincospi.ll
index b76ae20171147..14da03dff6f49 100644
--- a/llvm/test/Transforms/InstCombine/sincospi.ll
+++ b/llvm/test/Transforms/InstCombine/sincospi.ll
@@ -90,18 +90,14 @@ define float @test_instbased_f32_other_user(ptr %ptr) {
 
 define float @test_constant_f32() {
 ; CHECK-FLOAT-IN-VEC-LABEL: @test_constant_f32(
-; CHECK-FLOAT-IN-VEC-NEXT:[[SINCOSPI:%.*]] = call <2 x float> 
@__sincospif_stret(float 1.00e+00)
-; CHECK-FLOAT-IN-VEC-NEXT:[[SINPI:%.*]] = extractelement <2 x float> 
[[SINCOSPI]], i64 0
-; CHECK-FLOAT-IN-VEC-NEXT:[[COSPI:%.*]] = extractelement <2 x float> 
[[SINCOSPI]], i64 1
-; CHECK-FLOAT-IN-VEC-NEXT:[[COS:%.*]] = call float @__cospif(float 
1.00e+00) #[[ATTR0]]
+; CHECK-FLOAT-IN-VEC-NEXT:[[SINPI:%.*]] = call float @__sinpif(float 
1.00e+00) #[[ATTR0]]
+; CHECK-FLOAT-IN-VEC-NEXT:[[COSPI:%.*]] = call float @__cospif(float 
1.00e+00) #[[ATTR0]]
 ; CHECK-FLOAT-IN-VEC-NEXT:[[RES:%.*]] = fadd float [[SINPI]], [[COSPI]]
 ; CHECK-FLOAT-IN-VEC-NEXT:ret float [[RES]]
 ;
 ; CHECK-LABEL: @test_constant_f32(
-; CHECK-NEXT:[[SINCOSPI:%.*]] = call { float, float } 
@__sincospif_stret(float 1.00e+00)
-; CHECK-NEXT:[[SINPI:%.*]] = extractvalue { float, float } [[SINCOSPI]], 0
-; CHECK-NEXT:[[COSPI:%.*]] = extractvalue { float, float } [[SINCOSPI]], 1
-; CHECK-NEXT:[[COS:%.*]] = call float @__cospif(float 1.00e+00) 
#[[ATTR0]]
+; CHECK-NEXT:[[SINPI:%.*]] = call float @__sinpif(float 1.00e+00) 
#[[ATTR0]]
+; CHECK-NEXT:[[COSPI:%.*]] = call float @__cospif(float 1.00e+00) 
#[[ATTR0]]
 ; CHECK-NEXT:[[RES:%.*]] = fadd float [[SINPI]], [[COSPI]]
 ; CHECK-NEXT:ret float [[RES]]
 ;
@@ -172,18 +168,14 @@ define double @test_instbased_f64() {
 
 define double @test_constant_f64() {
 ; CHECK-FLOAT-IN-VEC-LABEL: @test_constant_f64(
-; CHECK-FLOAT-IN-VEC-NEXT:[[SINCOSPI:%.*]] = call { double, double } 
@__sincospi_stret(double 1.00e+00)
-; CHECK-FLOAT-IN-VEC-NEXT:[[SINPI:%.*]] = extractvalue { double, double } 
[[SINCOSPI]], 0
-; CHECK-FLOAT-IN-VEC-NEXT:[[COSPI:%.*]] = extractvalue { double, double } 
[[SINCOSPI]], 1
-; CHECK-FLOAT-IN-VEC-NEXT:[[COS:%.*]] = call double @__cospi(double 
1.00e+00) #[[ATTR0]]
+; CHECK-FLOAT-IN-VEC-NEXT:[[SINPI:%.*]] = call double @__sinpi(double 
1.00e+00) #[[ATTR0]]
+; CHECK-FLOAT-IN-VEC-NEXT:[[COSPI:%.*]] = call double @__cospi(double 
1.00e+00) #[[ATTR0]]
 ; CHECK-FLOAT-IN-VEC-NEXT:[[RES:%.*]] = fadd double [[SINPI]], [[COSPI]]
 ; CHECK-FLOAT-IN-VEC-NEXT:ret double [[RES]]
 ;
 ; CHECK-LABEL: @test_constant_f64(
-; CHECK-NEXT:[[SINCOSPI:%.*]] = call { double, double } 
@__sincospi_stret(double 1.00e+00)
-; CHECK-NEXT:[[SINPI:%.*]] = extractvalue { double, double } [[SINCOSPI]], 0
-; CHECK-NEXT:[[COSPI:%.*]] = extractvalue { double, double } [[SINCOSPI]], 
1
-; CHECK-NEXT:[[COS:%.*]] = call double @__cospi(double 1.00e+00) 
#[[ATTR0]]
+; CHECK-NEXT:[[SINPI:%.*]] = call double @__sinpi(double 1.00e+00) 
#[[ATTR0]]
+; CHECK-NEXT:[[COSPI:%.*]] = call double @__cospi(double 1.00e+00) 
#[[ATTR0]]
 ; CHECK-NEXT:[[RES:%.*]] = fadd double [[SINPI]], [[COSPI]]
 ; CHECK-NEXT:ret double [[RES]]
 ;

___
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] LICM: Avoid looking at use list of constant data (PR #134690)

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

https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/134690

>From a0cee0af33f27ac37aff44f8c20f76d0f4f1dbd8 Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Mon, 7 Apr 2025 20:10:54 +0700
Subject: [PATCH] LICM: Avoid looking at use list of constant data

The codegen test changes seem incidental. Either way,
sms-grp-order.ll seems to already not hit the original issue.
---
 llvm/lib/Transforms/Scalar/LICM.cpp| 12 ---
 llvm/test/CodeGen/AMDGPU/swdev380865.ll|  9 ++---
 llvm/test/CodeGen/PowerPC/pr43527.ll   | 22 +++-
 llvm/test/CodeGen/PowerPC/pr48519.ll   |  5 +--
 llvm/test/CodeGen/PowerPC/sms-grp-order.ll | 30 
 llvm/test/Transforms/LICM/pr50367.ll   | 41 +-
 llvm/test/Transforms/LICM/pr59324.ll   | 27 +-
 7 files changed, 110 insertions(+), 36 deletions(-)

diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp 
b/llvm/lib/Transforms/Scalar/LICM.cpp
index d872a381050ca..889b43a843bef 100644
--- a/llvm/lib/Transforms/Scalar/LICM.cpp
+++ b/llvm/lib/Transforms/Scalar/LICM.cpp
@@ -2294,10 +2294,14 @@ collectPromotionCandidates(MemorySSA *MSSA, 
AliasAnalysis *AA, Loop *L) {
   AliasSetTracker AST(BatchAA);
 
   auto IsPotentiallyPromotable = [L](const Instruction *I) {
-if (const auto *SI = dyn_cast(I))
-  return L->isLoopInvariant(SI->getPointerOperand());
-if (const auto *LI = dyn_cast(I))
-  return L->isLoopInvariant(LI->getPointerOperand());
+if (const auto *SI = dyn_cast(I)) {
+  const Value *PtrOp = SI->getPointerOperand();
+  return !isa(PtrOp) && L->isLoopInvariant(PtrOp);
+}
+if (const auto *LI = dyn_cast(I)) {
+  const Value *PtrOp = LI->getPointerOperand();
+  return !isa(PtrOp) && L->isLoopInvariant(PtrOp);
+}
 return false;
   };
 
diff --git a/llvm/test/CodeGen/AMDGPU/swdev380865.ll 
b/llvm/test/CodeGen/AMDGPU/swdev380865.ll
index 9189cef019cf4..4a5dc8f300af3 100644
--- a/llvm/test/CodeGen/AMDGPU/swdev380865.ll
+++ b/llvm/test/CodeGen/AMDGPU/swdev380865.ll
@@ -16,15 +16,16 @@ define amdgpu_kernel void @_Z6kernelILi4000ELi1EEvPd(ptr 
addrspace(1) %x.coerce)
 ; CHECK:   ; %bb.0: ; %entry
 ; CHECK-NEXT:s_mov_b64 s[0:1], 0
 ; CHECK-NEXT:s_load_dword s2, s[0:1], 0x0
+; CHECK-NEXT:s_mov_b64 s[0:1], 0x100
 ; CHECK-NEXT:s_load_dwordx2 s[6:7], s[0:1], 0x0
 ; CHECK-NEXT:s_mov_b32 s4, 0
 ; CHECK-NEXT:s_mov_b32 s0, 0
-; CHECK-NEXT:s_mov_b32 s5, 0x4028
 ; CHECK-NEXT:s_waitcnt lgkmcnt(0)
 ; CHECK-NEXT:s_mov_b32 s1, s2
 ; CHECK-NEXT:s_mov_b32 s2, 0
 ; CHECK-NEXT:v_mov_b32_e32 v0, s6
 ; CHECK-NEXT:s_mov_b32 s3, 0x4026
+; CHECK-NEXT:s_mov_b32 s5, 0x4028
 ; CHECK-NEXT:v_mov_b32_e32 v1, s7
 ; CHECK-NEXT:  .LBB0_1: ; %for.cond4.preheader
 ; CHECK-NEXT:; =>This Inner Loop Header: Depth=1
@@ -50,7 +51,7 @@ define amdgpu_kernel void @_Z6kernelILi4000ELi1EEvPd(ptr 
addrspace(1) %x.coerce)
 ; CHECK-NEXT:v_add_f64 v[0:1], v[0:1], s[4:5]
 ; CHECK-NEXT:s_cbranch_scc1 .LBB0_1
 ; CHECK-NEXT:  ; %bb.2: ; %for.cond.cleanup.loopexit
-; CHECK-NEXT:v_mov_b32_e32 v2, 0
+; CHECK-NEXT:v_mov_b32_e32 v2, 0x100
 ; CHECK-NEXT:v_mov_b32_e32 v3, 0
 ; CHECK-NEXT:global_store_dwordx2 v[2:3], v[0:1], off
 ; CHECK-NEXT:s_endpgm
@@ -61,7 +62,7 @@ entry:
 
 for.cond4.preheader:  ; preds = 
%for.cond4.preheader, %entry
   %idx.07 = phi i32 [ %add13, %for.cond4.preheader ], [ 0, %entry ]
-  %arrayidx.promoted = load double, ptr addrspace(1) null, align 8
+  %arrayidx.promoted = load double, ptr addrspace(1) inttoptr (i64 256 to ptr 
addrspace(1)), align 8
   %add9 = fadd contract double %arrayidx.promoted, 0.00e+00
   %add9.1 = fadd contract double %add9, 5.00e+00
   %add9.2 = fadd contract double %add9.1, 6.00e+00
@@ -70,7 +71,7 @@ for.cond4.preheader:  ; preds = 
%for.cond4.preheader
   %add9.5 = fadd contract double %add9.4, 1.00e+01
   %add9.6 = fadd contract double %add9.5, 1.10e+01
   %add9.7 = fadd contract double %add9.6, 1.20e+01
-  store double %add9.7, ptr addrspace(1) null, align 8
+  store double %add9.7, ptr addrspace(1) inttoptr (i64 256 to ptr 
addrspace(1)), align 8
   %add13 = add i32 %idx.07, %0
   %cmp = icmp slt i32 %add13, 2560
   br i1 %cmp, label %for.cond4.preheader, label %for.cond.cleanup
diff --git a/llvm/test/CodeGen/PowerPC/pr43527.ll 
b/llvm/test/CodeGen/PowerPC/pr43527.ll
index 379bd6c070c77..adfea51077a0b 100644
--- a/llvm/test/CodeGen/PowerPC/pr43527.ll
+++ b/llvm/test/CodeGen/PowerPC/pr43527.ll
@@ -2,7 +2,7 @@
 ; RUN: llc -ppc-asm-full-reg-names -verify-machineinstrs \
 ; RUN:   -mtriple=powerpc64le-unknown-linux-gnu -mcpu=pwr8 < %s | FileCheck %s
 ; We don't want to produce a CTR loop due to the call to lrint in the body.
-define dso_local void @test(i64 %arg, i64 %arg1) {
+define dso_local void @test(i64 %arg, i64 %arg1, ptr %arg2) {
 ; CHECK-LABEL: test:
 ; CHECK:

[llvm-branch-commits] [llvm] PHITransAddr: Avoid looking at constant use lists (PR #134689)

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

https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/134689

>From 744e2c14fb3f9134f3e9bd658066e13a04838771 Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Mon, 7 Apr 2025 07:42:53 +0700
Subject: [PATCH] PHITransAddr: Avoid looking at constant use lists

Avoids asserts in GVN
---
 llvm/lib/Analysis/PHITransAddr.cpp  |  3 ++
 llvm/test/Transforms/GVN/pr65447.ll | 83 ++---
 2 files changed, 79 insertions(+), 7 deletions(-)

diff --git a/llvm/lib/Analysis/PHITransAddr.cpp 
b/llvm/lib/Analysis/PHITransAddr.cpp
index e42113db42781..276708c2ebf77 100644
--- a/llvm/lib/Analysis/PHITransAddr.cpp
+++ b/llvm/lib/Analysis/PHITransAddr.cpp
@@ -224,6 +224,9 @@ Value *PHITransAddr::translateSubExpr(Value *V, BasicBlock 
*CurBB,
 
 // Scan to see if we have this GEP available.
 Value *APHIOp = GEPOps[0];
+if (isa(APHIOp))
+  return nullptr;
+
 for (User *U : APHIOp->users()) {
   if (GetElementPtrInst *GEPI = dyn_cast(U))
 if (GEPI->getType() == GEP->getType() &&
diff --git a/llvm/test/Transforms/GVN/pr65447.ll 
b/llvm/test/Transforms/GVN/pr65447.ll
index 1b951e907e822..1fa3811a3a81d 100644
--- a/llvm/test/Transforms/GVN/pr65447.ll
+++ b/llvm/test/Transforms/GVN/pr65447.ll
@@ -2,29 +2,98 @@
 ; RUN: opt -S -passes=gvn < %s | FileCheck %s
 
 ; Make sure deduplicated phi nodes are removed from the VN map.
-define i64 @f() {
-; CHECK-LABEL: define i64 @f() {
+define i64 @f2(ptr %arg) {
+; CHECK-LABEL: define i64 @f2(
+; CHECK-SAME: ptr [[ARG:%.*]]) {
+; CHECK-NEXT:  BB:
+; CHECK-NEXT:store i1 false, ptr [[ARG]], align 1
+; CHECK-NEXT:br label [[BB2D:%.*]]
+; CHECK:   BB2a:
+; CHECK-NEXT:br label [[BB2B:%.*]]
+; CHECK:   BB2b:
+; CHECK-NEXT:br label [[BB2C:%.*]]
+; CHECK:   BB2c:
+; CHECK-NEXT:[[AZ2:%.*]] = phi i1 [ true, [[BB2B]] ], [ [[AZ:%.*]], 
[[BB2D]] ]
+; CHECK-NEXT:[[DOTPHI_TRANS_INSERT:%.*]] = sext i1 [[AZ2]] to i64
+; CHECK-NEXT:[[GEP2_PHI_TRANS_INSERT:%.*]] = getelementptr i1, ptr 
[[ARG]], i64 [[DOTPHI_TRANS_INSERT]]
+; CHECK-NEXT:[[L93_PRE:%.*]] = load i1, ptr [[GEP2_PHI_TRANS_INSERT]], 
align 1
+; CHECK-NEXT:br label [[BB2D]]
+; CHECK:   BB2d:
+; CHECK-NEXT:[[AZ]] = phi i1 [ [[AZ2]], [[BB2C]] ], [ false, [[BB:%.*]] ]
+; CHECK-NEXT:[[L93:%.*]] = phi i1 [ [[L93_PRE]], [[BB2C]] ], [ false, 
[[BB]] ]
+; CHECK-NEXT:[[TMP0:%.*]] = sext i1 [[AZ]] to i64
+; CHECK-NEXT:[[GEP2:%.*]] = getelementptr i1, ptr [[ARG]], i64 [[TMP0]]
+; CHECK-NEXT:store i1 [[AZ]], ptr [[ARG]], align 2
+; CHECK-NEXT:br i1 [[L93]], label [[BB2C]], label [[BB1E:%.*]]
+; CHECK:   BB1e:
+; CHECK-NEXT:br i1 [[AZ]], label [[BB2F:%.*]], label [[BB4:%.*]]
+; CHECK:   BB2f:
+; CHECK-NEXT:store i1 true, ptr [[ARG]], align 2
+; CHECK-NEXT:br label [[BB2B]]
+; CHECK:   BB4:
+; CHECK-NEXT:br label [[BB4]]
+;
+BB:
+  store i1 false, ptr %arg, align 1
+  br label %BB2d
+
+BB2a: ; No predecessors!
+  br label %BB2b
+
+BB2b:   ; preds = %BB2f, %BB2a
+  br label %BB2c
+
+BB2c: ; preds = %BB2d, %BB2b
+  %0 = phi i1 [ true, %BB2b ], [ %1, %BB2d ]
+  br label %BB2d
+
+BB2d:  ; preds = %BB2c, %BB
+  %1 = phi i1 [ %0, %BB2c ], [ false, %BB ]
+  %2 = sext i1 %1 to i64
+  %gep2 = getelementptr i1, ptr %arg, i64 %2
+  %L93 = load i1, ptr %gep2, align 1
+  %Az = load i1, ptr %arg, align 2
+  store i1 %1, ptr %arg, align 2
+  br i1 %L93, label %BB2c, label %BB1e
+
+BB1e:; preds = %BB2d
+  br i1 %Az, label %BB2f, label %BB4
+
+BB2f:; preds = %BB1e
+  store i1 true, ptr %arg, align 2
+  br label %BB2b
+
+BB4:  ; preds = %BB1e, %BB4
+  br label %BB4
+
+; uselistorder directives
+  uselistorder label %BB4, { 1, 0 }
+}
+
+; Make sure deduplicated phi nodes are removed from the VN map. Make
+; sure there is no assert on attempt to use ConstantData use lists.
+define i64 @f_null() {
+; CHECK-LABEL: define i64 @f_null() {
 ; CHECK-NEXT:  BB:
 ; CHECK-NEXT:store i1 false, ptr null, align 1
 ; CHECK-NEXT:br label [[BB2D:%.*]]
 ; CHECK:   BB2a:
 ; CHECK-NEXT:br label [[BB2B:%.*]]
 ; CHECK:   BB2b:
-; CHECK-NEXT:[[L93_PRE_PRE:%.*]] = load i1, ptr inttoptr (i64 -1 to ptr), 
align 1
 ; CHECK-NEXT:br label [[BB2C:%.*]]
 ; CHECK:   BB2c:
-; CHECK-NEXT:[[L93_PRE:%.*]] = phi i1 [ [[L93_PRE_PRE]], [[BB2B]] ], [ 
true, [[BB2D]] ]
 ; CHECK-NEXT:[[AZ2:%.*]] = phi i1 [ true, [[BB2B]] ], [ [[AZ:%.*]], 
[[BB2D]] ]
 ; CHECK-NEXT:[[DOTPHI_TRANS_INSERT:%.*]] = sext i1 [[AZ2]] to i64
 ; CHECK-NEXT:[[GEP2_PHI_TRANS_INSERT:%.*]] = getelementptr i1, ptr null, 
i64 [[DOTPHI_TRANS_INSERT]]
+; CHECK-NEXT:[[L93_PRE:%.*]] = load i1, ptr [[GEP2_PHI_TRANS_INSERT]], 
align 1
 ; CHECK-NEXT:br label [[BB2D]]
 ; CHECK:   BB2d:
-; CHECK-NEXT:[[L93_PRE5:%.*]] = phi i1 [ [[L93_PRE]], [[BB2C]] ], [ false,

[llvm-branch-commits] [llvm] SimplifyLibCalls: Skip sincospi optimization for ConstantData (PR #134688)

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

https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/134688

>From a59013c053ef9362ca9a15436d31435dec39a5d5 Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Mon, 7 Apr 2025 07:36:45 +0700
Subject: [PATCH] SimplifyLibCalls: Skip sincospi optimization for ConstantData

Avoids looking at the uselist, and it would probably be more
productive to constant fold this.
---
 .../lib/Transforms/Utils/SimplifyLibCalls.cpp |  3 +++
 llvm/test/Transforms/InstCombine/sincospi.ll  | 24 +++
 2 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp 
b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index 2d0027d976019..4e37c587dc975 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -3002,6 +3002,9 @@ Value *LibCallSimplifier::optimizeSinCosPi(CallInst *CI, 
bool IsSin, IRBuilderBa
 return nullptr;
 
   Value *Arg = CI->getArgOperand(0);
+  if (isa(Arg))
+return nullptr;
+
   SmallVector SinCalls;
   SmallVector CosCalls;
   SmallVector SinCosCalls;
diff --git a/llvm/test/Transforms/InstCombine/sincospi.ll 
b/llvm/test/Transforms/InstCombine/sincospi.ll
index b76ae20171147..14da03dff6f49 100644
--- a/llvm/test/Transforms/InstCombine/sincospi.ll
+++ b/llvm/test/Transforms/InstCombine/sincospi.ll
@@ -90,18 +90,14 @@ define float @test_instbased_f32_other_user(ptr %ptr) {
 
 define float @test_constant_f32() {
 ; CHECK-FLOAT-IN-VEC-LABEL: @test_constant_f32(
-; CHECK-FLOAT-IN-VEC-NEXT:[[SINCOSPI:%.*]] = call <2 x float> 
@__sincospif_stret(float 1.00e+00)
-; CHECK-FLOAT-IN-VEC-NEXT:[[SINPI:%.*]] = extractelement <2 x float> 
[[SINCOSPI]], i64 0
-; CHECK-FLOAT-IN-VEC-NEXT:[[COSPI:%.*]] = extractelement <2 x float> 
[[SINCOSPI]], i64 1
-; CHECK-FLOAT-IN-VEC-NEXT:[[COS:%.*]] = call float @__cospif(float 
1.00e+00) #[[ATTR0]]
+; CHECK-FLOAT-IN-VEC-NEXT:[[SINPI:%.*]] = call float @__sinpif(float 
1.00e+00) #[[ATTR0]]
+; CHECK-FLOAT-IN-VEC-NEXT:[[COSPI:%.*]] = call float @__cospif(float 
1.00e+00) #[[ATTR0]]
 ; CHECK-FLOAT-IN-VEC-NEXT:[[RES:%.*]] = fadd float [[SINPI]], [[COSPI]]
 ; CHECK-FLOAT-IN-VEC-NEXT:ret float [[RES]]
 ;
 ; CHECK-LABEL: @test_constant_f32(
-; CHECK-NEXT:[[SINCOSPI:%.*]] = call { float, float } 
@__sincospif_stret(float 1.00e+00)
-; CHECK-NEXT:[[SINPI:%.*]] = extractvalue { float, float } [[SINCOSPI]], 0
-; CHECK-NEXT:[[COSPI:%.*]] = extractvalue { float, float } [[SINCOSPI]], 1
-; CHECK-NEXT:[[COS:%.*]] = call float @__cospif(float 1.00e+00) 
#[[ATTR0]]
+; CHECK-NEXT:[[SINPI:%.*]] = call float @__sinpif(float 1.00e+00) 
#[[ATTR0]]
+; CHECK-NEXT:[[COSPI:%.*]] = call float @__cospif(float 1.00e+00) 
#[[ATTR0]]
 ; CHECK-NEXT:[[RES:%.*]] = fadd float [[SINPI]], [[COSPI]]
 ; CHECK-NEXT:ret float [[RES]]
 ;
@@ -172,18 +168,14 @@ define double @test_instbased_f64() {
 
 define double @test_constant_f64() {
 ; CHECK-FLOAT-IN-VEC-LABEL: @test_constant_f64(
-; CHECK-FLOAT-IN-VEC-NEXT:[[SINCOSPI:%.*]] = call { double, double } 
@__sincospi_stret(double 1.00e+00)
-; CHECK-FLOAT-IN-VEC-NEXT:[[SINPI:%.*]] = extractvalue { double, double } 
[[SINCOSPI]], 0
-; CHECK-FLOAT-IN-VEC-NEXT:[[COSPI:%.*]] = extractvalue { double, double } 
[[SINCOSPI]], 1
-; CHECK-FLOAT-IN-VEC-NEXT:[[COS:%.*]] = call double @__cospi(double 
1.00e+00) #[[ATTR0]]
+; CHECK-FLOAT-IN-VEC-NEXT:[[SINPI:%.*]] = call double @__sinpi(double 
1.00e+00) #[[ATTR0]]
+; CHECK-FLOAT-IN-VEC-NEXT:[[COSPI:%.*]] = call double @__cospi(double 
1.00e+00) #[[ATTR0]]
 ; CHECK-FLOAT-IN-VEC-NEXT:[[RES:%.*]] = fadd double [[SINPI]], [[COSPI]]
 ; CHECK-FLOAT-IN-VEC-NEXT:ret double [[RES]]
 ;
 ; CHECK-LABEL: @test_constant_f64(
-; CHECK-NEXT:[[SINCOSPI:%.*]] = call { double, double } 
@__sincospi_stret(double 1.00e+00)
-; CHECK-NEXT:[[SINPI:%.*]] = extractvalue { double, double } [[SINCOSPI]], 0
-; CHECK-NEXT:[[COSPI:%.*]] = extractvalue { double, double } [[SINCOSPI]], 
1
-; CHECK-NEXT:[[COS:%.*]] = call double @__cospi(double 1.00e+00) 
#[[ATTR0]]
+; CHECK-NEXT:[[SINPI:%.*]] = call double @__sinpi(double 1.00e+00) 
#[[ATTR0]]
+; CHECK-NEXT:[[COSPI:%.*]] = call double @__cospi(double 1.00e+00) 
#[[ATTR0]]
 ; CHECK-NEXT:[[RES:%.*]] = fadd double [[SINPI]], [[COSPI]]
 ; CHECK-NEXT:ret double [[RES]]
 ;

___
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] PHITransAddr: Avoid looking at constant use lists (PR #134689)

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

https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/134689

>From 744e2c14fb3f9134f3e9bd658066e13a04838771 Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Mon, 7 Apr 2025 07:42:53 +0700
Subject: [PATCH] PHITransAddr: Avoid looking at constant use lists

Avoids asserts in GVN
---
 llvm/lib/Analysis/PHITransAddr.cpp  |  3 ++
 llvm/test/Transforms/GVN/pr65447.ll | 83 ++---
 2 files changed, 79 insertions(+), 7 deletions(-)

diff --git a/llvm/lib/Analysis/PHITransAddr.cpp 
b/llvm/lib/Analysis/PHITransAddr.cpp
index e42113db42781..276708c2ebf77 100644
--- a/llvm/lib/Analysis/PHITransAddr.cpp
+++ b/llvm/lib/Analysis/PHITransAddr.cpp
@@ -224,6 +224,9 @@ Value *PHITransAddr::translateSubExpr(Value *V, BasicBlock 
*CurBB,
 
 // Scan to see if we have this GEP available.
 Value *APHIOp = GEPOps[0];
+if (isa(APHIOp))
+  return nullptr;
+
 for (User *U : APHIOp->users()) {
   if (GetElementPtrInst *GEPI = dyn_cast(U))
 if (GEPI->getType() == GEP->getType() &&
diff --git a/llvm/test/Transforms/GVN/pr65447.ll 
b/llvm/test/Transforms/GVN/pr65447.ll
index 1b951e907e822..1fa3811a3a81d 100644
--- a/llvm/test/Transforms/GVN/pr65447.ll
+++ b/llvm/test/Transforms/GVN/pr65447.ll
@@ -2,29 +2,98 @@
 ; RUN: opt -S -passes=gvn < %s | FileCheck %s
 
 ; Make sure deduplicated phi nodes are removed from the VN map.
-define i64 @f() {
-; CHECK-LABEL: define i64 @f() {
+define i64 @f2(ptr %arg) {
+; CHECK-LABEL: define i64 @f2(
+; CHECK-SAME: ptr [[ARG:%.*]]) {
+; CHECK-NEXT:  BB:
+; CHECK-NEXT:store i1 false, ptr [[ARG]], align 1
+; CHECK-NEXT:br label [[BB2D:%.*]]
+; CHECK:   BB2a:
+; CHECK-NEXT:br label [[BB2B:%.*]]
+; CHECK:   BB2b:
+; CHECK-NEXT:br label [[BB2C:%.*]]
+; CHECK:   BB2c:
+; CHECK-NEXT:[[AZ2:%.*]] = phi i1 [ true, [[BB2B]] ], [ [[AZ:%.*]], 
[[BB2D]] ]
+; CHECK-NEXT:[[DOTPHI_TRANS_INSERT:%.*]] = sext i1 [[AZ2]] to i64
+; CHECK-NEXT:[[GEP2_PHI_TRANS_INSERT:%.*]] = getelementptr i1, ptr 
[[ARG]], i64 [[DOTPHI_TRANS_INSERT]]
+; CHECK-NEXT:[[L93_PRE:%.*]] = load i1, ptr [[GEP2_PHI_TRANS_INSERT]], 
align 1
+; CHECK-NEXT:br label [[BB2D]]
+; CHECK:   BB2d:
+; CHECK-NEXT:[[AZ]] = phi i1 [ [[AZ2]], [[BB2C]] ], [ false, [[BB:%.*]] ]
+; CHECK-NEXT:[[L93:%.*]] = phi i1 [ [[L93_PRE]], [[BB2C]] ], [ false, 
[[BB]] ]
+; CHECK-NEXT:[[TMP0:%.*]] = sext i1 [[AZ]] to i64
+; CHECK-NEXT:[[GEP2:%.*]] = getelementptr i1, ptr [[ARG]], i64 [[TMP0]]
+; CHECK-NEXT:store i1 [[AZ]], ptr [[ARG]], align 2
+; CHECK-NEXT:br i1 [[L93]], label [[BB2C]], label [[BB1E:%.*]]
+; CHECK:   BB1e:
+; CHECK-NEXT:br i1 [[AZ]], label [[BB2F:%.*]], label [[BB4:%.*]]
+; CHECK:   BB2f:
+; CHECK-NEXT:store i1 true, ptr [[ARG]], align 2
+; CHECK-NEXT:br label [[BB2B]]
+; CHECK:   BB4:
+; CHECK-NEXT:br label [[BB4]]
+;
+BB:
+  store i1 false, ptr %arg, align 1
+  br label %BB2d
+
+BB2a: ; No predecessors!
+  br label %BB2b
+
+BB2b:   ; preds = %BB2f, %BB2a
+  br label %BB2c
+
+BB2c: ; preds = %BB2d, %BB2b
+  %0 = phi i1 [ true, %BB2b ], [ %1, %BB2d ]
+  br label %BB2d
+
+BB2d:  ; preds = %BB2c, %BB
+  %1 = phi i1 [ %0, %BB2c ], [ false, %BB ]
+  %2 = sext i1 %1 to i64
+  %gep2 = getelementptr i1, ptr %arg, i64 %2
+  %L93 = load i1, ptr %gep2, align 1
+  %Az = load i1, ptr %arg, align 2
+  store i1 %1, ptr %arg, align 2
+  br i1 %L93, label %BB2c, label %BB1e
+
+BB1e:; preds = %BB2d
+  br i1 %Az, label %BB2f, label %BB4
+
+BB2f:; preds = %BB1e
+  store i1 true, ptr %arg, align 2
+  br label %BB2b
+
+BB4:  ; preds = %BB1e, %BB4
+  br label %BB4
+
+; uselistorder directives
+  uselistorder label %BB4, { 1, 0 }
+}
+
+; Make sure deduplicated phi nodes are removed from the VN map. Make
+; sure there is no assert on attempt to use ConstantData use lists.
+define i64 @f_null() {
+; CHECK-LABEL: define i64 @f_null() {
 ; CHECK-NEXT:  BB:
 ; CHECK-NEXT:store i1 false, ptr null, align 1
 ; CHECK-NEXT:br label [[BB2D:%.*]]
 ; CHECK:   BB2a:
 ; CHECK-NEXT:br label [[BB2B:%.*]]
 ; CHECK:   BB2b:
-; CHECK-NEXT:[[L93_PRE_PRE:%.*]] = load i1, ptr inttoptr (i64 -1 to ptr), 
align 1
 ; CHECK-NEXT:br label [[BB2C:%.*]]
 ; CHECK:   BB2c:
-; CHECK-NEXT:[[L93_PRE:%.*]] = phi i1 [ [[L93_PRE_PRE]], [[BB2B]] ], [ 
true, [[BB2D]] ]
 ; CHECK-NEXT:[[AZ2:%.*]] = phi i1 [ true, [[BB2B]] ], [ [[AZ:%.*]], 
[[BB2D]] ]
 ; CHECK-NEXT:[[DOTPHI_TRANS_INSERT:%.*]] = sext i1 [[AZ2]] to i64
 ; CHECK-NEXT:[[GEP2_PHI_TRANS_INSERT:%.*]] = getelementptr i1, ptr null, 
i64 [[DOTPHI_TRANS_INSERT]]
+; CHECK-NEXT:[[L93_PRE:%.*]] = load i1, ptr [[GEP2_PHI_TRANS_INSERT]], 
align 1
 ; CHECK-NEXT:br label [[BB2D]]
 ; CHECK:   BB2d:
-; CHECK-NEXT:[[L93_PRE5:%.*]] = phi i1 [ [[L93_PRE]], [[BB2C]] ], [ false,

[llvm-branch-commits] [llvm] LICM: Avoid looking at use list of constant data (PR #134690)

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

https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/134690

>From a0cee0af33f27ac37aff44f8c20f76d0f4f1dbd8 Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Mon, 7 Apr 2025 20:10:54 +0700
Subject: [PATCH] LICM: Avoid looking at use list of constant data

The codegen test changes seem incidental. Either way,
sms-grp-order.ll seems to already not hit the original issue.
---
 llvm/lib/Transforms/Scalar/LICM.cpp| 12 ---
 llvm/test/CodeGen/AMDGPU/swdev380865.ll|  9 ++---
 llvm/test/CodeGen/PowerPC/pr43527.ll   | 22 +++-
 llvm/test/CodeGen/PowerPC/pr48519.ll   |  5 +--
 llvm/test/CodeGen/PowerPC/sms-grp-order.ll | 30 
 llvm/test/Transforms/LICM/pr50367.ll   | 41 +-
 llvm/test/Transforms/LICM/pr59324.ll   | 27 +-
 7 files changed, 110 insertions(+), 36 deletions(-)

diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp 
b/llvm/lib/Transforms/Scalar/LICM.cpp
index d872a381050ca..889b43a843bef 100644
--- a/llvm/lib/Transforms/Scalar/LICM.cpp
+++ b/llvm/lib/Transforms/Scalar/LICM.cpp
@@ -2294,10 +2294,14 @@ collectPromotionCandidates(MemorySSA *MSSA, 
AliasAnalysis *AA, Loop *L) {
   AliasSetTracker AST(BatchAA);
 
   auto IsPotentiallyPromotable = [L](const Instruction *I) {
-if (const auto *SI = dyn_cast(I))
-  return L->isLoopInvariant(SI->getPointerOperand());
-if (const auto *LI = dyn_cast(I))
-  return L->isLoopInvariant(LI->getPointerOperand());
+if (const auto *SI = dyn_cast(I)) {
+  const Value *PtrOp = SI->getPointerOperand();
+  return !isa(PtrOp) && L->isLoopInvariant(PtrOp);
+}
+if (const auto *LI = dyn_cast(I)) {
+  const Value *PtrOp = LI->getPointerOperand();
+  return !isa(PtrOp) && L->isLoopInvariant(PtrOp);
+}
 return false;
   };
 
diff --git a/llvm/test/CodeGen/AMDGPU/swdev380865.ll 
b/llvm/test/CodeGen/AMDGPU/swdev380865.ll
index 9189cef019cf4..4a5dc8f300af3 100644
--- a/llvm/test/CodeGen/AMDGPU/swdev380865.ll
+++ b/llvm/test/CodeGen/AMDGPU/swdev380865.ll
@@ -16,15 +16,16 @@ define amdgpu_kernel void @_Z6kernelILi4000ELi1EEvPd(ptr 
addrspace(1) %x.coerce)
 ; CHECK:   ; %bb.0: ; %entry
 ; CHECK-NEXT:s_mov_b64 s[0:1], 0
 ; CHECK-NEXT:s_load_dword s2, s[0:1], 0x0
+; CHECK-NEXT:s_mov_b64 s[0:1], 0x100
 ; CHECK-NEXT:s_load_dwordx2 s[6:7], s[0:1], 0x0
 ; CHECK-NEXT:s_mov_b32 s4, 0
 ; CHECK-NEXT:s_mov_b32 s0, 0
-; CHECK-NEXT:s_mov_b32 s5, 0x4028
 ; CHECK-NEXT:s_waitcnt lgkmcnt(0)
 ; CHECK-NEXT:s_mov_b32 s1, s2
 ; CHECK-NEXT:s_mov_b32 s2, 0
 ; CHECK-NEXT:v_mov_b32_e32 v0, s6
 ; CHECK-NEXT:s_mov_b32 s3, 0x4026
+; CHECK-NEXT:s_mov_b32 s5, 0x4028
 ; CHECK-NEXT:v_mov_b32_e32 v1, s7
 ; CHECK-NEXT:  .LBB0_1: ; %for.cond4.preheader
 ; CHECK-NEXT:; =>This Inner Loop Header: Depth=1
@@ -50,7 +51,7 @@ define amdgpu_kernel void @_Z6kernelILi4000ELi1EEvPd(ptr 
addrspace(1) %x.coerce)
 ; CHECK-NEXT:v_add_f64 v[0:1], v[0:1], s[4:5]
 ; CHECK-NEXT:s_cbranch_scc1 .LBB0_1
 ; CHECK-NEXT:  ; %bb.2: ; %for.cond.cleanup.loopexit
-; CHECK-NEXT:v_mov_b32_e32 v2, 0
+; CHECK-NEXT:v_mov_b32_e32 v2, 0x100
 ; CHECK-NEXT:v_mov_b32_e32 v3, 0
 ; CHECK-NEXT:global_store_dwordx2 v[2:3], v[0:1], off
 ; CHECK-NEXT:s_endpgm
@@ -61,7 +62,7 @@ entry:
 
 for.cond4.preheader:  ; preds = 
%for.cond4.preheader, %entry
   %idx.07 = phi i32 [ %add13, %for.cond4.preheader ], [ 0, %entry ]
-  %arrayidx.promoted = load double, ptr addrspace(1) null, align 8
+  %arrayidx.promoted = load double, ptr addrspace(1) inttoptr (i64 256 to ptr 
addrspace(1)), align 8
   %add9 = fadd contract double %arrayidx.promoted, 0.00e+00
   %add9.1 = fadd contract double %add9, 5.00e+00
   %add9.2 = fadd contract double %add9.1, 6.00e+00
@@ -70,7 +71,7 @@ for.cond4.preheader:  ; preds = 
%for.cond4.preheader
   %add9.5 = fadd contract double %add9.4, 1.00e+01
   %add9.6 = fadd contract double %add9.5, 1.10e+01
   %add9.7 = fadd contract double %add9.6, 1.20e+01
-  store double %add9.7, ptr addrspace(1) null, align 8
+  store double %add9.7, ptr addrspace(1) inttoptr (i64 256 to ptr 
addrspace(1)), align 8
   %add13 = add i32 %idx.07, %0
   %cmp = icmp slt i32 %add13, 2560
   br i1 %cmp, label %for.cond4.preheader, label %for.cond.cleanup
diff --git a/llvm/test/CodeGen/PowerPC/pr43527.ll 
b/llvm/test/CodeGen/PowerPC/pr43527.ll
index 379bd6c070c77..adfea51077a0b 100644
--- a/llvm/test/CodeGen/PowerPC/pr43527.ll
+++ b/llvm/test/CodeGen/PowerPC/pr43527.ll
@@ -2,7 +2,7 @@
 ; RUN: llc -ppc-asm-full-reg-names -verify-machineinstrs \
 ; RUN:   -mtriple=powerpc64le-unknown-linux-gnu -mcpu=pwr8 < %s | FileCheck %s
 ; We don't want to produce a CTR loop due to the call to lrint in the body.
-define dso_local void @test(i64 %arg, i64 %arg1) {
+define dso_local void @test(i64 %arg, i64 %arg1, ptr %arg2) {
 ; CHECK-LABEL: test:
 ; CHECK:

[llvm-branch-commits] [llvm] IR: Remove uselist for constantdata (PR #134692)

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

llvmbot wrote:



@llvm/pr-subscribers-backend-aarch64

@llvm/pr-subscribers-llvm-ir

Author: Matt Arsenault (arsenm)


Changes

This is a resurrected version of the patch attached to this RFC:

https://discourse.llvm.org/t/rfc-constantdata-should-not-have-use-lists/42606

In this adaptation, there are a few differences. In the original patch, the 
Use's
use list was replaced with an unsigned* to the reference count in the value. 
This
version leaves them as null and leaves the ref counting only in Value.

Remove use-lists from instances of ConstantData (which are shared
across modules and have no operands).

To continue supporting most of the use-list API, store a ref-count in
place of the use-list; this is for API like Value::use_empty and
Value::hasNUses.  Operations that actually need the use-list -- like
Value::use_begin -- will assert.

This change has three benefits:

 1. The compiler output cannot in any way depend on the use-list order
of instances of ConstantData.

 2. There's no use-list traffic when adding and removing simple
constants from operand lists (although there is ref-count traffic;
YMMV).

 3. It's cheaper to serialize use-lists (since we're no longer
serializing the use-list order of things like i32 0).

The downside is that you can't look at all the users of ConstantData,
but traversals of users of i32 0 are already ill-advised.

Possible follow-ups:
  - Stop handling hasNUses checks for constants. The reference counts aren't 
really a useful replacement for these.
  - Track if an instance of a ConstantVector/ConstantArray/etc. is known
to have all ConstantData arguments, and drop the use-lists to
ref-counts in those cases.  Callers need to check Value::hasUseList
before iterating through the use-list.
  - Remove even the ref-counts.  I'm not sure they have any benefit
besides minimizing the scope of this commit, and maintaining the
counts is not free.

Fixes #58629

---

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


24 Files Affected:

- (modified) llvm/include/llvm/IR/Use.h (+6-17) 
- (modified) llvm/include/llvm/IR/Value.h (+94-24) 
- (modified) llvm/lib/Analysis/TypeMetadataUtils.cpp (+3) 
- (modified) llvm/lib/AsmParser/LLParser.cpp (+2) 
- (modified) llvm/lib/Bitcode/Reader/BitcodeReader.cpp (+4) 
- (modified) llvm/lib/Bitcode/Writer/ValueEnumerator.cpp (+3) 
- (modified) llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/CodeGenPrepare.cpp (+3) 
- (modified) llvm/lib/CodeGen/ComplexDeinterleavingPass.cpp (+3) 
- (modified) llvm/lib/IR/AsmWriter.cpp (+7-2) 
- (modified) llvm/lib/IR/Instruction.cpp (+3-1) 
- (modified) llvm/lib/IR/Use.cpp (+6-2) 
- (modified) llvm/lib/IR/Value.cpp (+18-8) 
- (modified) llvm/lib/Target/AArch64/GISel/AArch64RegisterBankInfo.cpp (+1-1) 
- (modified) llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp (+37-29) 
- (modified) llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp 
(+6-1) 
- (modified) llvm/lib/Transforms/InstCombine/InstructionCombining.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/Reassociate.cpp (+2-1) 
- (modified) llvm/test/Analysis/MemorySSA/nondeterminism.ll (-1) 
- (added) llvm/test/tools/llvm-diff/uselistorder-issue58629-gv.ll (+14) 
- (modified) llvm/test/tools/llvm-diff/uselistorder-issue58629.ll (+3-2) 
- (modified) llvm/test/tools/llvm-reduce/bitcode-uselistorder.ll (+12-11) 
- (modified) llvm/test/tools/llvm-reduce/uselistorder-invalid-ir-output.ll 
(+4-2) 
- (modified) llvm/tools/verify-uselistorder/verify-uselistorder.cpp (+9) 


``diff
diff --git a/llvm/include/llvm/IR/Use.h b/llvm/include/llvm/IR/Use.h
index a86b9c46c1f69..bcd1fd6677497 100644
--- a/llvm/include/llvm/IR/Use.h
+++ b/llvm/include/llvm/IR/Use.h
@@ -23,6 +23,7 @@
 namespace llvm {
 
 template  struct simplify_type;
+class ConstantData;
 class User;
 class Value;
 
@@ -42,10 +43,7 @@ class Use {
 
 private:
   /// Destructor - Only for zap()
-  ~Use() {
-if (Val)
-  removeFromList();
-  }
+  ~Use();
 
   /// Constructor
   Use(User *Parent) : Parent(Parent) {}
@@ -87,19 +85,10 @@ class Use {
   Use **Prev = nullptr;
   User *Parent = nullptr;
 
-  void addToList(Use **List) {
-Next = *List;
-if (Next)
-  Next->Prev = &Next;
-Prev = List;
-*Prev = this;
-  }
-
-  void removeFromList() {
-*Prev = Next;
-if (Next)
-  Next->Prev = Prev;
-  }
+  inline void addToList(unsigned &Count);
+  inline void addToList(Use *&List);
+  inline void removeFromList(unsigned &Count);
+  inline void removeFromList(Use *&List);
 };
 
 /// Allow clients to treat uses just like values when using
diff --git a/llvm/include/llvm/IR/Value.h b/llvm/include/llvm/IR/Value.h
index cfed12e2f5f8d..96e4cf446cb93 100644
--- a/llvm/include/llvm/IR/Value.h
+++ b/llvm/include/llvm/IR/Value.h
@@ -116,7 +116,10 @@ class Value {
 
 private:
   Type *VTy;
-  Use *UseList;
+  union {
+Use *List = nu

[llvm-branch-commits] [llvm] IR: Remove uselist for constantdata (PR #134692)

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

llvmbot wrote:




@llvm/pr-subscribers-llvm-analysis

Author: Matt Arsenault (arsenm)


Changes

This is a resurrected version of the patch attached to this RFC:

https://discourse.llvm.org/t/rfc-constantdata-should-not-have-use-lists/42606

In this adaptation, there are a few differences. In the original patch, the 
Use's
use list was replaced with an unsigned* to the reference count in the value. 
This
version leaves them as null and leaves the ref counting only in Value.

Remove use-lists from instances of ConstantData (which are shared
across modules and have no operands).

To continue supporting most of the use-list API, store a ref-count in
place of the use-list; this is for API like Value::use_empty and
Value::hasNUses.  Operations that actually need the use-list -- like
Value::use_begin -- will assert.

This change has three benefits:

 1. The compiler output cannot in any way depend on the use-list order
of instances of ConstantData.

 2. There's no use-list traffic when adding and removing simple
constants from operand lists (although there is ref-count traffic;
YMMV).

 3. It's cheaper to serialize use-lists (since we're no longer
serializing the use-list order of things like i32 0).

The downside is that you can't look at all the users of ConstantData,
but traversals of users of i32 0 are already ill-advised.

Possible follow-ups:
  - Stop handling hasNUses checks for constants. The reference counts aren't 
really a useful replacement for these.
  - Track if an instance of a ConstantVector/ConstantArray/etc. is known
to have all ConstantData arguments, and drop the use-lists to
ref-counts in those cases.  Callers need to check Value::hasUseList
before iterating through the use-list.
  - Remove even the ref-counts.  I'm not sure they have any benefit
besides minimizing the scope of this commit, and maintaining the
counts is not free.

Fixes #58629

---

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


24 Files Affected:

- (modified) llvm/include/llvm/IR/Use.h (+6-17) 
- (modified) llvm/include/llvm/IR/Value.h (+94-24) 
- (modified) llvm/lib/Analysis/TypeMetadataUtils.cpp (+3) 
- (modified) llvm/lib/AsmParser/LLParser.cpp (+2) 
- (modified) llvm/lib/Bitcode/Reader/BitcodeReader.cpp (+4) 
- (modified) llvm/lib/Bitcode/Writer/ValueEnumerator.cpp (+3) 
- (modified) llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/CodeGenPrepare.cpp (+3) 
- (modified) llvm/lib/CodeGen/ComplexDeinterleavingPass.cpp (+3) 
- (modified) llvm/lib/IR/AsmWriter.cpp (+7-2) 
- (modified) llvm/lib/IR/Instruction.cpp (+3-1) 
- (modified) llvm/lib/IR/Use.cpp (+6-2) 
- (modified) llvm/lib/IR/Value.cpp (+18-8) 
- (modified) llvm/lib/Target/AArch64/GISel/AArch64RegisterBankInfo.cpp (+1-1) 
- (modified) llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp (+37-29) 
- (modified) llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp 
(+6-1) 
- (modified) llvm/lib/Transforms/InstCombine/InstructionCombining.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/Reassociate.cpp (+2-1) 
- (modified) llvm/test/Analysis/MemorySSA/nondeterminism.ll (-1) 
- (added) llvm/test/tools/llvm-diff/uselistorder-issue58629-gv.ll (+14) 
- (modified) llvm/test/tools/llvm-diff/uselistorder-issue58629.ll (+3-2) 
- (modified) llvm/test/tools/llvm-reduce/bitcode-uselistorder.ll (+12-11) 
- (modified) llvm/test/tools/llvm-reduce/uselistorder-invalid-ir-output.ll 
(+4-2) 
- (modified) llvm/tools/verify-uselistorder/verify-uselistorder.cpp (+9) 


``diff
diff --git a/llvm/include/llvm/IR/Use.h b/llvm/include/llvm/IR/Use.h
index a86b9c46c1f69..bcd1fd6677497 100644
--- a/llvm/include/llvm/IR/Use.h
+++ b/llvm/include/llvm/IR/Use.h
@@ -23,6 +23,7 @@
 namespace llvm {
 
 template  struct simplify_type;
+class ConstantData;
 class User;
 class Value;
 
@@ -42,10 +43,7 @@ class Use {
 
 private:
   /// Destructor - Only for zap()
-  ~Use() {
-if (Val)
-  removeFromList();
-  }
+  ~Use();
 
   /// Constructor
   Use(User *Parent) : Parent(Parent) {}
@@ -87,19 +85,10 @@ class Use {
   Use **Prev = nullptr;
   User *Parent = nullptr;
 
-  void addToList(Use **List) {
-Next = *List;
-if (Next)
-  Next->Prev = &Next;
-Prev = List;
-*Prev = this;
-  }
-
-  void removeFromList() {
-*Prev = Next;
-if (Next)
-  Next->Prev = Prev;
-  }
+  inline void addToList(unsigned &Count);
+  inline void addToList(Use *&List);
+  inline void removeFromList(unsigned &Count);
+  inline void removeFromList(Use *&List);
 };
 
 /// Allow clients to treat uses just like values when using
diff --git a/llvm/include/llvm/IR/Value.h b/llvm/include/llvm/IR/Value.h
index cfed12e2f5f8d..96e4cf446cb93 100644
--- a/llvm/include/llvm/IR/Value.h
+++ b/llvm/include/llvm/IR/Value.h
@@ -116,7 +116,10 @@ class Value {
 
 private:
   Type *VTy;
-  Use *UseList;
+  union {
+Use *List = nullptr;
+unsigned Count;
+  

[llvm-branch-commits] [llvm] IR: Remove uselist for constantdata (PR #134692)

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

llvmbot wrote:




@llvm/pr-subscribers-llvm-transforms

Author: Matt Arsenault (arsenm)


Changes

This is a resurrected version of the patch attached to this RFC:

https://discourse.llvm.org/t/rfc-constantdata-should-not-have-use-lists/42606

In this adaptation, there are a few differences. In the original patch, the 
Use's
use list was replaced with an unsigned* to the reference count in the value. 
This
version leaves them as null and leaves the ref counting only in Value.

Remove use-lists from instances of ConstantData (which are shared
across modules and have no operands).

To continue supporting most of the use-list API, store a ref-count in
place of the use-list; this is for API like Value::use_empty and
Value::hasNUses.  Operations that actually need the use-list -- like
Value::use_begin -- will assert.

This change has three benefits:

 1. The compiler output cannot in any way depend on the use-list order
of instances of ConstantData.

 2. There's no use-list traffic when adding and removing simple
constants from operand lists (although there is ref-count traffic;
YMMV).

 3. It's cheaper to serialize use-lists (since we're no longer
serializing the use-list order of things like i32 0).

The downside is that you can't look at all the users of ConstantData,
but traversals of users of i32 0 are already ill-advised.

Possible follow-ups:
  - Stop handling hasNUses checks for constants. The reference counts aren't 
really a useful replacement for these.
  - Track if an instance of a ConstantVector/ConstantArray/etc. is known
to have all ConstantData arguments, and drop the use-lists to
ref-counts in those cases.  Callers need to check Value::hasUseList
before iterating through the use-list.
  - Remove even the ref-counts.  I'm not sure they have any benefit
besides minimizing the scope of this commit, and maintaining the
counts is not free.

Fixes #58629

---

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


24 Files Affected:

- (modified) llvm/include/llvm/IR/Use.h (+6-17) 
- (modified) llvm/include/llvm/IR/Value.h (+94-24) 
- (modified) llvm/lib/Analysis/TypeMetadataUtils.cpp (+3) 
- (modified) llvm/lib/AsmParser/LLParser.cpp (+2) 
- (modified) llvm/lib/Bitcode/Reader/BitcodeReader.cpp (+4) 
- (modified) llvm/lib/Bitcode/Writer/ValueEnumerator.cpp (+3) 
- (modified) llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/CodeGenPrepare.cpp (+3) 
- (modified) llvm/lib/CodeGen/ComplexDeinterleavingPass.cpp (+3) 
- (modified) llvm/lib/IR/AsmWriter.cpp (+7-2) 
- (modified) llvm/lib/IR/Instruction.cpp (+3-1) 
- (modified) llvm/lib/IR/Use.cpp (+6-2) 
- (modified) llvm/lib/IR/Value.cpp (+18-8) 
- (modified) llvm/lib/Target/AArch64/GISel/AArch64RegisterBankInfo.cpp (+1-1) 
- (modified) llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp (+37-29) 
- (modified) llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp 
(+6-1) 
- (modified) llvm/lib/Transforms/InstCombine/InstructionCombining.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/Reassociate.cpp (+2-1) 
- (modified) llvm/test/Analysis/MemorySSA/nondeterminism.ll (-1) 
- (added) llvm/test/tools/llvm-diff/uselistorder-issue58629-gv.ll (+14) 
- (modified) llvm/test/tools/llvm-diff/uselistorder-issue58629.ll (+3-2) 
- (modified) llvm/test/tools/llvm-reduce/bitcode-uselistorder.ll (+12-11) 
- (modified) llvm/test/tools/llvm-reduce/uselistorder-invalid-ir-output.ll 
(+4-2) 
- (modified) llvm/tools/verify-uselistorder/verify-uselistorder.cpp (+9) 


``diff
diff --git a/llvm/include/llvm/IR/Use.h b/llvm/include/llvm/IR/Use.h
index a86b9c46c1f69..bcd1fd6677497 100644
--- a/llvm/include/llvm/IR/Use.h
+++ b/llvm/include/llvm/IR/Use.h
@@ -23,6 +23,7 @@
 namespace llvm {
 
 template  struct simplify_type;
+class ConstantData;
 class User;
 class Value;
 
@@ -42,10 +43,7 @@ class Use {
 
 private:
   /// Destructor - Only for zap()
-  ~Use() {
-if (Val)
-  removeFromList();
-  }
+  ~Use();
 
   /// Constructor
   Use(User *Parent) : Parent(Parent) {}
@@ -87,19 +85,10 @@ class Use {
   Use **Prev = nullptr;
   User *Parent = nullptr;
 
-  void addToList(Use **List) {
-Next = *List;
-if (Next)
-  Next->Prev = &Next;
-Prev = List;
-*Prev = this;
-  }
-
-  void removeFromList() {
-*Prev = Next;
-if (Next)
-  Next->Prev = Prev;
-  }
+  inline void addToList(unsigned &Count);
+  inline void addToList(Use *&List);
+  inline void removeFromList(unsigned &Count);
+  inline void removeFromList(Use *&List);
 };
 
 /// Allow clients to treat uses just like values when using
diff --git a/llvm/include/llvm/IR/Value.h b/llvm/include/llvm/IR/Value.h
index cfed12e2f5f8d..96e4cf446cb93 100644
--- a/llvm/include/llvm/IR/Value.h
+++ b/llvm/include/llvm/IR/Value.h
@@ -116,7 +116,10 @@ class Value {
 
 private:
   Type *VTy;
-  Use *UseList;
+  union {
+Use *List = nullptr;
+unsigned Count;
+

[llvm-branch-commits] [llvm] IR: Remove uselist for constantdata (PR #134692)

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

https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/134692

>From 21970c51d15b2a95a3cea384662139cee341ebbd Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Thu, 3 Apr 2025 17:30:01 +0700
Subject: [PATCH] IR: Remove uselist for constantdata

This is a resurrected version of the patch attached to this RFC:

https://discourse.llvm.org/t/rfc-constantdata-should-not-have-use-lists/42606

In this adaptation, there are a few differences. In the original patch, the 
Use's
use list was replaced with an unsigned* to the reference count in the value. 
This
version leaves them as null and leaves the ref counting only in Value.

Remove use-lists from instances of ConstantData (which are shared
across modules and have no operands).

To continue supporting most of the use-list API, store a ref-count in
place of the use-list; this is for API like Value::use_empty and
Value::hasNUses.  Operations that actually need the use-list -- like
Value::use_begin -- will assert.

This change has three benefits:

 1. The compiler output cannot in any way depend on the use-list order
of instances of ConstantData.

 2. There's no use-list traffic when adding and removing simple
constants from operand lists (although there is ref-count traffic;
YMMV).

 3. It's cheaper to serialize use-lists (since we're no longer
serializing the use-list order of things like i32 0).

The downside is that you can't look at all the users of ConstantData,
but traversals of users of i32 0 are already ill-advised.

Possible follow-ups:
  - Track if an instance of a ConstantVector/ConstantArray/etc. is known
to have all ConstantData arguments, and drop the use-lists to
ref-counts in those cases.  Callers need to check Value::hasUseList
before iterating through the use-list.
  - Remove even the ref-counts.  I'm not sure they have any benefit
besides minimizing the scope of this commit, and maintaining the
counts is not free.

Fixes #58629
---
 llvm/include/llvm/IR/Use.h|  23 +---
 llvm/include/llvm/IR/Value.h  | 118 ++
 llvm/lib/Analysis/TypeMetadataUtils.cpp   |   3 +
 llvm/lib/AsmParser/LLParser.cpp   |   2 +
 llvm/lib/Bitcode/Reader/BitcodeReader.cpp |   4 +
 llvm/lib/Bitcode/Writer/ValueEnumerator.cpp   |   3 +
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp|   2 +-
 llvm/lib/CodeGen/CodeGenPrepare.cpp   |   3 +
 .../lib/CodeGen/ComplexDeinterleavingPass.cpp |   3 +
 llvm/lib/IR/AsmWriter.cpp |   9 +-
 llvm/lib/IR/Instruction.cpp   |   4 +-
 llvm/lib/IR/Use.cpp   |   8 +-
 llvm/lib/IR/Value.cpp |  26 ++--
 .../AArch64/GISel/AArch64RegisterBankInfo.cpp |   2 +-
 llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp |  66 +-
 .../InstCombineSimplifyDemanded.cpp   |   7 +-
 .../InstCombine/InstructionCombining.cpp  |   2 +-
 llvm/lib/Transforms/Scalar/Reassociate.cpp|   3 +-
 .../test/Analysis/MemorySSA/nondeterminism.ll |   1 -
 .../llvm-diff/uselistorder-issue58629-gv.ll   |  14 +++
 .../llvm-diff/uselistorder-issue58629.ll  |   5 +-
 .../tools/llvm-reduce/bitcode-uselistorder.ll |  23 ++--
 .../uselistorder-invalid-ir-output.ll |   6 +-
 .../verify-uselistorder.cpp   |   9 ++
 24 files changed, 242 insertions(+), 104 deletions(-)
 create mode 100644 llvm/test/tools/llvm-diff/uselistorder-issue58629-gv.ll

diff --git a/llvm/include/llvm/IR/Use.h b/llvm/include/llvm/IR/Use.h
index a86b9c46c1f69..bcd1fd6677497 100644
--- a/llvm/include/llvm/IR/Use.h
+++ b/llvm/include/llvm/IR/Use.h
@@ -23,6 +23,7 @@
 namespace llvm {
 
 template  struct simplify_type;
+class ConstantData;
 class User;
 class Value;
 
@@ -42,10 +43,7 @@ class Use {
 
 private:
   /// Destructor - Only for zap()
-  ~Use() {
-if (Val)
-  removeFromList();
-  }
+  ~Use();
 
   /// Constructor
   Use(User *Parent) : Parent(Parent) {}
@@ -87,19 +85,10 @@ class Use {
   Use **Prev = nullptr;
   User *Parent = nullptr;
 
-  void addToList(Use **List) {
-Next = *List;
-if (Next)
-  Next->Prev = &Next;
-Prev = List;
-*Prev = this;
-  }
-
-  void removeFromList() {
-*Prev = Next;
-if (Next)
-  Next->Prev = Prev;
-  }
+  inline void addToList(unsigned &Count);
+  inline void addToList(Use *&List);
+  inline void removeFromList(unsigned &Count);
+  inline void removeFromList(Use *&List);
 };
 
 /// Allow clients to treat uses just like values when using
diff --git a/llvm/include/llvm/IR/Value.h b/llvm/include/llvm/IR/Value.h
index cfed12e2f5f8d..96e4cf446cb93 100644
--- a/llvm/include/llvm/IR/Value.h
+++ b/llvm/include/llvm/IR/Value.h
@@ -116,7 +116,10 @@ class Value {
 
 private:
   Type *VTy;
-  Use *UseList;
+  union {
+Use *List = nullptr;
+unsigned Count;
+  } Uses;
 
   friend class ValueAsMetadata; // Allow access to IsUsedByMD.
   friend class ValueHandleBase; // Allow access to Ha

[llvm-branch-commits] [llvm] SCEVExpander: Don't look at uses of constants (PR #134691)

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

https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/134691

>From 36377c351008594c2b05c4751a483c3c5565e68e Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Mon, 7 Apr 2025 21:56:00 +0700
Subject: [PATCH] SCEVExpander: Don't look at uses of constants

This could be more relaxed, and look for uses of globals in
the same function but no tests apparently depend on that.
---
 .../Utils/ScalarEvolutionExpander.cpp | 29 ++-
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp 
b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
index 41bf202230e22..e25ec6c3b2a58 100644
--- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
+++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
@@ -111,20 +111,23 @@ Value *SCEVExpander::ReuseOrCreateCast(Value *V, Type *Ty,
 
   Value *Ret = nullptr;
 
-  // Check to see if there is already a cast!
-  for (User *U : V->users()) {
-if (U->getType() != Ty)
-  continue;
-CastInst *CI = dyn_cast(U);
-if (!CI || CI->getOpcode() != Op)
-  continue;
+  if (!isa(V)) {
+// Check to see if there is already a cast!
+for (User *U : V->users()) {
+  if (U->getType() != Ty)
+continue;
+  CastInst *CI = dyn_cast(U);
+  if (!CI || CI->getOpcode() != Op)
+continue;
 
-// Found a suitable cast that is at IP or comes before IP. Use it. Note 
that
-// the cast must also properly dominate the Builder's insertion point.
-if (IP->getParent() == CI->getParent() && &*BIP != CI &&
-(&*IP == CI || CI->comesBefore(&*IP))) {
-  Ret = CI;
-  break;
+  // Found a suitable cast that is at IP or comes before IP. Use it. Note
+  // that the cast must also properly dominate the Builder's insertion
+  // point.
+  if (IP->getParent() == CI->getParent() && &*BIP != CI &&
+  (&*IP == CI || CI->comesBefore(&*IP))) {
+Ret = CI;
+break;
+  }
 }
   }
 

___
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] IR: Remove uselist for constantdata (PR #134692)

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

https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/134692

>From 21970c51d15b2a95a3cea384662139cee341ebbd Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Thu, 3 Apr 2025 17:30:01 +0700
Subject: [PATCH] IR: Remove uselist for constantdata

This is a resurrected version of the patch attached to this RFC:

https://discourse.llvm.org/t/rfc-constantdata-should-not-have-use-lists/42606

In this adaptation, there are a few differences. In the original patch, the 
Use's
use list was replaced with an unsigned* to the reference count in the value. 
This
version leaves them as null and leaves the ref counting only in Value.

Remove use-lists from instances of ConstantData (which are shared
across modules and have no operands).

To continue supporting most of the use-list API, store a ref-count in
place of the use-list; this is for API like Value::use_empty and
Value::hasNUses.  Operations that actually need the use-list -- like
Value::use_begin -- will assert.

This change has three benefits:

 1. The compiler output cannot in any way depend on the use-list order
of instances of ConstantData.

 2. There's no use-list traffic when adding and removing simple
constants from operand lists (although there is ref-count traffic;
YMMV).

 3. It's cheaper to serialize use-lists (since we're no longer
serializing the use-list order of things like i32 0).

The downside is that you can't look at all the users of ConstantData,
but traversals of users of i32 0 are already ill-advised.

Possible follow-ups:
  - Track if an instance of a ConstantVector/ConstantArray/etc. is known
to have all ConstantData arguments, and drop the use-lists to
ref-counts in those cases.  Callers need to check Value::hasUseList
before iterating through the use-list.
  - Remove even the ref-counts.  I'm not sure they have any benefit
besides minimizing the scope of this commit, and maintaining the
counts is not free.

Fixes #58629
---
 llvm/include/llvm/IR/Use.h|  23 +---
 llvm/include/llvm/IR/Value.h  | 118 ++
 llvm/lib/Analysis/TypeMetadataUtils.cpp   |   3 +
 llvm/lib/AsmParser/LLParser.cpp   |   2 +
 llvm/lib/Bitcode/Reader/BitcodeReader.cpp |   4 +
 llvm/lib/Bitcode/Writer/ValueEnumerator.cpp   |   3 +
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp|   2 +-
 llvm/lib/CodeGen/CodeGenPrepare.cpp   |   3 +
 .../lib/CodeGen/ComplexDeinterleavingPass.cpp |   3 +
 llvm/lib/IR/AsmWriter.cpp |   9 +-
 llvm/lib/IR/Instruction.cpp   |   4 +-
 llvm/lib/IR/Use.cpp   |   8 +-
 llvm/lib/IR/Value.cpp |  26 ++--
 .../AArch64/GISel/AArch64RegisterBankInfo.cpp |   2 +-
 llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp |  66 +-
 .../InstCombineSimplifyDemanded.cpp   |   7 +-
 .../InstCombine/InstructionCombining.cpp  |   2 +-
 llvm/lib/Transforms/Scalar/Reassociate.cpp|   3 +-
 .../test/Analysis/MemorySSA/nondeterminism.ll |   1 -
 .../llvm-diff/uselistorder-issue58629-gv.ll   |  14 +++
 .../llvm-diff/uselistorder-issue58629.ll  |   5 +-
 .../tools/llvm-reduce/bitcode-uselistorder.ll |  23 ++--
 .../uselistorder-invalid-ir-output.ll |   6 +-
 .../verify-uselistorder.cpp   |   9 ++
 24 files changed, 242 insertions(+), 104 deletions(-)
 create mode 100644 llvm/test/tools/llvm-diff/uselistorder-issue58629-gv.ll

diff --git a/llvm/include/llvm/IR/Use.h b/llvm/include/llvm/IR/Use.h
index a86b9c46c1f69..bcd1fd6677497 100644
--- a/llvm/include/llvm/IR/Use.h
+++ b/llvm/include/llvm/IR/Use.h
@@ -23,6 +23,7 @@
 namespace llvm {
 
 template  struct simplify_type;
+class ConstantData;
 class User;
 class Value;
 
@@ -42,10 +43,7 @@ class Use {
 
 private:
   /// Destructor - Only for zap()
-  ~Use() {
-if (Val)
-  removeFromList();
-  }
+  ~Use();
 
   /// Constructor
   Use(User *Parent) : Parent(Parent) {}
@@ -87,19 +85,10 @@ class Use {
   Use **Prev = nullptr;
   User *Parent = nullptr;
 
-  void addToList(Use **List) {
-Next = *List;
-if (Next)
-  Next->Prev = &Next;
-Prev = List;
-*Prev = this;
-  }
-
-  void removeFromList() {
-*Prev = Next;
-if (Next)
-  Next->Prev = Prev;
-  }
+  inline void addToList(unsigned &Count);
+  inline void addToList(Use *&List);
+  inline void removeFromList(unsigned &Count);
+  inline void removeFromList(Use *&List);
 };
 
 /// Allow clients to treat uses just like values when using
diff --git a/llvm/include/llvm/IR/Value.h b/llvm/include/llvm/IR/Value.h
index cfed12e2f5f8d..96e4cf446cb93 100644
--- a/llvm/include/llvm/IR/Value.h
+++ b/llvm/include/llvm/IR/Value.h
@@ -116,7 +116,10 @@ class Value {
 
 private:
   Type *VTy;
-  Use *UseList;
+  union {
+Use *List = nullptr;
+unsigned Count;
+  } Uses;
 
   friend class ValueAsMetadata; // Allow access to IsUsedByMD.
   friend class ValueHandleBase; // Allow access to Ha

[llvm-branch-commits] [llvm] IR: Remove uselist for constantdata (PR #134692)

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

https://github.com/arsenm ready_for_review 
https://github.com/llvm/llvm-project/pull/134692
___
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] IR: Remove uselist for constantdata (PR #134692)

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

https://github.com/arsenm edited 
https://github.com/llvm/llvm-project/pull/134692
___
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] IR: Remove uselist for constantdata (PR #134692)

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


@@ -889,10 +919,50 @@ inline raw_ostream &operator<<(raw_ostream &OS, const 
Value &V) {
   return OS;
 }
 
+inline Use::~Use() {
+  if (Val)
+Val->removeUse(*this);
+}
+
+void Use::addToList(unsigned &Count) {
+  assert(isa(Val) && "Only ConstantData is ref-counted");
+  ++Count;
+
+  // We don't have a uselist - clear the remnant if we are replacing a
+  // non-constant value.
+  Prev = nullptr;
+  Next = nullptr;

arsenm wrote:

I meant to revisit this. I think this was only a problem in cases where 
Use::swap was used between a register and a constant 

https://github.com/llvm/llvm-project/pull/134692
___
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] SimplifyLibCalls: Skip sincospi optimization for ConstantData (PR #134688)

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

arsenm wrote:

a24ef4b07ee798b14fe0f3daa23cc3ec09410bc6

https://github.com/llvm/llvm-project/pull/134688
___
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] SimplifyLibCalls: Skip sincospi optimization for ConstantData (PR #134688)

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

https://github.com/arsenm closed 
https://github.com/llvm/llvm-project/pull/134688
___
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] LICM: Avoid looking at use list of constant data (PR #134690)

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

https://github.com/arsenm closed 
https://github.com/llvm/llvm-project/pull/134690
___
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] LICM: Avoid looking at use list of constant data (PR #134690)

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

arsenm wrote:

393c783a10052b14d2b76b3ee930b3d83e7f1a16

https://github.com/llvm/llvm-project/pull/134690
___
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] IR: Remove uselist for constantdata (PR #134692)

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


@@ -437,7 +437,8 @@ static bool LinearizeExprTree(Instruction *I,
 for (unsigned OpIdx = 0; OpIdx < I->getNumOperands(); ++OpIdx) { // Visit 
operands.
   Value *Op = I->getOperand(OpIdx);
   LLVM_DEBUG(dbgs() << "OPERAND: " << *Op << " (" << Weight << ")\n");
-  assert(!Op->use_empty() && "No uses, so how did we get to it?!");
+  assert((isa(Op) || !Op->use_empty()) &&

arsenm wrote:

I've started thinking maybe it shouldn't. The hasN* use cases don't really mean 
anything useful given the references are context wide 

https://github.com/llvm/llvm-project/pull/134692
___
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] [X86] Backport saturate-convert intrinsics renaming & YMM rounding intrinsics removal in AVX10.2 (PR #135549)

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

llvmbot wrote:



@llvm/pr-subscribers-backend-x86

@llvm/pr-subscribers-clang

Author: Phoebe Wang (phoebewang)


Changes

AVX10.2 YMM rounding instructions are removed from latest AVX10 technical 
paper. Remove all intrinsics from compiler.

AVX10.2 saturate-convert intrinsics are modified to use "s_" in the name. It is 
a consensus made with GCC folks to avoid future ambiguity.

---

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


21 Files Affected:

- (modified) clang/lib/Headers/avx10_2_512convertintrin.h (+24-22) 
- (modified) clang/lib/Headers/avx10_2_512satcvtdsintrin.h (+28-24) 
- (modified) clang/lib/Headers/avx10_2_512satcvtintrin.h (+84-84) 
- (modified) clang/lib/Headers/avx10_2convertintrin.h (+50-62) 
- (modified) clang/lib/Headers/avx10_2minmaxintrin.h (-45) 
- (modified) clang/lib/Headers/avx10_2niintrin.h (-1666) 
- (modified) clang/lib/Headers/avx10_2satcvtdsintrin.h (+52-158) 
- (modified) clang/lib/Headers/avx10_2satcvtintrin.h (+88-200) 
- (modified) clang/test/CodeGen/X86/avx10_2_512convert-builtins.c (+54-54) 
- (modified) clang/test/CodeGen/X86/avx10_2_512minmax-error.c (-11) 
- (removed) clang/test/CodeGen/X86/avx10_2_512satcvt-builtins-error.c (-198) 
- (modified) clang/test/CodeGen/X86/avx10_2_512satcvt-builtins.c (+180-180) 
- (modified) clang/test/CodeGen/X86/avx10_2_512satcvtds-builtins-x64.c (+48-48) 
- (modified) clang/test/CodeGen/X86/avx10_2_512satcvtds-builtins.c (+37-37) 
- (modified) clang/test/CodeGen/X86/avx10_2convert-builtins.c (+108-126) 
- (modified) clang/test/CodeGen/X86/avx10_2minmax-builtins.c (-54) 
- (modified) clang/test/CodeGen/X86/avx10_2ni-builtins.c (-2405) 
- (modified) clang/test/CodeGen/X86/avx10_2satcvt-builtins.c (+216-358) 
- (removed) clang/test/CodeGen/X86/avx10_2satcvtds-builtins-errors.c (-57) 
- (modified) clang/test/CodeGen/X86/avx10_2satcvtds-builtins-x64.c (+84-156) 
- (modified) clang/test/CodeGen/X86/avx10_2satcvtds-builtins.c (+74-149) 


``diff
diff --git a/clang/lib/Headers/avx10_2_512convertintrin.h 
b/clang/lib/Headers/avx10_2_512convertintrin.h
index 516ccc68672d6..ee8cbf28ca41c 100644
--- a/clang/lib/Headers/avx10_2_512convertintrin.h
+++ b/clang/lib/Headers/avx10_2_512convertintrin.h
@@ -78,20 +78,20 @@ _mm512_maskz_cvtbiasph_bf8(__mmask32 __U, __m512i __A, 
__m512h __B) {
 }
 
 static __inline__ __m256i __DEFAULT_FN_ATTRS512
-_mm512_cvtbiassph_bf8(__m512i __A, __m512h __B) {
+_mm512_cvts_biasph_bf8(__m512i __A, __m512h __B) {
   return (__m256i)__builtin_ia32_vcvtbiasph2bf8s_512_mask(
   (__v64qi)__A, (__v32hf)__B, (__v32qi)_mm256_undefined_si256(),
   (__mmask32)-1);
 }
 
-static __inline__ __m256i __DEFAULT_FN_ATTRS512 _mm512_mask_cvtbiassph_bf8(
+static __inline__ __m256i __DEFAULT_FN_ATTRS512 _mm512_mask_cvts_biasph_bf8(
 __m256i __W, __mmask32 __U, __m512i __A, __m512h __B) {
   return (__m256i)__builtin_ia32_vcvtbiasph2bf8s_512_mask(
   (__v64qi)__A, (__v32hf)__B, (__v32qi)(__m256i)__W, (__mmask32)__U);
 }
 
 static __inline__ __m256i __DEFAULT_FN_ATTRS512
-_mm512_maskz_cvtbiassph_bf8(__mmask32 __U, __m512i __A, __m512h __B) {
+_mm512_maskz_cvts_biasph_bf8(__mmask32 __U, __m512i __A, __m512h __B) {
   return (__m256i)__builtin_ia32_vcvtbiasph2bf8s_512_mask(
   (__v64qi)__A, (__v32hf)__B, (__v32qi)(__m256i)_mm256_setzero_si256(),
   (__mmask32)__U);
@@ -118,20 +118,20 @@ _mm512_maskz_cvtbiasph_hf8(__mmask32 __U, __m512i __A, 
__m512h __B) {
 }
 
 static __inline__ __m256i __DEFAULT_FN_ATTRS512
-_mm512_cvtbiassph_hf8(__m512i __A, __m512h __B) {
+_mm512_cvts_biasph_hf8(__m512i __A, __m512h __B) {
   return (__m256i)__builtin_ia32_vcvtbiasph2hf8s_512_mask(
   (__v64qi)__A, (__v32hf)__B, (__v32qi)_mm256_undefined_si256(),
   (__mmask32)-1);
 }
 
-static __inline__ __m256i __DEFAULT_FN_ATTRS512 _mm512_mask_cvtbiassph_hf8(
+static __inline__ __m256i __DEFAULT_FN_ATTRS512 _mm512_mask_cvts_biasph_hf8(
 __m256i __W, __mmask32 __U, __m512i __A, __m512h __B) {
   return (__m256i)__builtin_ia32_vcvtbiasph2hf8s_512_mask(
   (__v64qi)__A, (__v32hf)__B, (__v32qi)(__m256i)__W, (__mmask32)__U);
 }
 
 static __inline__ __m256i __DEFAULT_FN_ATTRS512
-_mm512_maskz_cvtbiassph_hf8(__mmask32 __U, __m512i __A, __m512h __B) {
+_mm512_maskz_cvts_biasph_hf8(__mmask32 __U, __m512i __A, __m512h __B) {
   return (__m256i)__builtin_ia32_vcvtbiasph2hf8s_512_mask(
   (__v64qi)__A, (__v32hf)__B, (__v32qi)(__m256i)_mm256_setzero_si256(),
   (__mmask32)__U);
@@ -157,21 +157,21 @@ _mm512_maskz_cvt2ph_bf8(__mmask64 __U, __m512h __A, 
__m512h __B) {
 }
 
 static __inline__ __m512i __DEFAULT_FN_ATTRS512
-_mm512_cvts2ph_bf8(__m512h __A, __m512h __B) {
+_mm512_cvts_2ph_bf8(__m512h __A, __m512h __B) {
   return (__m512i)__builtin_ia32_vcvt2ph2bf8s_512((__v32hf)(__A),
   (__v32hf)(__B));
 }
 
 static __inline__ __m512i __DEFAULT_FN_ATTRS512
-_mm512_mask_cvts2ph_bf8(__m512i __W, __mmask64 __

[llvm-branch-commits] [clang] [llvm] [X86] Backport new intrinsic and instruction changes in AVX10.2 (PR #133219)

2025-04-13 Thread Phoebe Wang via llvm-branch-commits

phoebewang wrote:

> > > Doesn't this break ABI by changing intrinsic / builtin numbers?
> > 
> > 
> > So the headers could still be updated but must use the existing builtins in 
> > the backport?
> 
> Sounds good, I can try with it. Thanks!

A reduced one for intrinsics only 
https://github.com/llvm/llvm-project/pull/135549, PTAL.

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


[llvm-branch-commits] [clang] [llvm] [X86] Backport new intrinsic and instruction changes in AVX10.2 (PR #133219)

2025-04-13 Thread Phoebe Wang via llvm-branch-commits

https://github.com/phoebewang closed 
https://github.com/llvm/llvm-project/pull/133219
___
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] PHITransAddr: Avoid looking at constant use lists (PR #134689)

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

https://github.com/arsenm closed 
https://github.com/llvm/llvm-project/pull/134689
___
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] PHITransAddr: Avoid looking at constant use lists (PR #134689)

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

arsenm wrote:

b37476f99c37a9edf48684d82dde745d9e0df957

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


[llvm-branch-commits] [llvm] [LV] An attempt to cherry-pick the fix PR #132691 (cherry-pick from the main branch to the release/20.x branch) (PR #135231)

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

https://github.com/nikic milestoned 
https://github.com/llvm/llvm-project/pull/135231
___
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] [X86] Backport saturate-convert intrinsics renaming & YMM rounding intrinsics removal in AVX10.2 (PR #135549)

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

https://github.com/nikic milestoned 
https://github.com/llvm/llvm-project/pull/135549
___
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] SCEVExpander: Don't look at uses of constants (PR #134691)

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

arsenm wrote:

30ae47eeefaeb2c78ae7f234621b8bb0444b7844

https://github.com/llvm/llvm-project/pull/134691
___
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] SCEVExpander: Don't look at uses of constants (PR #134691)

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

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


[llvm-branch-commits] [llvm] [LV] An attempt to cherry-pick the fix PR #132691 (cherry-pick from the main branch to the release/20.x branch) (PR #135231)

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

https://github.com/nikic requested changes to this pull request.

Breaks LoopUtils.h ABI in obvious ways and FMF.h ABI in less obvious ways.

Can this be fixed in a more minimal way than backporting 18 commits that 
include a lot of refactorings?

https://github.com/llvm/llvm-project/pull/135231
___
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: [modules] Handle friend function that was a definition but became only a declaration during AST deserialization (#132214) (PR #134232)

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

https://github.com/nikic requested changes to this pull request.


https://github.com/llvm/llvm-project/pull/134232
___
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: [modules] Handle friend function that was a definition but became only a declaration during AST deserialization (#132214) (PR #134232)

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


@@ -1392,6 +1392,10 @@ class ASTReader
 
   llvm::DenseMap DefinitionSource;
 
+  /// Friend functions that were defined but might have had their bodies
+  /// removed.
+  llvm::DenseSet ThisDeclarationWasADefinitionSet;

nikic wrote:

This is an ABI break.

https://github.com/llvm/llvm-project/pull/134232
___
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: [modules] Handle friend function that was a definition but became only a declaration during AST deserialization (#132214) (PR #134232)

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

https://github.com/nikic milestoned 
https://github.com/llvm/llvm-project/pull/134232
___
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: [modules] Handle friend function that was a definition but became only a declaration during AST deserialization (#132214) (PR #134232)

2025-04-13 Thread Dmitry Polukhin via llvm-branch-commits

dmpolukhin wrote:

@nikic what do you mean by ABI change in this case? It doesn't change ABI of 
generated code, moreover it doesn't even change PCM serialized format because 
it is in memory only filed and attribute.

https://github.com/llvm/llvm-project/pull/134232
___
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: [modules] Handle friend function that was a definition but became only a declaration during AST deserialization (#132214) (PR #134232)

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

nikic wrote:

> @nikic what do you mean by ABI change in this case? It doesn't change ABI of 
> generated code, moreover it doesn't even change PCM serialized format because 
> it is in memory only filed and attribute.

It changes the ABI of libclang-cpp, by changing the layout of an exported type.

https://github.com/llvm/llvm-project/pull/134232
___
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] RISCVAsmParser: Reject call foo@invalid (PR #135509)

2025-04-13 Thread Sudharsan Veeravalli via llvm-branch-commits

svs-quic wrote:

I had pushed #135324 a couple of days ago to fix the same issue. I'm happy to 
land either patch.

https://github.com/llvm/llvm-project/pull/135509
___
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] [Github]CI] Upload .ninja_log as an artifact (PR #135539)

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

https://github.com/boomanaiden154 updated 
https://github.com/llvm/llvm-project/pull/135539

>From 109923e35d854d63faa5b9599f5fd128bcfe5c79 Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Sun, 13 Apr 2025 11:26:06 +
Subject: [PATCH] testing

Created using spr 1.3.4
---
 .ci/monolithic-linux.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.ci/monolithic-linux.sh b/.ci/monolithic-linux.sh
index 6461c9d40ad59..8c1ad5d80da51 100755
--- a/.ci/monolithic-linux.sh
+++ b/.ci/monolithic-linux.sh
@@ -34,6 +34,7 @@ function at-exit {
   mkdir -p artifacts
   ccache --print-stats > artifacts/ccache_stats.txt
   cp "${BUILD_DIR}"/.ninja_log artifacts/.ninja_log
+  ls artifacts/
 
   # If building fails there will be no results files.
   shopt -s nullglob

___
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] [Github]CI] Upload .ninja_log as an artifact (PR #135539)

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

https://github.com/boomanaiden154 updated 
https://github.com/llvm/llvm-project/pull/135539

>From 109923e35d854d63faa5b9599f5fd128bcfe5c79 Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Sun, 13 Apr 2025 11:26:06 +
Subject: [PATCH] testing

Created using spr 1.3.4
---
 .ci/monolithic-linux.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.ci/monolithic-linux.sh b/.ci/monolithic-linux.sh
index 6461c9d40ad59..8c1ad5d80da51 100755
--- a/.ci/monolithic-linux.sh
+++ b/.ci/monolithic-linux.sh
@@ -34,6 +34,7 @@ function at-exit {
   mkdir -p artifacts
   ccache --print-stats > artifacts/ccache_stats.txt
   cp "${BUILD_DIR}"/.ninja_log artifacts/.ninja_log
+  ls artifacts/
 
   # If building fails there will be no results files.
   shopt -s nullglob

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [flang] [llvm] [Github][CI] Upload .ninja_log as an artifact (PR #135539)

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

https://github.com/boomanaiden154 updated 
https://github.com/llvm/llvm-project/pull/135539

>From 109923e35d854d63faa5b9599f5fd128bcfe5c79 Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Sun, 13 Apr 2025 11:26:06 +
Subject: [PATCH 1/2] testing

Created using spr 1.3.4
---
 .ci/monolithic-linux.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.ci/monolithic-linux.sh b/.ci/monolithic-linux.sh
index 6461c9d40ad59..8c1ad5d80da51 100755
--- a/.ci/monolithic-linux.sh
+++ b/.ci/monolithic-linux.sh
@@ -34,6 +34,7 @@ function at-exit {
   mkdir -p artifacts
   ccache --print-stats > artifacts/ccache_stats.txt
   cp "${BUILD_DIR}"/.ninja_log artifacts/.ninja_log
+  ls artifacts/
 
   # If building fails there will be no results files.
   shopt -s nullglob

>From 78c42b3aed24e533d53b2f701f5a0abd5f611e2a Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Sun, 13 Apr 2025 11:43:16 +
Subject: [PATCH 2/2] cleanup

Created using spr 1.3.4
---
 flang/CMakeLists.txt | 1 -
 1 file changed, 1 deletion(-)

diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index 236b4644404ec..76eb13295eb07 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -1,4 +1,3 @@
-# testing
 cmake_minimum_required(VERSION 3.20.0)
 set(LLVM_SUBPROJECT_TITLE "Flang")
 

___
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] [Github][CI] Upload .ninja_log as an artifact (PR #135539)

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

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


[llvm-branch-commits] [llvm] release/20.x: [SCEV] Use ashr to adjust constant multipliers (#135534) (PR #135543)

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

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

Backport bb9580a02b393683ff0b6c360df684f33c715a1f

Requested by: @dtcxzyw

>From aa784fdf7baffcff8ae1c4f5c353632828aa00a4 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Sun, 13 Apr 2025 20:22:48 +0800
Subject: [PATCH] [SCEV] Use ashr to adjust constant multipliers (#135534)

SCEV converts "-2 *nsw (i32 V)" into "2148473647 *nsw (i32 V)". But we
cannot preserve the nsw flag when the constant multiplier is negative.
This patch changes lshr to ashr so that we can preserve both nsw and nuw
flags.

Alive2 proof: https://alive2.llvm.org/ce/z/LZVSEa
Closes https://github.com/llvm/llvm-project/issues/135531.

(cherry picked from commit bb9580a02b393683ff0b6c360df684f33c715a1f)
---
 llvm/lib/Analysis/ScalarEvolution.cpp |  2 +-
 .../test/Analysis/ScalarEvolution/pr135531.ll | 19 +++
 2 files changed, 20 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/Analysis/ScalarEvolution/pr135531.ll

diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp 
b/llvm/lib/Analysis/ScalarEvolution.cpp
index b8069df4e6598..36fe036aa9e9f 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -7854,7 +7854,7 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) {
   unsigned GCD = std::min(MulZeros, TZ);
   APInt DivAmt = APInt::getOneBitSet(BitWidth, TZ - GCD);
   SmallVector MulOps;
-  MulOps.push_back(getConstant(OpC->getAPInt().lshr(GCD)));
+  MulOps.push_back(getConstant(OpC->getAPInt().ashr(GCD)));
   append_range(MulOps, LHSMul->operands().drop_front());
   auto *NewMul = getMulExpr(MulOps, LHSMul->getNoWrapFlags());
   ShiftedLHS = getUDivExpr(NewMul, getConstant(DivAmt));
diff --git a/llvm/test/Analysis/ScalarEvolution/pr135531.ll 
b/llvm/test/Analysis/ScalarEvolution/pr135531.ll
new file mode 100644
index 0..e172d56d3a515
--- /dev/null
+++ b/llvm/test/Analysis/ScalarEvolution/pr135531.ll
@@ -0,0 +1,19 @@
+; NOTE: Assertions have been autogenerated by 
utils/update_analyze_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -disable-output -passes='print' < %s 2>&1 | 
FileCheck %s
+
+define i32 @pr135511(i32 %x) {
+; CHECK-LABEL: 'pr135511'
+; CHECK-NEXT:  Classifying expressions for: @pr135511
+; CHECK-NEXT:%and = and i32 %x, 16382
+; CHECK-NEXT:--> (2 * (zext i13 (trunc i32 (%x /u 2) to i13) to 
i32)) U: [0,16383) S: [0,16383)
+; CHECK-NEXT:%neg = sub nsw i32 0, %and
+; CHECK-NEXT:--> (-2 * (zext i13 (trunc i32 (%x /u 2) to i13) to 
i32)) U: [0,-1) S: [-16382,1)
+; CHECK-NEXT:%res = and i32 %neg, 268431360
+; CHECK-NEXT:--> (4096 * (zext i16 (trunc i32 ((-1 * (zext i13 (trunc i32 
(%x /u 2) to i13) to i32)) /u 2048) to i16) to i32)) U: 
[0,268431361) S: [0,268431361)
+; CHECK-NEXT:  Determining loop execution counts for: @pr135511
+;
+  %and = and i32 %x, 16382
+  %neg = sub nsw i32 0, %and
+  %res = and i32 %neg, 268431360
+  ret i32 %res
+}

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/20.x: [SCEV] Use ashr to adjust constant multipliers (#135534) (PR #135543)

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

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


[llvm-branch-commits] [llvm] release/20.x: [SCEV] Use ashr to adjust constant multipliers (#135534) (PR #135543)

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

llvmbot wrote:

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

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


[llvm-branch-commits] [llvm] release/20.x: [SCEV] Use ashr to adjust constant multipliers (#135534) (PR #135543)

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

llvmbot wrote:




@llvm/pr-subscribers-llvm-analysis

Author: None (llvmbot)


Changes

Backport bb9580a02b393683ff0b6c360df684f33c715a1f

Requested by: @dtcxzyw

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


2 Files Affected:

- (modified) llvm/lib/Analysis/ScalarEvolution.cpp (+1-1) 
- (added) llvm/test/Analysis/ScalarEvolution/pr135531.ll (+19) 


``diff
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp 
b/llvm/lib/Analysis/ScalarEvolution.cpp
index b8069df4e6598..36fe036aa9e9f 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -7854,7 +7854,7 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) {
   unsigned GCD = std::min(MulZeros, TZ);
   APInt DivAmt = APInt::getOneBitSet(BitWidth, TZ - GCD);
   SmallVector MulOps;
-  MulOps.push_back(getConstant(OpC->getAPInt().lshr(GCD)));
+  MulOps.push_back(getConstant(OpC->getAPInt().ashr(GCD)));
   append_range(MulOps, LHSMul->operands().drop_front());
   auto *NewMul = getMulExpr(MulOps, LHSMul->getNoWrapFlags());
   ShiftedLHS = getUDivExpr(NewMul, getConstant(DivAmt));
diff --git a/llvm/test/Analysis/ScalarEvolution/pr135531.ll 
b/llvm/test/Analysis/ScalarEvolution/pr135531.ll
new file mode 100644
index 0..e172d56d3a515
--- /dev/null
+++ b/llvm/test/Analysis/ScalarEvolution/pr135531.ll
@@ -0,0 +1,19 @@
+; NOTE: Assertions have been autogenerated by 
utils/update_analyze_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -disable-output -passes='print' < %s 2>&1 | 
FileCheck %s
+
+define i32 @pr135511(i32 %x) {
+; CHECK-LABEL: 'pr135511'
+; CHECK-NEXT:  Classifying expressions for: @pr135511
+; CHECK-NEXT:%and = and i32 %x, 16382
+; CHECK-NEXT:--> (2 * (zext i13 (trunc i32 (%x /u 2) to i13) to 
i32)) U: [0,16383) S: [0,16383)
+; CHECK-NEXT:%neg = sub nsw i32 0, %and
+; CHECK-NEXT:--> (-2 * (zext i13 (trunc i32 (%x /u 2) to i13) to 
i32)) U: [0,-1) S: [-16382,1)
+; CHECK-NEXT:%res = and i32 %neg, 268431360
+; CHECK-NEXT:--> (4096 * (zext i16 (trunc i32 ((-1 * (zext i13 (trunc i32 
(%x /u 2) to i13) to i32)) /u 2048) to i16) to i32)) U: 
[0,268431361) S: [0,268431361)
+; CHECK-NEXT:  Determining loop execution counts for: @pr135511
+;
+  %and = and i32 %x, 16382
+  %neg = sub nsw i32 0, %and
+  %res = and i32 %neg, 268431360
+  ret i32 %res
+}

``




https://github.com/llvm/llvm-project/pull/135543
___
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] [Github]CI] Upload .ninja_log as an artifact (PR #135539)

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

https://github.com/boomanaiden154 updated 
https://github.com/llvm/llvm-project/pull/135539

>From 109923e35d854d63faa5b9599f5fd128bcfe5c79 Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Sun, 13 Apr 2025 11:26:06 +
Subject: [PATCH] testing

Created using spr 1.3.4
---
 .ci/monolithic-linux.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.ci/monolithic-linux.sh b/.ci/monolithic-linux.sh
index 6461c9d40ad59..8c1ad5d80da51 100755
--- a/.ci/monolithic-linux.sh
+++ b/.ci/monolithic-linux.sh
@@ -34,6 +34,7 @@ function at-exit {
   mkdir -p artifacts
   ccache --print-stats > artifacts/ccache_stats.txt
   cp "${BUILD_DIR}"/.ninja_log artifacts/.ninja_log
+  ls artifacts/
 
   # If building fails there will be no results files.
   shopt -s nullglob

___
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] IR: Remove uselist for constantdata (PR #134692)

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

https://github.com/nikic commented:

Compile-time: 
https://llvm-compile-time-tracker.com/compare.php?from=09588e93bbe486ce782de9fba604f5cd184ec446&to=54260021fd4ffa41b5f20994af7b34653b4d4d42&stat=instructions%3Au
 It's possible that the wall-time picture may be different due to slightly less 
memory traffic, but I suspect the overhead of having two different code paths 
in a lot of common operations dominates.

This does make me wonder though if we wouldn't be better off keeping the actual 
use lists and just asserting that they aren't accessed (and excluding them from 
uselistorder, as they cannot matter). Given that we still have to keep the 
Next/Prev pointers in Use, we're not really gaining much from dropping the list.

https://github.com/llvm/llvm-project/pull/134692
___
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] Store GUIDs in metadata (PR #133682)

2025-04-13 Thread Owen Rodley via llvm-branch-commits

https://github.com/orodley updated 
https://github.com/llvm/llvm-project/pull/133682

>From 67d512e2d2055c73d3e6121d3972b23932342d5d Mon Sep 17 00:00:00 2001
From: Owen Rodley 
Date: Mon, 31 Mar 2025 16:16:35 +1100
Subject: [PATCH] Store GUIDs in metadata

See https://discourse.llvm.org/t/rfc-keep-globalvalue-guids-stable/84801
for context.

This takes the existing AssignGUID pass from CtxProfAnalysis, and runs
it by default, at the appropriate stages of the LTO pipeline. It also
changes GlobalValue::getGUID() to retrieve the GUID from the metadata
instead of computing it.

We don't yet have the supporting downstream changes to make a dedicated
GUID table in bitcode, nor do we use the metadata as part of ThinLTO --
it retains its existing mechanisms of recomputing GUIDs from separately
saved data. That will be changed later.
---
 llvm/include/llvm/Analysis/CtxProfAnalysis.h  | 38 -
 llvm/include/llvm/IR/FixedMetadataKinds.def   |  1 +
 llvm/include/llvm/IR/GlobalValue.h|  6 +--
 .../llvm/Transforms/Utils/AssignGUID.h| 34 +++
 llvm/lib/Analysis/CtxProfAnalysis.cpp | 42 ++-
 llvm/lib/IR/Globals.cpp   | 34 +++
 llvm/lib/Passes/PassBuilder.cpp   |  1 +
 llvm/lib/Passes/PassBuilderPipelines.cpp  |  9 +++-
 .../Instrumentation/PGOCtxProfFlattening.cpp  |  2 +-
 .../Instrumentation/PGOCtxProfLowering.cpp|  3 +-
 llvm/lib/Transforms/Utils/AssignGUID.cpp  | 34 +++
 llvm/lib/Transforms/Utils/CMakeLists.txt  |  1 +
 .../Transforms/Utils/CallPromotionUtils.cpp   |  5 +--
 llvm/lib/Transforms/Utils/InlineFunction.cpp  |  4 +-
 14 files changed, 131 insertions(+), 83 deletions(-)
 create mode 100644 llvm/include/llvm/Transforms/Utils/AssignGUID.h
 create mode 100644 llvm/lib/Transforms/Utils/AssignGUID.cpp

diff --git a/llvm/include/llvm/Analysis/CtxProfAnalysis.h 
b/llvm/include/llvm/Analysis/CtxProfAnalysis.h
index 6f1c3696ca78c..2ca21fc154f9a 100644
--- a/llvm/include/llvm/Analysis/CtxProfAnalysis.h
+++ b/llvm/include/llvm/Analysis/CtxProfAnalysis.h
@@ -46,9 +46,6 @@ class PGOContextualProfile {
   // we'll need when we maintain the profiles during IPO transformations.
   std::map FuncInfo;
 
-  /// Get the GUID of this Function if it's defined in this module.
-  GlobalValue::GUID getDefinedFunctionGUID(const Function &F) const;
-
   // This is meant to be constructed from CtxProfAnalysis, which will also set
   // its state piecemeal.
   PGOContextualProfile() = default;
@@ -67,9 +64,9 @@ class PGOContextualProfile {
 
   bool isInSpecializedModule() const;
 
-  bool isFunctionKnown(const Function &F) const {
-return getDefinedFunctionGUID(F) != 0;
-  }
+  bool isInSpecializedModule() const;
+
+  bool isFunctionKnown(const Function &F) const { return F.getGUID() != 0; }
 
   StringRef getFunctionName(GlobalValue::GUID GUID) const {
 auto It = FuncInfo.find(GUID);
@@ -80,22 +77,22 @@ class PGOContextualProfile {
 
   uint32_t getNumCounters(const Function &F) const {
 assert(isFunctionKnown(F));
-return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCounterIndex;
+return FuncInfo.find(F.getGUID())->second.NextCounterIndex;
   }
 
   uint32_t getNumCallsites(const Function &F) const {
 assert(isFunctionKnown(F));
-return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCallsiteIndex;
+return FuncInfo.find(F.getGUID())->second.NextCallsiteIndex;
   }
 
   uint32_t allocateNextCounterIndex(const Function &F) {
 assert(isFunctionKnown(F));
-return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCounterIndex++;
+return FuncInfo.find(F.getGUID())->second.NextCounterIndex++;
   }
 
   uint32_t allocateNextCallsiteIndex(const Function &F) {
 assert(isFunctionKnown(F));
-return 
FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCallsiteIndex++;
+return FuncInfo.find(F.getGUID())->second.NextCallsiteIndex++;
   }
 
   using ConstVisitor = function_ref;
@@ -157,26 +154,5 @@ class CtxProfAnalysisPrinterPass
   const PrintMode Mode;
 };
 
-/// Assign a GUID to functions as metadata. GUID calculation takes linkage into
-/// account, which may change especially through and after thinlto. By
-/// pre-computing and assigning as metadata, this mechanism is resilient to 
such
-/// changes (as well as name changes e.g. suffix ".llvm." additions).
-
-// FIXME(mtrofin): we can generalize this mechanism to calculate a GUID early 
in
-// the pass pipeline, associate it with any Global Value, and then use it for
-// PGO and ThinLTO.
-// At that point, this should be moved elsewhere.
-class AssignGUIDPass : public PassInfoMixin {
-public:
-  explicit AssignGUIDPass() = default;
-
-  /// Assign a GUID *if* one is not already assign, as a function metadata 
named
-  /// `GUIDMetadataName`.
-  PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
-  static const char *GUIDMetadataName;
-  // This should become GlobalValue:

[llvm-branch-commits] [llvm] Store GUIDs in metadata (PR #133682)

2025-04-13 Thread Owen Rodley via llvm-branch-commits

https://github.com/orodley updated 
https://github.com/llvm/llvm-project/pull/133682

>From 9d34fae78840876402a1b049d345b73285ffe4e5 Mon Sep 17 00:00:00 2001
From: Owen Rodley 
Date: Mon, 31 Mar 2025 16:16:35 +1100
Subject: [PATCH] Store GUIDs in metadata

This takes the existing AssignGUID pass from CtxProfAnalysis, and runs
it by default, at the appropriate stages of the LTO pipeline. It also
changes GlobalValue::getGUID() to retrieve the GUID from the metadata
instead of computing it.

We don't yet have the supporting downstream changes to make a dedicated
GUID table in bitcode, nor do we use the metadata as part of ThinLTO --
it retains its existing mechanisms of recomputing GUIDs from separately
saved data. That will be changed later.
---
 llvm/include/llvm/Analysis/CtxProfAnalysis.h  | 38 -
 llvm/include/llvm/IR/FixedMetadataKinds.def   |  1 +
 llvm/include/llvm/IR/GlobalValue.h|  6 +--
 .../llvm/Transforms/Utils/AssignGUID.h| 34 +++
 llvm/lib/Analysis/CtxProfAnalysis.cpp | 42 ++-
 llvm/lib/IR/Globals.cpp   | 34 +++
 llvm/lib/Passes/PassBuilder.cpp   |  1 +
 llvm/lib/Passes/PassBuilderPipelines.cpp  |  9 +++-
 .../Instrumentation/PGOCtxProfFlattening.cpp  |  2 +-
 .../Instrumentation/PGOCtxProfLowering.cpp|  3 +-
 llvm/lib/Transforms/Utils/AssignGUID.cpp  | 34 +++
 llvm/lib/Transforms/Utils/CMakeLists.txt  |  1 +
 .../Transforms/Utils/CallPromotionUtils.cpp   |  5 +--
 llvm/lib/Transforms/Utils/InlineFunction.cpp  |  4 +-
 14 files changed, 131 insertions(+), 83 deletions(-)
 create mode 100644 llvm/include/llvm/Transforms/Utils/AssignGUID.h
 create mode 100644 llvm/lib/Transforms/Utils/AssignGUID.cpp

diff --git a/llvm/include/llvm/Analysis/CtxProfAnalysis.h 
b/llvm/include/llvm/Analysis/CtxProfAnalysis.h
index 6f1c3696ca78c..2ca21fc154f9a 100644
--- a/llvm/include/llvm/Analysis/CtxProfAnalysis.h
+++ b/llvm/include/llvm/Analysis/CtxProfAnalysis.h
@@ -46,9 +46,6 @@ class PGOContextualProfile {
   // we'll need when we maintain the profiles during IPO transformations.
   std::map FuncInfo;
 
-  /// Get the GUID of this Function if it's defined in this module.
-  GlobalValue::GUID getDefinedFunctionGUID(const Function &F) const;
-
   // This is meant to be constructed from CtxProfAnalysis, which will also set
   // its state piecemeal.
   PGOContextualProfile() = default;
@@ -67,9 +64,9 @@ class PGOContextualProfile {
 
   bool isInSpecializedModule() const;
 
-  bool isFunctionKnown(const Function &F) const {
-return getDefinedFunctionGUID(F) != 0;
-  }
+  bool isInSpecializedModule() const;
+
+  bool isFunctionKnown(const Function &F) const { return F.getGUID() != 0; }
 
   StringRef getFunctionName(GlobalValue::GUID GUID) const {
 auto It = FuncInfo.find(GUID);
@@ -80,22 +77,22 @@ class PGOContextualProfile {
 
   uint32_t getNumCounters(const Function &F) const {
 assert(isFunctionKnown(F));
-return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCounterIndex;
+return FuncInfo.find(F.getGUID())->second.NextCounterIndex;
   }
 
   uint32_t getNumCallsites(const Function &F) const {
 assert(isFunctionKnown(F));
-return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCallsiteIndex;
+return FuncInfo.find(F.getGUID())->second.NextCallsiteIndex;
   }
 
   uint32_t allocateNextCounterIndex(const Function &F) {
 assert(isFunctionKnown(F));
-return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCounterIndex++;
+return FuncInfo.find(F.getGUID())->second.NextCounterIndex++;
   }
 
   uint32_t allocateNextCallsiteIndex(const Function &F) {
 assert(isFunctionKnown(F));
-return 
FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCallsiteIndex++;
+return FuncInfo.find(F.getGUID())->second.NextCallsiteIndex++;
   }
 
   using ConstVisitor = function_ref;
@@ -157,26 +154,5 @@ class CtxProfAnalysisPrinterPass
   const PrintMode Mode;
 };
 
-/// Assign a GUID to functions as metadata. GUID calculation takes linkage into
-/// account, which may change especially through and after thinlto. By
-/// pre-computing and assigning as metadata, this mechanism is resilient to 
such
-/// changes (as well as name changes e.g. suffix ".llvm." additions).
-
-// FIXME(mtrofin): we can generalize this mechanism to calculate a GUID early 
in
-// the pass pipeline, associate it with any Global Value, and then use it for
-// PGO and ThinLTO.
-// At that point, this should be moved elsewhere.
-class AssignGUIDPass : public PassInfoMixin {
-public:
-  explicit AssignGUIDPass() = default;
-
-  /// Assign a GUID *if* one is not already assign, as a function metadata 
named
-  /// `GUIDMetadataName`.
-  PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
-  static const char *GUIDMetadataName;
-  // This should become GlobalValue::getGUID
-  static uint64_t getGUID(const Function &F);
-};
-
 } // namespace llvm
 #en

[llvm-branch-commits] [clang] [llvm] release/20.x: [X86][AVX10] Remove VAES and VPCLMULQDQ feature from AVX10.1 (#135489) (PR #135577)

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

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (llvmbot)


Changes

Backport ebba554a3211b0b98d3ae33ba70f9d6ceaab6ad4

Requested by: @phoebewang

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


3 Files Affected:

- (modified) clang/test/CodeGen/attr-target-x86.c (+4-4) 
- (modified) llvm/lib/Target/X86/X86.td (+1-1) 
- (modified) llvm/lib/TargetParser/X86TargetParser.cpp (+1-2) 


``diff
diff --git a/clang/test/CodeGen/attr-target-x86.c 
b/clang/test/CodeGen/attr-target-x86.c
index c92aad633082f..e5067c1c3b075 100644
--- a/clang/test/CodeGen/attr-target-x86.c
+++ b/clang/test/CodeGen/attr-target-x86.c
@@ -56,7 +56,7 @@ void f_default2(void) {
 __attribute__((target("avx,  sse4.2,  arch=   ivybridge")))
 void f_avx_sse4_2_ivybridge_2(void) {}
 
-// CHECK: [[f_no_aes_ivybridge]] = {{.*}}"target-cpu"="ivybridge" 
"target-features"="+avx,+cmov,+crc32,+cx16,+cx8,+f16c,+fsgsbase,+fxsr,+mmx,+pclmul,+popcnt,+rdrnd,+sahf,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave,+xsaveopt,-aes,-amx-avx512,-avx10.1-256,-avx10.1-512,-avx10.2-256,-avx10.2-512,-vaes"
+// CHECK: [[f_no_aes_ivybridge]] = {{.*}}"target-cpu"="ivybridge" 
"target-features"="+avx,+cmov,+crc32,+cx16,+cx8,+f16c,+fsgsbase,+fxsr,+mmx,+pclmul,+popcnt,+rdrnd,+sahf,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave,+xsaveopt,-aes,-vaes"
 __attribute__((target("no-aes, arch=ivybridge")))
 void f_no_aes_ivybridge(void) {}
 
@@ -98,11 +98,11 @@ void f_x86_64_v3(void) {}
 __attribute__((target("arch=x86-64-v4")))
 void f_x86_64_v4(void) {}
 
-// CHECK: [[f_avx10_1_256]] = {{.*}}"target-cpu"="i686" 
"target-features"="+aes,+avx,+avx10.1-256,+avx2,+avx512bf16,+avx512bitalg,+avx512bw,+avx512cd,+avx512dq,+avx512f,+avx512fp16,+avx512ifma,+avx512vbmi,+avx512vbmi2,+avx512vl,+avx512vnni,+avx512vpopcntdq,+cmov,+crc32,+cx8,+f16c,+fma,+mmx,+pclmul,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+vaes,+vpclmulqdq,+x87,+xsave,-amx-avx512,-avx10.1-512,-avx10.2-512,-evex512"
+// CHECK: [[f_avx10_1_256]] = {{.*}}"target-cpu"="i686" 
"target-features"="+avx,+avx10.1-256,+avx2,+avx512bf16,+avx512bitalg,+avx512bw,+avx512cd,+avx512dq,+avx512f,+avx512fp16,+avx512ifma,+avx512vbmi,+avx512vbmi2,+avx512vl,+avx512vnni,+avx512vpopcntdq,+cmov,+crc32,+cx8,+f16c,+fma,+mmx,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave,-amx-avx512,-avx10.1-512,-avx10.2-512,-evex512"
 __attribute__((target("avx10.1-256")))
 void f_avx10_1_256(void) {}
 
-// CHECK: [[f_avx10_1_512]] = {{.*}}"target-cpu"="i686" 
"target-features"="+aes,+avx,+avx10.1-256,+avx10.1-512,+avx2,+avx512bf16,+avx512bitalg,+avx512bw,+avx512cd,+avx512dq,+avx512f,+avx512fp16,+avx512ifma,+avx512vbmi,+avx512vbmi2,+avx512vl,+avx512vnni,+avx512vpopcntdq,+cmov,+crc32,+cx8,+evex512,+f16c,+fma,+mmx,+pclmul,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+vaes,+vpclmulqdq,+x87,+xsave"
+// CHECK: [[f_avx10_1_512]] = {{.*}}"target-cpu"="i686" 
"target-features"="+avx,+avx10.1-256,+avx10.1-512,+avx2,+avx512bf16,+avx512bitalg,+avx512bw,+avx512cd,+avx512dq,+avx512f,+avx512fp16,+avx512ifma,+avx512vbmi,+avx512vbmi2,+avx512vl,+avx512vnni,+avx512vpopcntdq,+cmov,+crc32,+cx8,+evex512,+f16c,+fma,+mmx,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave"
 __attribute__((target("avx10.1-512")))
 void f_avx10_1_512(void) {}
 
@@ -112,4 +112,4 @@ void f_prefer_256_bit(void) {}
 
 // CHECK: [[f_no_prefer_256_bit]] = 
{{.*}}"target-features"="{{.*}}-prefer-256-bit
 __attribute__((target("no-prefer-256-bit")))
-void f_no_prefer_256_bit(void) {}
\ No newline at end of file
+void f_no_prefer_256_bit(void) {}
diff --git a/llvm/lib/Target/X86/X86.td b/llvm/lib/Target/X86/X86.td
index 38761e1fd7eec..577428cad6d61 100644
--- a/llvm/lib/Target/X86/X86.td
+++ b/llvm/lib/Target/X86/X86.td
@@ -338,7 +338,7 @@ def FeatureAVX10_1 : SubtargetFeature<"avx10.1-256", 
"HasAVX10_1", "true",
   "Support AVX10.1 up to 256-bit 
instruction",
   [FeatureCDI, FeatureVBMI, FeatureIFMA, 
FeatureVNNI,
FeatureBF16, FeatureVPOPCNTDQ, 
FeatureVBMI2, FeatureBITALG,
-   FeatureVAES, FeatureVPCLMULQDQ, 
FeatureFP16]>;
+   FeatureFP16]>;
 def FeatureAVX10_1_512 : SubtargetFeature<"avx10.1-512", "HasAVX10_1_512", 
"true",
   "Support AVX10.1 up to 512-bit 
instruction",
   [FeatureAVX10_1, FeatureEVEX512]>;
diff --git a/llvm/lib/TargetParser/X86TargetParser.cpp 
b/llvm/lib/TargetParser/X86TargetParser.cpp
index e4b7ed7cf9b61..2ae6dd6b3d1ef 100644
--- a/llvm/lib/TargetParser/X86TargetParser.cpp
+++ b/llvm/lib/TargetParser/X86TargetParser.cpp
@@ -637,8 +637,7 @@ constexpr FeatureBitset ImpliedFeaturesAVXVNNI = 
FeatureAVX2;
 constexpr FeatureBitset ImpliedFeaturesAVX10_1 =
 FeatureAVX512CD | FeatureAVX512VBMI | FeatureAVX512IFMA |
 FeatureAVX512VNNI | Featur

[llvm-branch-commits] [clang] [llvm] release/20.x: [X86][AVX10] Remove VAES and VPCLMULQDQ feature from AVX10.1 (#135489) (PR #135577)

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

llvmbot wrote:

@e-kud What do you think about merging this PR to the release branch?

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


[llvm-branch-commits] [flang] [llvm] [Github][CI] Upload .ninja_log as an artifact (PR #135539)

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


@@ -33,6 +33,8 @@ function at-exit {
 
   mkdir -p artifacts
   ccache --print-stats > artifacts/ccache_stats.txt
+  cp "${BUILD_DIR}"/.ninja_log artifacts/.ninja_log
+  ls artifacts/

mizvekov wrote:

Should include hidden files, since we are uploading these too according to the 
other PR.
Might look prettier in list form.
Might be worth doing it recursively.
```suggestion
  ls -laR artifacts/
```

Why not do the same on the windows job though?

https://github.com/llvm/llvm-project/pull/135539
___
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] RISCVAsmParser: Reject call foo@invalid (PR #135509)

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

MaskRay wrote:

> I had pushed #135324 a couple of days ago to fix the same issue. I'm happy to 
> land either patch.

Thanks! I'll land this one (wanted to make it clear `@plt` is a legacy thing 
and test `call foo@3`). Let me think about the AsmBackend change.

https://github.com/llvm/llvm-project/pull/135509
___
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] RISCVAsmParser: Reject call foo@invalid (PR #135509)

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

https://github.com/MaskRay updated 
https://github.com/llvm/llvm-project/pull/135509

>From 3579f7d24a771f4c02e796a2ac9b91024b3c6ce9 Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Sat, 12 Apr 2025 16:27:14 -0700
Subject: [PATCH] .

Created using spr 1.3.5-bogner
---
 llvm/test/MC/RISCV/function-call-invalid.s | 1 +
 1 file changed, 1 insertion(+)

diff --git a/llvm/test/MC/RISCV/function-call-invalid.s 
b/llvm/test/MC/RISCV/function-call-invalid.s
index d429c4e27ba14..17d02015a6949 100644
--- a/llvm/test/MC/RISCV/function-call-invalid.s
+++ b/llvm/test/MC/RISCV/function-call-invalid.s
@@ -11,3 +11,4 @@ call %hi(foo) # CHECK: :[[@LINE]]:6: error: operand must be a 
bare symbol name
 call %lo(foo) # CHECK: :[[@LINE]]:6: error: operand must be a bare symbol name
 call foo, bar # CHECK: :[[@LINE]]:6: error: operand must be a bare symbol name
 call foo@pls # CHECK: :[[@LINE]]:10: error: @ (except the deprecated/ignored 
@plt) is disallowed
+call foo@3 # CHECK: :[[@LINE]]:10: error: @ (except the deprecated/ignored 
@plt) is disallowed

___
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] RISCVAsmParser: Reject call foo@invalid (PR #135509)

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

https://github.com/MaskRay updated 
https://github.com/llvm/llvm-project/pull/135509

>From 3579f7d24a771f4c02e796a2ac9b91024b3c6ce9 Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Sat, 12 Apr 2025 16:27:14 -0700
Subject: [PATCH] .

Created using spr 1.3.5-bogner
---
 llvm/test/MC/RISCV/function-call-invalid.s | 1 +
 1 file changed, 1 insertion(+)

diff --git a/llvm/test/MC/RISCV/function-call-invalid.s 
b/llvm/test/MC/RISCV/function-call-invalid.s
index d429c4e27ba14..17d02015a6949 100644
--- a/llvm/test/MC/RISCV/function-call-invalid.s
+++ b/llvm/test/MC/RISCV/function-call-invalid.s
@@ -11,3 +11,4 @@ call %hi(foo) # CHECK: :[[@LINE]]:6: error: operand must be a 
bare symbol name
 call %lo(foo) # CHECK: :[[@LINE]]:6: error: operand must be a bare symbol name
 call foo, bar # CHECK: :[[@LINE]]:6: error: operand must be a bare symbol name
 call foo@pls # CHECK: :[[@LINE]]:10: error: @ (except the deprecated/ignored 
@plt) is disallowed
+call foo@3 # CHECK: :[[@LINE]]:10: error: @ (except the deprecated/ignored 
@plt) is disallowed

___
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] Store GUIDs in metadata (PR #133682)

2025-04-13 Thread Owen Rodley via llvm-branch-commits

https://github.com/orodley updated 
https://github.com/llvm/llvm-project/pull/133682

>From 59631d43b44c8db12520c26fe4813c02a85c319c Mon Sep 17 00:00:00 2001
From: Owen Rodley 
Date: Mon, 31 Mar 2025 16:16:35 +1100
Subject: [PATCH] Store GUIDs in metadata

This takes the existing AssignGUID pass from CtxProfAnalysis, and runs
it by default, at the appropriate stages of the LTO pipeline. It also
changes GlobalValue::getGUID() to retrieve the GUID from the metadata
instead of computing it.

We don't yet have the supporting downstream changes to make a dedicated
GUID table in bitcode, nor do we use the metadata as part of ThinLTO --
it retains its existing mechanisms of recomputing GUIDs from separately
saved data. That will be changed later.
---
 llvm/include/llvm/Analysis/CtxProfAnalysis.h  | 36 +++
 llvm/include/llvm/IR/FixedMetadataKinds.def   |  1 +
 llvm/include/llvm/IR/GlobalValue.h|  6 +--
 .../llvm/Transforms/Utils/AssignGUID.h| 34 ++
 llvm/lib/Analysis/CtxProfAnalysis.cpp | 44 ++-
 llvm/lib/IR/Globals.cpp   | 34 ++
 llvm/lib/Passes/PassBuilder.cpp   |  1 +
 llvm/lib/Passes/PassBuilderPipelines.cpp  |  9 +++-
 .../Instrumentation/PGOCtxProfFlattening.cpp  |  2 +-
 .../Instrumentation/PGOCtxProfLowering.cpp|  3 +-
 llvm/lib/Transforms/Utils/AssignGUID.cpp  | 34 ++
 llvm/lib/Transforms/Utils/CMakeLists.txt  |  1 +
 .../Transforms/Utils/CallPromotionUtils.cpp   |  5 +--
 llvm/lib/Transforms/Utils/InlineFunction.cpp  |  4 +-
 14 files changed, 130 insertions(+), 84 deletions(-)
 create mode 100644 llvm/include/llvm/Transforms/Utils/AssignGUID.h
 create mode 100644 llvm/lib/Transforms/Utils/AssignGUID.cpp

diff --git a/llvm/include/llvm/Analysis/CtxProfAnalysis.h 
b/llvm/include/llvm/Analysis/CtxProfAnalysis.h
index ede8bd2fe5001..2e0b97b3844d9 100644
--- a/llvm/include/llvm/Analysis/CtxProfAnalysis.h
+++ b/llvm/include/llvm/Analysis/CtxProfAnalysis.h
@@ -37,9 +37,6 @@ class PGOContextualProfile {
   // we'll need when we maintain the profiles during IPO transformations.
   std::map FuncInfo;
 
-  /// Get the GUID of this Function if it's defined in this module.
-  GlobalValue::GUID getDefinedFunctionGUID(const Function &F) const;
-
   // This is meant to be constructed from CtxProfAnalysis, which will also set
   // its state piecemeal.
   PGOContextualProfile() = default;
@@ -56,9 +53,7 @@ class PGOContextualProfile {
 
   const PGOCtxProfile &profiles() const { return Profiles; }
 
-  bool isFunctionKnown(const Function &F) const {
-return getDefinedFunctionGUID(F) != 0;
-  }
+  bool isFunctionKnown(const Function &F) const { return F.getGUID() != 0; }
 
   StringRef getFunctionName(GlobalValue::GUID GUID) const {
 auto It = FuncInfo.find(GUID);
@@ -69,22 +64,22 @@ class PGOContextualProfile {
 
   uint32_t getNumCounters(const Function &F) const {
 assert(isFunctionKnown(F));
-return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCounterIndex;
+return FuncInfo.find(F.getGUID())->second.NextCounterIndex;
   }
 
   uint32_t getNumCallsites(const Function &F) const {
 assert(isFunctionKnown(F));
-return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCallsiteIndex;
+return FuncInfo.find(F.getGUID())->second.NextCallsiteIndex;
   }
 
   uint32_t allocateNextCounterIndex(const Function &F) {
 assert(isFunctionKnown(F));
-return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCounterIndex++;
+return FuncInfo.find(F.getGUID())->second.NextCounterIndex++;
   }
 
   uint32_t allocateNextCallsiteIndex(const Function &F) {
 assert(isFunctionKnown(F));
-return 
FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCallsiteIndex++;
+return FuncInfo.find(F.getGUID())->second.NextCallsiteIndex++;
   }
 
   using ConstVisitor = function_ref;
@@ -145,26 +140,5 @@ class CtxProfAnalysisPrinterPass
   const PrintMode Mode;
 };
 
-/// Assign a GUID to functions as metadata. GUID calculation takes linkage into
-/// account, which may change especially through and after thinlto. By
-/// pre-computing and assigning as metadata, this mechanism is resilient to 
such
-/// changes (as well as name changes e.g. suffix ".llvm." additions).
-
-// FIXME(mtrofin): we can generalize this mechanism to calculate a GUID early 
in
-// the pass pipeline, associate it with any Global Value, and then use it for
-// PGO and ThinLTO.
-// At that point, this should be moved elsewhere.
-class AssignGUIDPass : public PassInfoMixin {
-public:
-  explicit AssignGUIDPass() = default;
-
-  /// Assign a GUID *if* one is not already assign, as a function metadata 
named
-  /// `GUIDMetadataName`.
-  PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
-  static const char *GUIDMetadataName;
-  // This should become GlobalValue::getGUID
-  static uint64_t getGUID(const Function &F);
-};
-
 } // namespace llvm
 #endif // LLVM_ANALYSIS_CT

[llvm-branch-commits] [llvm] Store GUIDs in metadata (PR #133682)

2025-04-13 Thread Owen Rodley via llvm-branch-commits

https://github.com/orodley updated 
https://github.com/llvm/llvm-project/pull/133682

>From 59631d43b44c8db12520c26fe4813c02a85c319c Mon Sep 17 00:00:00 2001
From: Owen Rodley 
Date: Mon, 31 Mar 2025 16:16:35 +1100
Subject: [PATCH] Store GUIDs in metadata

This takes the existing AssignGUID pass from CtxProfAnalysis, and runs
it by default, at the appropriate stages of the LTO pipeline. It also
changes GlobalValue::getGUID() to retrieve the GUID from the metadata
instead of computing it.

We don't yet have the supporting downstream changes to make a dedicated
GUID table in bitcode, nor do we use the metadata as part of ThinLTO --
it retains its existing mechanisms of recomputing GUIDs from separately
saved data. That will be changed later.
---
 llvm/include/llvm/Analysis/CtxProfAnalysis.h  | 36 +++
 llvm/include/llvm/IR/FixedMetadataKinds.def   |  1 +
 llvm/include/llvm/IR/GlobalValue.h|  6 +--
 .../llvm/Transforms/Utils/AssignGUID.h| 34 ++
 llvm/lib/Analysis/CtxProfAnalysis.cpp | 44 ++-
 llvm/lib/IR/Globals.cpp   | 34 ++
 llvm/lib/Passes/PassBuilder.cpp   |  1 +
 llvm/lib/Passes/PassBuilderPipelines.cpp  |  9 +++-
 .../Instrumentation/PGOCtxProfFlattening.cpp  |  2 +-
 .../Instrumentation/PGOCtxProfLowering.cpp|  3 +-
 llvm/lib/Transforms/Utils/AssignGUID.cpp  | 34 ++
 llvm/lib/Transforms/Utils/CMakeLists.txt  |  1 +
 .../Transforms/Utils/CallPromotionUtils.cpp   |  5 +--
 llvm/lib/Transforms/Utils/InlineFunction.cpp  |  4 +-
 14 files changed, 130 insertions(+), 84 deletions(-)
 create mode 100644 llvm/include/llvm/Transforms/Utils/AssignGUID.h
 create mode 100644 llvm/lib/Transforms/Utils/AssignGUID.cpp

diff --git a/llvm/include/llvm/Analysis/CtxProfAnalysis.h 
b/llvm/include/llvm/Analysis/CtxProfAnalysis.h
index ede8bd2fe5001..2e0b97b3844d9 100644
--- a/llvm/include/llvm/Analysis/CtxProfAnalysis.h
+++ b/llvm/include/llvm/Analysis/CtxProfAnalysis.h
@@ -37,9 +37,6 @@ class PGOContextualProfile {
   // we'll need when we maintain the profiles during IPO transformations.
   std::map FuncInfo;
 
-  /// Get the GUID of this Function if it's defined in this module.
-  GlobalValue::GUID getDefinedFunctionGUID(const Function &F) const;
-
   // This is meant to be constructed from CtxProfAnalysis, which will also set
   // its state piecemeal.
   PGOContextualProfile() = default;
@@ -56,9 +53,7 @@ class PGOContextualProfile {
 
   const PGOCtxProfile &profiles() const { return Profiles; }
 
-  bool isFunctionKnown(const Function &F) const {
-return getDefinedFunctionGUID(F) != 0;
-  }
+  bool isFunctionKnown(const Function &F) const { return F.getGUID() != 0; }
 
   StringRef getFunctionName(GlobalValue::GUID GUID) const {
 auto It = FuncInfo.find(GUID);
@@ -69,22 +64,22 @@ class PGOContextualProfile {
 
   uint32_t getNumCounters(const Function &F) const {
 assert(isFunctionKnown(F));
-return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCounterIndex;
+return FuncInfo.find(F.getGUID())->second.NextCounterIndex;
   }
 
   uint32_t getNumCallsites(const Function &F) const {
 assert(isFunctionKnown(F));
-return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCallsiteIndex;
+return FuncInfo.find(F.getGUID())->second.NextCallsiteIndex;
   }
 
   uint32_t allocateNextCounterIndex(const Function &F) {
 assert(isFunctionKnown(F));
-return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCounterIndex++;
+return FuncInfo.find(F.getGUID())->second.NextCounterIndex++;
   }
 
   uint32_t allocateNextCallsiteIndex(const Function &F) {
 assert(isFunctionKnown(F));
-return 
FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCallsiteIndex++;
+return FuncInfo.find(F.getGUID())->second.NextCallsiteIndex++;
   }
 
   using ConstVisitor = function_ref;
@@ -145,26 +140,5 @@ class CtxProfAnalysisPrinterPass
   const PrintMode Mode;
 };
 
-/// Assign a GUID to functions as metadata. GUID calculation takes linkage into
-/// account, which may change especially through and after thinlto. By
-/// pre-computing and assigning as metadata, this mechanism is resilient to 
such
-/// changes (as well as name changes e.g. suffix ".llvm." additions).
-
-// FIXME(mtrofin): we can generalize this mechanism to calculate a GUID early 
in
-// the pass pipeline, associate it with any Global Value, and then use it for
-// PGO and ThinLTO.
-// At that point, this should be moved elsewhere.
-class AssignGUIDPass : public PassInfoMixin {
-public:
-  explicit AssignGUIDPass() = default;
-
-  /// Assign a GUID *if* one is not already assign, as a function metadata 
named
-  /// `GUIDMetadataName`.
-  PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
-  static const char *GUIDMetadataName;
-  // This should become GlobalValue::getGUID
-  static uint64_t getGUID(const Function &F);
-};
-
 } // namespace llvm
 #endif // LLVM_ANALYSIS_CT

[llvm-branch-commits] [clang] 75c486a - Revert "[RISCV][NFC] Make generated intrinsic records more human-readable (#1…"

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

Author: Pengcheng Wang
Date: 2025-04-14T12:53:45+08:00
New Revision: 75c486af5652662bc4c9adcff164d6ec8efcddbf

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

LOG: Revert "[RISCV][NFC] Make generated intrinsic records more human-readable 
(#1…"

This reverts commit d0cf5cd5f9790dc21396936d076389c3be1a9599.

Added: 


Modified: 
clang/include/clang/Support/RISCVVIntrinsicUtils.h
clang/lib/Sema/SemaRISCV.cpp
clang/lib/Support/RISCVVIntrinsicUtils.cpp
clang/utils/TableGen/RISCVVEmitter.cpp

Removed: 




diff  --git a/clang/include/clang/Support/RISCVVIntrinsicUtils.h 
b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
index dd0817f225258..8f2a4f54a1b7f 100644
--- a/clang/include/clang/Support/RISCVVIntrinsicUtils.h
+++ b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
@@ -11,7 +11,6 @@
 
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/BitmaskEnum.h"
-#include "llvm/ADT/Bitset.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include 
@@ -377,8 +376,6 @@ enum PolicyScheme : uint8_t {
   HasPolicyOperand,
 };
 
-llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, enum PolicyScheme PS);
-
 // TODO refactor RVVIntrinsic class design after support all intrinsic
 // combination. This represents an instantiation of an intrinsic with a
 // particular type and prototype
@@ -510,23 +507,6 @@ enum RVVRequire {
   RVV_REQ_NUM,
 };
 
-llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, enum RVVRequire Require);
-
-struct RequiredExtensions {
-  llvm::Bitset Bits;
-  RequiredExtensions() {}
-  RequiredExtensions(std::initializer_list Init) {
-for (auto I : Init)
-  Bits.set(I);
-  }
-
-  void set(unsigned I) { Bits.set(I); }
-  bool operator[](unsigned I) const { return Bits[I]; }
-};
-
-llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
-  const RequiredExtensions &Exts);
-
 // Raw RVV intrinsic info, used to expand later.
 // This struct is highly compact for minimized code size.
 struct RVVIntrinsicRecord {
@@ -538,7 +518,7 @@ struct RVVIntrinsicRecord {
   const char *OverloadedName;
 
   // Required target features for this intrinsic.
-  RequiredExtensions RequiredExtensions;
+  uint32_t RequiredExtensions[(RVV_REQ_NUM + 31) / 32];
 
   // Prototype for this intrinsic, index of RVVSignatureTable.
   uint16_t PrototypeIndex;

diff  --git a/clang/lib/Sema/SemaRISCV.cpp b/clang/lib/Sema/SemaRISCV.cpp
index b9f843b1920a1..746609604d1ba 100644
--- a/clang/lib/Sema/SemaRISCV.cpp
+++ b/clang/lib/Sema/SemaRISCV.cpp
@@ -232,7 +232,8 @@ void RISCVIntrinsicManagerImpl::ConstructRVVIntrinsics(
   for (auto &Record : Recs) {
 // Check requirements.
 if (llvm::any_of(FeatureCheckList, [&](const auto &Item) {
-  return Record.RequiredExtensions[Item.second] &&
+  return ((Record.RequiredExtensions[Item.second / 32] &
+   (1U << (Item.second % 32))) != 0) &&
  !TI.hasFeature(Item.first);
 }))
   continue;

diff  --git a/clang/lib/Support/RISCVVIntrinsicUtils.cpp 
b/clang/lib/Support/RISCVVIntrinsicUtils.cpp
index ee4d1e88e0ab8..e44fbb0181830 100644
--- a/clang/lib/Support/RISCVVIntrinsicUtils.cpp
+++ b/clang/lib/Support/RISCVVIntrinsicUtils.cpp
@@ -1196,91 +1196,36 @@ SmallVector 
parsePrototypes(StringRef Prototypes) {
   return PrototypeDescriptors;
 }
 
-#define STRINGIFY(NAME)
\
-  case NAME:   
\
-OS << #NAME;   
\
-break;
-
-llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, enum PolicyScheme PS) {
-  switch (PS) {
-STRINGIFY(SchemeNone)
-STRINGIFY(HasPassthruOperand)
-STRINGIFY(HasPolicyOperand)
-  }
-  return OS;
-}
-
-llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, enum RVVRequire Require) {
-  switch (Require) {
-STRINGIFY(RVV_REQ_RV64)
-STRINGIFY(RVV_REQ_Zvfhmin)
-STRINGIFY(RVV_REQ_Xsfvcp)
-STRINGIFY(RVV_REQ_Xsfvfnrclipxfqf)
-STRINGIFY(RVV_REQ_Xsfvfwmaccqqq)
-STRINGIFY(RVV_REQ_Xsfvqmaccdod)
-STRINGIFY(RVV_REQ_Xsfvqmaccqoq)
-STRINGIFY(RVV_REQ_Zvbb)
-STRINGIFY(RVV_REQ_Zvbc)
-STRINGIFY(RVV_REQ_Zvkb)
-STRINGIFY(RVV_REQ_Zvkg)
-STRINGIFY(RVV_REQ_Zvkned)
-STRINGIFY(RVV_REQ_Zvknha)
-STRINGIFY(RVV_REQ_Zvknhb)
-STRINGIFY(RVV_REQ_Zvksed)
-STRINGIFY(RVV_REQ_Zvksh)
-STRINGIFY(RVV_REQ_Zvfbfwma)
-STRINGIFY(RVV_REQ_Zvfbfmin)
-STRINGIFY(RVV_REQ_Zvfh)
-STRINGIFY(RVV_REQ_Experimental)
-  default:
-llvm_unreachable("Unsupported RVVRequire!");
-break;
-  }
-  return OS;
-}
-
-#undef STRINGIFY
-
-llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
-  

[llvm-branch-commits] [llvm] Store GUIDs in metadata (PR #133682)

2025-04-13 Thread Owen Rodley via llvm-branch-commits

https://github.com/orodley updated 
https://github.com/llvm/llvm-project/pull/133682

>From c7c5b411e4b22efd9a1b37cd5c71f2fa98069dc8 Mon Sep 17 00:00:00 2001
From: Owen Rodley 
Date: Mon, 31 Mar 2025 16:16:35 +1100
Subject: [PATCH] Store GUIDs in metadata

See https://discourse.llvm.org/t/rfc-keep-globalvalue-guids-stable/84801
for context.

This takes the existing AssignGUID pass from CtxProfAnalysis, and runs
it by default, at the appropriate stages of the LTO pipeline. It also
changes GlobalValue::getGUID() to retrieve the GUID from the metadata
instead of computing it.

We don't yet have the supporting downstream changes to make a dedicated
GUID table in bitcode, nor do we use the metadata as part of ThinLTO --
it retains its existing mechanisms of recomputing GUIDs from separately
saved data. That will be changed later.
---
 llvm/include/llvm/Analysis/CtxProfAnalysis.h  | 36 +++-
 llvm/include/llvm/IR/FixedMetadataKinds.def   |  1 +
 llvm/include/llvm/IR/GlobalValue.h|  6 +--
 .../llvm/Transforms/Utils/AssignGUID.h| 34 +++
 llvm/lib/Analysis/CtxProfAnalysis.cpp | 42 ++-
 llvm/lib/IR/Globals.cpp   | 34 +++
 llvm/lib/Passes/PassBuilder.cpp   |  1 +
 llvm/lib/Passes/PassBuilderPipelines.cpp  |  9 +++-
 .../Instrumentation/PGOCtxProfFlattening.cpp  |  2 +-
 .../Instrumentation/PGOCtxProfLowering.cpp|  3 +-
 llvm/lib/Transforms/Utils/AssignGUID.cpp  | 34 +++
 llvm/lib/Transforms/Utils/CMakeLists.txt  |  1 +
 .../Transforms/Utils/CallPromotionUtils.cpp   |  5 +--
 llvm/lib/Transforms/Utils/InlineFunction.cpp  |  4 +-
 14 files changed, 129 insertions(+), 83 deletions(-)
 create mode 100644 llvm/include/llvm/Transforms/Utils/AssignGUID.h
 create mode 100644 llvm/lib/Transforms/Utils/AssignGUID.cpp

diff --git a/llvm/include/llvm/Analysis/CtxProfAnalysis.h 
b/llvm/include/llvm/Analysis/CtxProfAnalysis.h
index 6f1c3696ca78c..b18b04e133f8f 100644
--- a/llvm/include/llvm/Analysis/CtxProfAnalysis.h
+++ b/llvm/include/llvm/Analysis/CtxProfAnalysis.h
@@ -46,9 +46,6 @@ class PGOContextualProfile {
   // we'll need when we maintain the profiles during IPO transformations.
   std::map FuncInfo;
 
-  /// Get the GUID of this Function if it's defined in this module.
-  GlobalValue::GUID getDefinedFunctionGUID(const Function &F) const;
-
   // This is meant to be constructed from CtxProfAnalysis, which will also set
   // its state piecemeal.
   PGOContextualProfile() = default;
@@ -67,9 +64,7 @@ class PGOContextualProfile {
 
   bool isInSpecializedModule() const;
 
-  bool isFunctionKnown(const Function &F) const {
-return getDefinedFunctionGUID(F) != 0;
-  }
+  bool isFunctionKnown(const Function &F) const { return F.getGUID() != 0; }
 
   StringRef getFunctionName(GlobalValue::GUID GUID) const {
 auto It = FuncInfo.find(GUID);
@@ -80,22 +75,22 @@ class PGOContextualProfile {
 
   uint32_t getNumCounters(const Function &F) const {
 assert(isFunctionKnown(F));
-return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCounterIndex;
+return FuncInfo.find(F.getGUID())->second.NextCounterIndex;
   }
 
   uint32_t getNumCallsites(const Function &F) const {
 assert(isFunctionKnown(F));
-return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCallsiteIndex;
+return FuncInfo.find(F.getGUID())->second.NextCallsiteIndex;
   }
 
   uint32_t allocateNextCounterIndex(const Function &F) {
 assert(isFunctionKnown(F));
-return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCounterIndex++;
+return FuncInfo.find(F.getGUID())->second.NextCounterIndex++;
   }
 
   uint32_t allocateNextCallsiteIndex(const Function &F) {
 assert(isFunctionKnown(F));
-return 
FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCallsiteIndex++;
+return FuncInfo.find(F.getGUID())->second.NextCallsiteIndex++;
   }
 
   using ConstVisitor = function_ref;
@@ -157,26 +152,5 @@ class CtxProfAnalysisPrinterPass
   const PrintMode Mode;
 };
 
-/// Assign a GUID to functions as metadata. GUID calculation takes linkage into
-/// account, which may change especially through and after thinlto. By
-/// pre-computing and assigning as metadata, this mechanism is resilient to 
such
-/// changes (as well as name changes e.g. suffix ".llvm." additions).
-
-// FIXME(mtrofin): we can generalize this mechanism to calculate a GUID early 
in
-// the pass pipeline, associate it with any Global Value, and then use it for
-// PGO and ThinLTO.
-// At that point, this should be moved elsewhere.
-class AssignGUIDPass : public PassInfoMixin {
-public:
-  explicit AssignGUIDPass() = default;
-
-  /// Assign a GUID *if* one is not already assign, as a function metadata 
named
-  /// `GUIDMetadataName`.
-  PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
-  static const char *GUIDMetadataName;
-  // This should become GlobalValue::getGUID
-  static uint64_t getGUID(const 

[llvm-branch-commits] [llvm] [AMDGPU][SDAG] Only fold flat offsets if they are inbounds (PR #132353)

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


@@ -8203,14 +8203,14 @@ static SDValue getMemcpyLoadsAndStores(
 
   Value = DAG.getExtLoad(
   ISD::EXTLOAD, dl, NVT, Chain,
-  DAG.getMemBasePlusOffset(Src, TypeSize::getFixed(SrcOff), dl),
+  DAG.getObjectPtrOffset(dl, Src, TypeSize::getFixed(SrcOff)),
   SrcPtrInfo.getWithOffset(SrcOff), VT,
   commonAlignment(*SrcAlign, SrcOff), SrcMMOFlags, NewAAInfo);
   OutLoadChains.push_back(Value.getValue(1));
 
   Store = DAG.getTruncStore(
   Chain, dl, Value,
-  DAG.getMemBasePlusOffset(Dst, TypeSize::getFixed(DstOff), dl),
+  DAG.getObjectPtrOffset(dl, Dst, TypeSize::getFixed(DstOff)),

arsenm wrote:

These should be split into a separate change 

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


[llvm-branch-commits] [mlir] 61393cc - Revert "[tosa]: canonicalize dynamic size of tosa.slice to static output shap…"

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

Author: Thurston Dang
Date: 2025-04-13T00:06:12-07:00
New Revision: 61393cc94c0223c2d2fe3ee15e6f79e55c4f3e8b

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

LOG: Revert "[tosa]: canonicalize dynamic size of tosa.slice to static output 
shap…"

This reverts commit 60b1d44d708d5912897c7bdab681cbefe8f35e79.

Added: 


Modified: 
mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
mlir/test/Dialect/Tosa/canonicalize.mlir

Removed: 




diff  --git a/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp 
b/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
index 84f89bfd7f2d3..c4ef7d0bb9ff5 100644
--- a/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
+++ b/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
@@ -731,62 +731,9 @@ struct ConcatSliceOptimization : public 
OpRewritePattern {
   }
 };
 
-// Update size operand of tosa.slice if size has dynamic dims but corresponding
-// output dim is static
-struct SliceDynamicSizeCanonicalization
-: public OpRewritePattern {
-  using OpRewritePattern::OpRewritePattern;
-
-  LogicalResult matchAndRewrite(tosa::SliceOp sliceOp,
-PatternRewriter &rewriter) const override {
-ShapedType resultType = cast(sliceOp.getType());
-
-ElementsAttr sizeElems;
-if (!matchPattern(sliceOp.getSize(), m_Constant(&sizeElems))) {
-  return rewriter.notifyMatchFailure(
-  sliceOp, "size of slice must be a static ranked shape");
-}
-
-llvm::SmallVector sliceSizes =
-llvm::to_vector(sizeElems.getValues());
-
-bool replaceSliceSize{false};
-// if size op has -1 indicating dynamic shape but corresponding dim on the
-// output is statically known, update size to match with known output dim
-// shape
-for (const auto &[index, size] : llvm::enumerate(sliceSizes)) {
-  if (size == -1 && !resultType.isDynamicDim(index)) {
-sliceSizes[index] = resultType.getDimSize(index);
-replaceSliceSize = true;
-  }
-}
-
-if (!replaceSliceSize) {
-  return rewriter.notifyMatchFailure(
-  sliceOp, "no dimension of size of slice is dynamic that resolves "
-   "to static output shape");
-}
-
-auto size_op = getTosaConstShape(rewriter, sliceOp.getLoc(), sliceSizes);
-auto newSliceOp = rewriter.create(
-sliceOp.getLoc(), sliceOp.getType(), sliceOp.getInput1(),
-sliceOp.getStart(), size_op);
-
-rewriter.replaceOp(sliceOp, newSliceOp.getResult());
-
-// Remove const_shape size op when it no longer has use point.
-Operation *sizeConstShape = sliceOp.getSize().getDefiningOp();
-if (sizeConstShape->getResult(0).hasOneUse())
-  rewriter.eraseOp(sizeConstShape);
-
-return success();
-  }
-};
-
 void SliceOp::getCanonicalizationPatterns(RewritePatternSet &results,
   MLIRContext *context) {
-  results.add(
-  context);
+  results.add(context);
 }
 
 
//===--===//

diff  --git a/mlir/test/Dialect/Tosa/canonicalize.mlir 
b/mlir/test/Dialect/Tosa/canonicalize.mlir
index a754a46be603f..b366b4f1e4fd4 100644
--- a/mlir/test/Dialect/Tosa/canonicalize.mlir
+++ b/mlir/test/Dialect/Tosa/canonicalize.mlir
@@ -1212,18 +1212,3 @@ func.func @do_not_fold_intdiv_division_by_0() -> 
tensor<1x24x2xi32> {
   %16 = tosa.intdiv %4, %1 : (tensor<1x24x2xi32>, tensor<1x24x2xi32>) -> 
tensor<1x24x2xi32>
   return %16 : tensor<1x24x2xi32>
 }
-
-
-// 
-// CHECK-LABEL:   func.func @slice_dynamic_size_static_output_canonicalize(
-// CHECK-SAME: %[[ARG0:.*]]: tensor<2x60x59x?xf32>) -> 
tensor<2x60x58x?xf32> {
-// CHECK:   %[[START:.*]] = tosa.const_shape  {values = dense<0> : 
tensor<4xindex>} : () -> !tosa.shape<4>
-// CHECK:   %[[SIZE:.*]] = tosa.const_shape  {values = dense<[2, 60, 
58, -1]> : tensor<4xindex>} : () -> !tosa.shape<4>
-// CHECK:   %[[SLICE:.*]] = tosa.slice %[[ARG0]], %[[START]], 
%[[SIZE]] : (tensor<2x60x59x?xf32>, !tosa.shape<4>, !tosa.shape<4>) -> 
tensor<2x60x58x?xf32>
-// CHECK:   return %[[SLICE]]
-func.func @slice_dynamic_size_static_output_canonicalize(%arg0: 
tensor<2x60x59x?xf32>) -> tensor<2x60x58x?xf32> {
-%0 = tosa.const_shape  {values = dense<0> : tensor<4xindex>} : () -> 
!tosa.shape<4>
-%1 = tosa.const_shape  {values = dense<[-1, 60, 58, -1]> : 
tensor<4xindex>} : () -> !tosa.shape<4>
-%2 = tosa.slice %arg0, %0, %1 : (tensor<2x60x59x?xf32>, !tosa.shape<4>, 
!tosa.shape<4>) -> tensor<2x60x58x?xf32>
-return %2 : tensor<2x60x58x?xf32>
-  }



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/li

[llvm-branch-commits] [llvm] [SSAUpdaterBulk] Add PHI simplification pass. (PR #135180)

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


@@ -77,6 +76,10 @@ class SSAUpdaterBulk {
   /// vector.
   void RewriteAllUses(DominatorTree *DT,
   SmallVectorImpl *InsertedPHIs = nullptr);
+
+  /// Rewrite all uses and simplify the inserted PHI nodes.
+  /// Use this method to preserve behavior when replacing SSAUpdater.
+  void RewriteAndOptimizeAllUses(DominatorTree *DT);

arsenm wrote:

Should this be a reference? Is null really permitted? 

https://github.com/llvm/llvm-project/pull/135180
___
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] [SSAUpdaterBulk] Add PHI simplification pass. (PR #135180)

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


@@ -222,3 +223,38 @@ void SSAUpdaterBulk::RewriteAllUses(DominatorTree *DT,
 }
   }
 }
+
+// Perform a single pass of simplification over the worklist of PHIs.
+static void SimplifyPass(MutableArrayRef Worklist) {

arsenm wrote:

Start with lowercase 

https://github.com/llvm/llvm-project/pull/135180
___
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] RISCVAsmParser: Reject call foo@invalid (PR #135509)

2025-04-13 Thread Sam Elliott via llvm-branch-commits

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


https://github.com/llvm/llvm-project/pull/135509
___
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] [SSAUpdaterBulk] Add PHI simplification pass. (PR #135180)

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


@@ -222,3 +223,38 @@ void SSAUpdaterBulk::RewriteAllUses(DominatorTree *DT,
 }
   }
 }
+
+// Perform a single pass of simplification over the worklist of PHIs.
+static void SimplifyPass(MutableArrayRef Worklist) {
+  if (Worklist.empty())
+return;
+
+  const DataLayout &DL = Worklist.front()->getParent()->getDataLayout();

arsenm wrote:

Pass this in as an argument? 

https://github.com/llvm/llvm-project/pull/135180
___
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] [SSAUpdaterBulk] Add PHI simplification pass. (PR #135180)

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


@@ -222,3 +223,38 @@ void SSAUpdaterBulk::RewriteAllUses(DominatorTree *DT,
 }
   }
 }
+
+// Perform a single pass of simplification over the worklist of PHIs.
+static void SimplifyPass(MutableArrayRef Worklist) {
+  if (Worklist.empty())
+return;
+
+  const DataLayout &DL = Worklist.front()->getParent()->getDataLayout();
+  for (PHINode *&PHI : Worklist) {
+if (Value *Simplified = simplifyInstruction(PHI, DL)) {
+  PHI->replaceAllUsesWith(Simplified);
+  PHI->eraseFromParent();
+  PHI = nullptr; // Mark as removed.
+}
+  }
+}
+
+static void DeduplicatePass(ArrayRef Worklist) {
+  SmallDenseMap BBs;
+  for (PHINode *PHI : Worklist) {
+if (PHI)
+  ++BBs[PHI->getParent()];
+  }
+
+  for (auto [BB, NumNewPHIs] : BBs) {
+auto FirstExistedPN = std::next(BB->phis().begin(), NumNewPHIs);
+EliminateNewDuplicatePHINodes(BB, FirstExistedPN);
+  }
+}
+
+void SSAUpdaterBulk::RewriteAndOptimizeAllUses(DominatorTree *DT) {
+  SmallVector PHIs;
+  RewriteAllUses(DT, &PHIs);
+  SimplifyPass(PHIs);
+  DeduplicatePass(PHIs);
+}

arsenm wrote:

```suggestion
}

```

https://github.com/llvm/llvm-project/pull/135180
___
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] IR: Remove uselist for constantdata (PR #134692)

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


@@ -437,7 +437,8 @@ static bool LinearizeExprTree(Instruction *I,
 for (unsigned OpIdx = 0; OpIdx < I->getNumOperands(); ++OpIdx) { // Visit 
operands.
   Value *Op = I->getOperand(OpIdx);
   LLVM_DEBUG(dbgs() << "OPERAND: " << *Op << " (" << Weight << ")\n");
-  assert(!Op->use_empty() && "No uses, so how did we get to it?!");
+  assert((isa(Op) || !Op->use_empty()) &&

nikic wrote:

Why do we need this change? use_empty() should still work on ConstantData?

https://github.com/llvm/llvm-project/pull/134692
___
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] IR: Remove uselist for constantdata (PR #134692)

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


@@ -8857,6 +8857,8 @@ bool LLParser::parseMDNodeVector(SmallVectorImpl &Elts) {
 
//===--===//
 bool LLParser::sortUseListOrder(Value *V, ArrayRef Indexes,
 SMLoc Loc) {
+  if (isa(V))

nikic wrote:

hasUseList() more natural here and next two files?

https://github.com/llvm/llvm-project/pull/134692
___
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] IR: Remove uselist for constantdata (PR #134692)

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


@@ -889,10 +919,50 @@ inline raw_ostream &operator<<(raw_ostream &OS, const 
Value &V) {
   return OS;
 }
 
+inline Use::~Use() {
+  if (Val)
+Val->removeUse(*this);
+}
+
+void Use::addToList(unsigned &Count) {
+  assert(isa(Val) && "Only ConstantData is ref-counted");
+  ++Count;
+
+  // We don't have a uselist - clear the remnant if we are replacing a
+  // non-constant value.
+  Prev = nullptr;
+  Next = nullptr;

nikic wrote:

Can you explain in more detail when this is necessary? It seems odd to me that 
addToList() should be responsible for nulling out these pointers.

https://github.com/llvm/llvm-project/pull/134692
___
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] [Github]CI] Upload .ninja_log as an artifact (PR #135539)

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

https://github.com/boomanaiden154 created 
https://github.com/llvm/llvm-project/pull/135539

This enables using tools like https://github.com/nico/ninjatracing for
performance introspection.



___
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] [Github]CI] Upload .ninja_log as an artifact (PR #135539)

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

https://github.com/boomanaiden154 updated 
https://github.com/llvm/llvm-project/pull/135539


___
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] [Github]CI] Upload .ninja_log as an artifact (PR #135539)

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

https://github.com/boomanaiden154 updated 
https://github.com/llvm/llvm-project/pull/135539


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits