-
Notifications
You must be signed in to change notification settings - Fork 14.6k
[RISCV] Fold (add (srl x, n), (srl x, n)) into (srl x, n-1) #144507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This patch adds a new fold that will turn (add (srl x, n), (srl x, n)) into (srl x, n-1) when bit n-1 is known to be zero in x. This could perhaps be moved to generic DAGCombiner in the future, but this patch adds it as a RISCV specific combine. For RISCV it typically trigger for DAG nodes like this that may be created by the legalizer: t1: i32 = srl RISCVISD::READ_VLENB:i32, Constant:i32<2> t2: i32 = add t1, t1 Got the idea when working on a solution for #141034, as it may avoid some regressions otherwise caused by the fix being prepared for that issue.
@@ -15240,12 +15240,42 @@ static SDValue combineAddOfBooleanXor(SDNode *N, SelectionDAG &DAG) { | |||
N0.getOperand(0)); | |||
} | |||
|
|||
// Try to turn (add (srl x, n), (srl x, n)) into (srl x, n-1). | |||
// | |||
// This combine could perhaps be moved to DAGCombiner. For RISCV this kind of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RISCV should be spelled RISC-V in comments. It's a trademark.
I may have an alternate proposal for this patch. Investigating. |
… (C0 + C1)) in getNode. This is an alternative to the DAGCombine proposed in llvm#144507.
My alternate proposal #144565 which covers the READ_VLENB cases. |
Thanks! That seems like a better solution. I'll abandon this. |
…ale * (C0 + C1)) in getNode. (llvm#144565) We already have shl/mul vscale related folds in getNode. This is an alternative to the DAGCombine proposed in llvm#144507.
This patch adds a new fold that will turn
(add (srl x, n), (srl x, n))
into
(srl x, n-1)
when bit n-1 is known to be zero in x.
This could perhaps be moved to generic DAGCombiner in the future, but this patch adds it as a RISCV specific combine. For RISCV it typically trigger for DAG nodes like this that may be created by the legalizer:
t1: i32 = srl RISCVISD::READ_VLENB:i32, Constant:i32<2>
t2: i32 = add t1, t1
Got the idea when working on a solution for #141034, as it may avoid some regressions otherwise caused by the fix being prepared for that issue.