On Thu, Jan 12, 2023 at 09:31:23PM +0100, Jakub Jelinek via Gcc-patches wrote: > On Thu, Jan 12, 2023 at 08:55:32PM +0100, Jakub Jelinek via Gcc-patches wrote: > > > > So, the following patch for the NOP_EXPR cases checks just in case that > > > > it is from integral type and more importantly checks it is a widening > > > > conversion, and then next to it also allows op0 to be just unsigned, > > > > promoted or not, as that is what the C FE will do for those cases too > > > > and I believe it must work - either the division/modulo common type > > > > will be that unsigned type, then we can shorten and don't need to worry > > > > about UB, or it will be some wider signed type but then it can't be most > > > > negative value of the wider type. > > > > > > Why not use the same condition in C and C++? > > > > I can test that. Do you mean change the C FE to match the patched C++ > > or change C++ FE to just test TYPE_UNSIGNED (orig_op0)? > > I think both should work, though what I wrote perhaps can shorten in more > > cases. Can try to construct testcases where it differs... > > E.g. > int f1 (int x, int y) { return (unsigned) x / y; } > unsigned short f2 (unsigned short x, unsigned short y) { return (unsigned) x > / y; } > unsigned int f3 (unsigned int x, unsigned int y) { return (long long) x / y; } > C++ FE before and after the patch shortens the division in f2 and f3, > C FE shortens only in f2. So using the C FE condition would be a regression > for C++. > > Therefore I'm going to test following patch:
Bootstrapped/regtested successfully on x86_64-linux and i686-linux. Jakub