https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109414
Bug ID: 109414 Summary: RISC-V: unnecessary sext.w in rv64 Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: sinan.lin at linux dot alibaba.com Target Milestone: --- I recently encountered several suboptimal cases with unnecessary sext.w in not/and/xor/or in rv64i. e.g. ``` int xor_2 (int x, int n) { return (x + 1) ^ n; } int not_2 (int x, int n) { return ~(x + n); } ``` gcc: ``` xor_2: addiw a0,a0,1 xor a0,a1,a0 sext.w a0,a0 ret not_2: addw a0,a0,a1 not a0,a0 sext.w a0,a0 ret ``` clang: ``` xor_2: addw a0, a0, a1 xor a0, a0, a1 ret not_2: addw a0, a0, a1 not a0, a0 ret ``` This case looks a bit similar to https://gcc.gnu.org/bugzilla//show_bug.cgi?id=106585 , where the X iterator is used in insn pattern.