https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127558
--- Comment #1 from Jeffrey A. Law <law at gcc dot gnu.org> --- Suggest trying with -fno-ext-dce. I don't have a loongarch setup handy, so can't do it myself easily. Reason I'm suggesting is we have fixed a few bugs in that pass recently and based on the behavior you're describing it could be ext-dce dropping a sign extension incorrectly.
