| From: | Andres Freund <andres(at)anarazel(dot)de> |
|---|---|
| To: | Greg Burd <greg(at)burd(dot)me> |
| Cc: | Nathan Bossart <nathandbossart(at)gmail(dot)com>, John Naylor <johncnaylorls(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Andrew Dunstan <andrew(at)dunslane(dot)net> |
| Subject: | Re: Add RISC-V Zbb popcount optimization |
| Date: | 2026-05-28 14:17:16 |
| Message-ID: | zhz7l5sxlgnibx6m4wval6j5ongohptndq6atimcfez3nso436@upcmbeylkdkg |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
On 2026-05-27 13:04:46 -0400, Greg Burd wrote:
> > Forgive me, while $subject only mentions popcount I couldn't help
> > myself so I added a few more RISC-V patches including a bug fix that I
> > hope makes greenfly happy again.
> >
> >
> > 0001 - This is a bug fix for DES/RISC-V/Clang DES initialization.
How confident are we that this bug just affects DES?
> > ------> Join me in "the rabbit hole" on this issue if you care to...
> >
> > The existing software DES (as shown by the build-farm animal "greenfly"
> > [1]) fails because Clang 20 has an auto-vectorization bug that we
> > trigger in the DES initialization code (des_init() function), not the
> > DES encryption algorithm itself.
> >
> > I searched the LLVM issue tracker, here are the issues that caught my eye:
> > 1. Issue #176001 - "RISC-V Wrong code at -O1"
> > - Vector peephole optimization with vmerge folding
> > - Fixed by PR #176077 (merged Jan 2024)
> > - Link: https://github.com/llvm/llvm-project/issues/176001
> > 2. Issue #187458 - "Wrong code for vector.extract.last.active"
> > - Large index issues with zvl1024b
> > - Partially fixed, still work ongoing
> > - Link: https://github.com/llvm/llvm-project/issues/187458
> > 3. Issue #171978 - "RISC-V Wrong code at -O2/O3"
> > - Illegal instruction from mismatched EEW
> > - Under investigation
> > - Link: https://github.com/llvm/llvm-project/issues/171978
> > 4. PR #176105 - "Fix i64 gather/scatter cost on rv32"
> > - Cost model fixes for scatter/gather (merged Jan 2026)
> > - Link: https://github.com/llvm/llvm-project/pull/176105
Have you confirmed that, by using a newer clang, the merging of the fixes
actually fixes the problem?
ISTM a perfectly viable patch would be to just reject building with a
non-very-recent clang on riscv.
> > My fix in 0001 is simply adding this in a few places in crypt-des.c:
> >
> > #if defined(__riscv) && defined(__clang__)
> > pg_memory_barrier();
> > #endif
That seems like a pretty odd fix for the problem. If the problem is
auto-vectorization, we should stop auto-vectorization, not sprinkle memory
barriers around. Either by pushing disabling of auto-vectorization on the
file scope (using a #pragma clang push), loop scope (using vectorize(disable))
or just globally (by disabling it on riscv + clang, if the compiler is too
old).
Greetings,
Andres Freund
| From | Date | Subject | |
|---|---|---|---|
| Next Message | vignesh C | 2026-05-28 14:49:14 | Re: Proposal: Conflict log history table for Logical Replication |
| Previous Message | Alexander Pyhalov | 2026-05-28 13:55:26 | Re: CREATE INDEX CONCURRENTLY on partitioned index |