This is an archive of the discontinued LLVM Phabricator instance.

[X86] Teach combineLoopSADPattern to handle cases where there is no loop and the add has two absolute difference inputs
ClosedPublic

Authored by craig.topper on Aug 15 2018, 3:43 PM.

Details

Summary

Previously we asumed a vector reduction add is part of a loop and one of the input is a phi. But the code in SelectionDAGBuilder that sets vector reduction flag handles more cases than that. It just requires that the use chain ends in a horizontal reduction. And there are no other uses. This means it can handle unrolled reduction loops.

If the initial value of the reduction was 0, an unrolled loop would begin with a vector reduction add that has two sad inputs. Previously we would only transform one side of the add, but for this case we need to transform both sides.

I've created a lambda to reuse some of the code for both sides. And fixed the variables names to remove reference to "phi".

I believe madd loop pattern probably has the same issue, but my motivating case is sad.

I can pre-commit the current codegen as part of the review if you want. I'll commit it in stages either way.

Diff Detail

Repository
rL LLVM