-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[DAGCombiner][RISCV] Prefer to sext i32 non-negative values #65984
Conversation
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.
LGTM
InstCombine does the same thing. Do we need a reverse transform to turn zext into sext explicitly? Or perhaps an isel pattern? |
I think you mean ISel.
It is unsafe to turn |
visitSExt in InstCombine will turn sext into zext. That code will happen before DAGCombine. The DAGCombine change will only effect sext that is created during SelectionDAG. sext that already existed in IR may get changed by InstCombine. So my question was do we need to change zext to sext if the sign bit of the input is known to be 0 by computeKnownBits. |
llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp Lines 1375 to 1377 in c464896
|
Diff: main...dtcxzyw:llvm-project:zext-to-sext It seems better to sext a non-negative value on riscv64. But this change broke some regression tests. |
By default, `DAGCombiner` folds `sext x` to `zext x` when `x` is non-negative. It will generate redundant `zext` inst seq on riscv64 (typically `slli (srli x, 32), 32`). godbolt: https://godbolt.org/z/osf6adP1o This patch applies the transform iff `zext` is **cheaper** than `sext`.
By default,
DAGCombiner
foldssext x
tozext x
whenx
is non-negative. It will generate redundantzext
inst seq on riscv64 (typicallyslli (srli x, 32), 32
).godbolt: https://godbolt.org/z/osf6adP1o
This patch applies the transform iff
zext
is cheaper thansext
.