This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombiner] Fold step_vector with add/mul/shl
ClosedPublic

Authored by junparser on Apr 7 2021, 10:33 PM.

Details

Summary

This patch implements some DAG combines for STEP_VECTOR:
add step_vector(C1), step_vector(C2) -> step_vector(C1+C2)
add (add X step_vector(C1)), step_vector(C2) -> add X step_vector(C1+C2)
mul step_vector(C1), C2 -> step_vector(C1*C2)
shl step_vector(C1), C2 -> step_vector(C1<<C2)

TestPlan: check-llvm

Diff Detail

Event Timeline

junparser created this revision.Apr 7 2021, 10:33 PM
junparser requested review of this revision.Apr 7 2021, 10:33 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 7 2021, 10:33 PM

The folds here look sensible to me! I just have a minor comment about the add fold.

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
2523

Is it worth adding an assert here like this?

assert(N1.getOperand(0).getValueType() == N0.getOperand(1)->getOperand(0).getValueType());
junparser added inline comments.Apr 11 2021, 7:34 PM
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
2523

Yep, always worth to add such assert. I'll add later.

junparser updated this revision to Diff 336732.Apr 11 2021, 8:10 PM

Address comments.

This revision is now accepted and ready to land.Apr 15 2021, 2:55 AM
This revision was automatically updated to reflect the committed changes.