https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118727
--- Comment #12 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
(In reply to Tamar Christina from comment #11)
> (In reply to Xi Ruoyao from comment #10)
> > The difference from AArch64 and LoongArch64 is AArch64 has WIDEN_ABD, and
> > (with GCC 14.2):
> >
> > t.c:10:17: note: abd pattern recognized: patt_29 = (int) patt_30;
> > t.c:10:17: note: extra pattern stmt: patt_30 = .VEC_WIDEN_ABD (a.0_4,
> > b.1_6);
> > t.c:10:17: note: vect_is_simple_use: operand ABS_EXPR <c_17>, type of def:
> > internal
> > t.c:10:17: note: vect_is_simple_use: operand .VEC_WIDEN_ABD (a.0_4,
> > b.1_6), type of def: internal
> > t.c:10:17: note: vect_is_simple_use: operand ABS_EXPR <c_17>, type of def:
> > internal
> > t.c:10:17: note: vect_is_simple_use: operand .VEC_WIDEN_ABD (a.0_4,
> > b.1_6), type of def: internal
> > t.c:10:17: note: vect_recog_sad_pattern: detected: r_18 = _8 + r_23;
> > t.c:10:17: note: sad pattern recognized: patt_28 = SAD_EXPR <a.0_4, b.1_6,
> > r_23>;
> >
> > So a different code path is used:
> >
> > if (gimple_call_internal_fn (abd_stmt) == IFN_ABD)
> > {
> > ==> if (!vect_look_through_possible_promotion (vinfo, abd_oprnd0, <==
> > LoongArch code path
> > &unprom[0])
> > || !vect_look_through_possible_promotion (vinfo, abd_oprnd1,
> > &unprom[1]))
> > return NULL;
> > }
> > else if (gimple_call_internal_fn (abd_stmt) == IFN_VEC_WIDEN_ABD)
> > {
> > ==> unprom[0].op = abd_oprnd0; <== AArch64
> > code path (already fixed in PR108692)
> > unprom[0].type = TREE_TYPE (abd_oprnd0);
> > unprom[1].op = abd_oprnd1;
> > unprom[1].type = TREE_TYPE (abd_oprnd1);
> > }
> > else
> > return NULL;
>
> Yes, that's why I disabled the patterns to look...
>
> There's still something platform specific going on here.
> My guess is it's a difference between signess of char.
>
> on AArch64 char is unsigned and so the first cast is redundant.
It's not redundant: the test case has explicit "signed char".
> my guess is your testcase on uint8_t it'll pass.
I guess the fail of my twisted test case (if you refer to this) is caused by my
previous attempt (patch in comment 3).
> The inputs should be unsigned, but it needs to dig through the promotions to
> find intermediate casts inserted by e.g. vect_recog_over_widening_pattern
To me those redundant promotions should have been stripped away by
vect_recog_abd_pattern if we already ended up having an ABD here. Or we have a
missed-optimization with ABD anyway.