Use unspec_volatile instead of unspec for those cache operations, because those operations have side effects, instruction scheduler might reorder those CMO operations if you use unspec.
> diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md > index b3c5bce842a..d60843df490 100644 > --- a/gcc/config/riscv/riscv.md > +++ b/gcc/config/riscv/riscv.md > @@ -45,6 +45,11 @@ > > ;; Stack tie > UNSPEC_TIE > + UNSPEC_CLEAN > + UNSPEC_FLUSH > + UNSPEC_INVAL > + UNSPEC_ZERO > + UNSPEC_PREI And then move those UNSPEC to unspecv > ]) > > (define_c_enum "unspecv" [ > @@ -69,6 +74,7 @@ > ;; Stack Smash Protector > UNSPEC_SSP_SET > UNSPEC_SSP_TEST > + > ])