http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54272
Bug #: 54272 Summary: [SH] Add support for addv / subv instructions Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: target AssignedTo: olege...@gcc.gnu.org ReportedBy: olege...@gcc.gnu.org Target: sh*-*-* The addv and subv instructions can be used for at least two things: 1) Implementing trapping signed integer arithmetic (-ftrapv) Currently, for the SH target, trapping insns (e.g. addvsi3) are supposed to be implemented by library functions in libgcc. However, it seems that for addvsi3 and subvsi3 normal addsi3 and subsi3 patterns are expanded by the middle-end, which is wrong. Probably PR 35412 is related to this. After adding the addvsi3 pattern to sh.md, the middle-end picks it up as expected. However, I'm unsure how to realize the actual trapping part. The library functions in libgcc just invoke 'abort ()' on overflow. I think the trapa instruction could be used here to get relatively compact code, like: addv r4,r5 bf 0f trapa #??? 0: However, I have no idea which trapa immediate value would be suitable for this, especially for GNU/Linux environments. Maybe it's better to make this user configurable through an -m option? 2) Saturating arithmetic E.g. the pattern ssaddsi3 can be implemented with the following sequence (if I'm not mistaken): mov.l .Lintmin, r1 ! r1 = 0x80000000 cmp/pz r4 ! only one sign matters in case of overflow negc r1,r2 ! r5 = 0 - r1 - T addv r4,r5 bf 0f mov r2,r5 0: However, I don't know how to make the middle-end expand patterns that contain 'ss_plus'. It seems that other targets provide the ssaddsi3 pattern through target specific built-in functions only...