Hi, I hoped to post this in time for Monday’s cut off date, but circumstances delayed me until today. Hoping if possible this patch will still be able to go in.
This patch builds upon the change for PR65947, and reduces the amount of code produced in a vectorized condition reduction where operand 2 of the COND_EXPR is an assignment of a increasing integer induction variable that won't wrap. For example (assuming all types are ints), this is a match: last = 5; for (i = 0; i < N; i++) if (a[i] < min_v) last = i; Whereas, this is not because the result is based off a memory access: last = 5; for (i = 0; i < N; i++) if (a[i] < min_v) last = a[i]; In the integer induction variable case we can just use a MAX reduction and skip all the code I added in my vectorized condition reduction patch - the additional induction variables in vectorizable_reduction () and the additional checks in vect_create_epilog_for_reduction (). From the patch diff only, it's not immediately obvious that those parts will be skipped as there is no code changes in those areas. The initial value of the induction variable is force set to zero, as any other value could effect the result of the induction. At the end of the loop, if the result is zero, then we restore the original initial value. Cheers, Alan.
optimizeConditionReductions.patch
Description: Binary data