[LoopVectorize] Enable integer Mul and Add as select reduction patterns
This patch vectorizes Phi node loop reductions for select's whos condition
comes from a floating-point comparison, with its operands being integers
for Add, Sub, and Mul reductions.
Example:
int foo(float *x, int n) {
int sum = 0;
for (int i=0; i<n; ++i) {
float elem = x[i];
if (elem > 0) {
sum += 2;
}
}
return sum;
}This would previously fail to vectorize due to the integer reduction.
Unfortunately integer flags aren't being propagated here. After having a quick look around the issue appears non-trivial as fast-math flags are propagated for the floating point case with a disclaimer. In RecurrenceDescriptor::AddReductionVar just after where the changes to RecurrenceDescriptor::isConditionalRdxPattern were made:
// FIXME: FMF is allowed on phi, but propagation is not handled correctly. if (isa<FPMathOperator>(ReduxDesc.getPatternInst()) && !IsAPhi) { FastMathFlags CurFMF = ReduxDesc.getPatternInst()->getFastMathFlags(); if (auto *Sel = dyn_cast<SelectInst>(ReduxDesc.getPatternInst())) { // Accept FMF on either fcmp or select of a min/max idiom. // TODO: This is a hack to work-around the fact that FMF may not be // assigned/propagated correctly. If that problem is fixed or we // standardize on fmin/fmax via intrinsics, this can be removed.After a look around for methods of propagating the IR flags I'm not quite sure how to proceed.