https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101596
Bug ID: 101596 Summary: vect_recog_mulhs_pattern could use incorrect precision to check shift count Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: linkw at gcc dot gnu.org Target Milestone: --- I happened to spot this when I was working to add one new pattern for Power10 divide extended. Now vect_recog_mulhs_pattern uses target_precision to check the scale_term is expected or not, it's wrong when the precision of the actual used new_type larger than target_precision, since we use the new_type for the internal function call. Test case: ``` #define N 32 typedef signed long long sLL; signed int si_a[N], si_b[N]; signed short sh_c[N]; #define SH_CNT 48 //#define SH_CNT 32 __attribute__ ((noipa)) void test_ui () { for (int i = 0; i < N; i++) sh_c[i] = ((sLL) si_a[i] * (sLL) si_b[i]) >> SH_CNT; } __attribute__ ((optimize ("O0"))) int main () { for (int i = 0; i < N; i++) { si_a[i] = 0x12345678; si_b[i] = 0x76543210; } test_ui (); for (int i = 0; i < N; i++) { signed short exp = ((sLL) si_a[i] * (sLL) si_b[i]) >> SH_CNT; if (exp != sh_c[i]) __builtin_abort (); } return 0; } ``` gcc test.c -mcpu=power10 -O2 -ftree-vectorize $ ./a.out Aborted (core dumped) test.c:13:21: note: vect_recog_mulhs_pattern: detected: _6 = _5 >> 48;