On 4/8/25 16:32, Vineet Gupta wrote:
>>>>>> Yay ! It does work. Awesome.
>>>>>> I've uploaded the further reduced test to PR/119533
>>>>> Hmm, I'm seeing the same ICE as before with my patch.  Did you happen to 
>>>>> change 
>>>>> something else on your local tree still?
>> Yeah I had some debug stuff lying around. In particular it is missing the
>> initializer for kill bitmap.
>>
>> @@ -2698,6 +2713,7 @@ pre_vsetvl::compute_lcm_local_properties ()
>>    m_avout = sbitmap_vector_alloc (last_basic_block_for_fn (cfun), 
>> num_exprs);
>>  
>>    bitmap_vector_clear (m_avloc, last_basic_block_for_fn (cfun));
>> +  bitmap_vector_clear (m_kill, last_basic_block_for_fn (cfun));
>>    bitmap_vector_clear (m_antloc, last_basic_block_for_fn (cfun));
>>    bitmap_vector_ones (m_transp, last_basic_block_for_fn (cfun));
>>
>>
>>>> On top, I'm now seeing a ton of vsetvl test failures vs just the one I 
>>>> reported...  No idea what I have been testing before.  Grml.
>> From your inline diff (with "!= 1" as cue) , I'd placed the check as follows
>>
>>       if (!curr_info.valid_p ()
>>           || eg->probability == profile_probability::never ()
>>           || src_block_info.probability
>>            == profile_probability::uninitialized ()
>>           /* When multiple set bits in earliest edge, such edge may
>>          have infinite loop in preds or succs or multiple conflict
>>          vsetvl expression which make such edge is unrelated.  We
>>          don't perform fusion for such situation.  */
>>           || bitmap_count_bits (e) != 1)
>>         continue;
>>
>> +      if (!bitmap_bit_p (m_transp[eg->src->index], expr_index))
>> +        continue;
>>
>> With both of above changes both go tests passed in the morning.
>>
>>> Ah, of course the check was intended to be inside src_block_info.empty_p () 
>>> and 
>>> not outside.  That gets rid of the test failures.  But the go tests still 
>>> ICE 
>>> for me, one way or another.
>> Now I moved the bitmap check further down inside src_block_info.empty_p () 
>> and
>> both tests still pass.
>> So looks like the kill bitmap init is essential as well.
> Doh ! Something is weird, I did a clean everything and now I see the issues
> still and it seems for baseline build, prinstine trunk is hitting ICE on glibc
> build as of
>
>      2025-04-08 0980a6ff7ae3 Daily bump.
>
> Let me untangle my testing first.

The go issue, needs your transparent set check but we also need to tighten
tighten invalid_opt_bb_p () for skipping successor edges being abnormal,
currently it only does for predecessors only.  If you recall this is something
I'd tried last week, but that alone was not enough.

So it seems we might have to seperate out the changes for PR/119547 (opencv) and
119533 (libgo) with latter dependent on former.
 
On baseline Daily Bump of April 01, with attached patch including everything
(just to test), we see 2 deltas

    rv64imafdcv_zvl256b_zba_zbb_zbs_zicond/  lp64d/ medlow |  303 /   101 |   16
/     4 |   67 /    12 |
    rv64imafdcv_zvl256b_zba_zbb_zbs_zicond/  lp64d/ medlow |  311 /   103 |   16
/     4 |   67 /    12 |

 FAIL: gcc.target/riscv/rvv/vsetvl/vlmax_switch_vtype-10.c
 FAIL: gcc.target/riscv/rvv/vsetvl/avl_single-68.c

I still need to figure out if vlmax_switch_vtype-10 is transparency related or
the edge issue.

Thx,
-Vineet
From cf538157f1af8ab090f31f66b5689dae3f5a58cc Mon Sep 17 00:00:00 2001
From: Vineet Gupta <vine...@rivosinc.com>
Date: Tue, 8 Apr 2025 13:37:12 -0700
Subject: [RFC/do-not-merge] RISC-V: vsetvl: skip over tranaparent blocks in
 LCM

Signed-off-by: Vineet Gupta <vine...@rivosinc.com>
---
 gcc/config/riscv/riscv-vsetvl.cc            |  10 +-
 gcc/testsuite/go.dg/pr119533-riscv.go       | 120 ++++++++++++++++++++
 gcc/testsuite/go.dg/pr119533-small-riscv.go |  42 +++++++
 3 files changed, 171 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/go.dg/pr119533-riscv.go
 create mode 100644 gcc/testsuite/go.dg/pr119533-small-riscv.go

diff --git a/gcc/config/riscv/riscv-vsetvl.cc b/gcc/config/riscv/riscv-vsetvl.cc
index 0ac2538f596f..37d5f0c37c75 100644
--- a/gcc/config/riscv/riscv-vsetvl.cc
+++ b/gcc/config/riscv/riscv-vsetvl.cc
@@ -685,7 +685,7 @@ invalid_opt_bb_p (basic_block cfg_bb)
   /* We only do LCM optimizations on blocks that are post dominated by
      EXIT block, that is, we don't do LCM optimizations on infinite loop.  */
   FOR_EACH_EDGE (e, ei, cfg_bb->succs)
-    if (e->flags & EDGE_FAKE)
+    if ((e->flags & EDGE_FAKE) || (e->flags & EDGE_ABNORMAL))
       return true;
 
   return false;
@@ -2698,6 +2698,7 @@ pre_vsetvl::compute_lcm_local_properties ()
   m_avout = sbitmap_vector_alloc (last_basic_block_for_fn (cfun), num_exprs);
 
   bitmap_vector_clear (m_avloc, last_basic_block_for_fn (cfun));
+  bitmap_vector_clear (m_kill, last_basic_block_for_fn (cfun));
   bitmap_vector_clear (m_antloc, last_basic_block_for_fn (cfun));
   bitmap_vector_ones (m_transp, last_basic_block_for_fn (cfun));
 
@@ -2749,6 +2750,9 @@ pre_vsetvl::compute_lcm_local_properties ()
 
       if (invalid_opt_bb_p (bb->cfg_bb ()))
 	{
+	  if (dump_file)
+	    fprintf (dump_file, "\n --- skipping bb %u): ", bb->index ());
+
 	  bitmap_clear (m_antloc[bb_index]);
 	  bitmap_clear (m_transp[bb_index]);
 	}
@@ -3004,6 +3008,10 @@ pre_vsetvl::earliest_fuse_vsetvl_info (int iter)
 
 	  if (src_block_info.empty_p ())
 	    {
+
+	      if (!bitmap_bit_p (m_transp[eg->src->index], expr_index))
+		continue;
+
 	      vsetvl_info new_curr_info = curr_info;
 	      new_curr_info.set_bb (crtl->ssa->bb (eg->dest));
 	      bool has_compatible_p
diff --git a/gcc/testsuite/go.dg/pr119533-riscv.go b/gcc/testsuite/go.dg/pr119533-riscv.go
new file mode 100644
index 000000000000..30f52d267c5f
--- /dev/null
+++ b/gcc/testsuite/go.dg/pr119533-riscv.go
@@ -0,0 +1,120 @@
+// { dg-do compile { target riscv64*-*-* } }
+// { dg-options "-O2 -march=rv64gcv -mabi=lp64d" }
+
+// Reduced from libgo build (multi-file reduction, merged mnaully
+// and hand reduced again).
+
+package ast
+import (
+	"go/token"
+	"go/scanner"
+	"reflect"
+)
+type v struct {}
+type w func( string,  reflect.Value) bool
+func x( string,  reflect.Value) bool
+type r struct {
+	scanner.ErrorList
+}
+type ab interface {}
+type ae interface {}
+type af interface {}
+type ag struct {}
+func (ag) Pos() token.Pos
+func (ag) ah() token.Pos
+type c struct {
+	aj    ae          }
+type ak struct {
+	al    []c  }
+type (
+	am struct {
+		an    string    }
+	bs struct {
+		Value    string
+	  }
+)
+func ao(string) *am
+type (
+	ap interface {}
+	aq struct {
+		ar    bs     }
+as struct {
+		bt ak
+		an am        }
+)
+type File struct {
+	*ag
+	token.Pos
+	*am
+	at      []af
+	*v
+	au    []*aq
+	av *am
+	aw   []*ag }
+type ax struct {
+	an    string
+	*v
+	ay   map[string]File   }
+func a(az *token.FileSet, b token.Pos) int
+type k struct {
+	l token.Pos
+	ah   token.Pos
+}
+type m struct {
+	bb bool
+	bc   *ag
+}
+
+type bi uint
+func bj(a *as) string {
+	if b := a.bt; len(b.al) == 1 {
+		c := b.al[0].aj
+		if e := c; e != nil {}
+	}
+	return a.an.an
+}
+func MergePackageFiles(f ax, g bi) *File {
+	h := 0
+	bk := 0
+	k := 0
+	bl := make([]string, len(f.ay))
+	i := 0
+	for bm, a := range f.ay {
+		bl[i] = bm
+		k += len(a.at)
+	}
+	var bn *ag
+	var l token.Pos
+	if h > 0 {}
+	var bo []af
+		bu := make(map[string]int)
+		m := 0
+		for _, bm := range bl {
+			a := f.ay[bm]
+			for _, d := range a.at {
+				if g!= 0 {
+					if a, p := d.(*as); p {
+						n := bj(a)
+						if j, bp := bu[n]; bp {
+							if bo != nil && bo[j]== nil {}
+						}
+					}
+				}
+			}
+		}
+		if m > 0 {}
+	var bq []*aq
+		q := make(map[string]bool)
+		for _, bm := range bl {
+			a := f.ay[bm]
+			for _, br := range a.au {
+				if o := br.ar.Value; q[o] {}
+			}
+		}
+	var bh = make([]*ag, bk)
+		for _, bm := range bl {
+			a := f.ay[bm]
+			copy(bh, a.aw)
+		}
+	return &File{bn, l, ao(f.an), bo, f.v, bq, nil, bh}
+}
diff --git a/gcc/testsuite/go.dg/pr119533-small-riscv.go b/gcc/testsuite/go.dg/pr119533-small-riscv.go
new file mode 100644
index 000000000000..ce3ffaffe9d4
--- /dev/null
+++ b/gcc/testsuite/go.dg/pr119533-small-riscv.go
@@ -0,0 +1,42 @@
+// { dg-do compile { target riscv64*-*-* } }
+// { dg-options "-O2 -march=rv64gcv -mabi=lp64d" }
+
+package ast
+
+type as struct {
+	bt []struct{}
+	an string
+}
+
+func bj(a *as) string {
+	if b := a.bt; len(a.an) == 1 {
+		_ = b[0]
+	}
+	return a.an
+}
+
+func MergePackageFiles(f map[string][]interface{}, g uint) []interface{} {
+	bl := make([]string, len(f))
+	var bo []interface{}
+	bu := make(map[string]int)
+	for _, bm := range bl {
+		a := f[bm]
+		for _, d := range a {
+			if g != 0 {
+				if a, p := d.(*as); p {
+					n := bj(a)
+					if j, bp := bu[n]; bp {
+						_ = j
+					}
+				}
+			}
+		}
+	}
+	for _, bm := range bl {
+		_ = bm
+	}
+	for _, bm := range bl {
+		_ = f[bm]
+	}
+	return bo
+}
-- 
2.43.0

Reply via email to