[llvm] [DAGCombiner] Add basic support for `trunc nsw/nuw` (PR #113808)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 31 07:18:32 PDT 2024
================
@@ -13807,23 +13809,27 @@ SDValue DAGCombiner::visitSIGN_EXTEND(SDNode *N) {
unsigned OpBits = Op.getScalarValueSizeInBits();
unsigned MidBits = N0.getScalarValueSizeInBits();
unsigned DestBits = VT.getScalarSizeInBits();
- unsigned NumSignBits = DAG.ComputeNumSignBits(Op);
- if (OpBits == DestBits) {
- // Op is i32, Mid is i8, and Dest is i32. If Op has more than 24 sign
- // bits, it is already ready.
- if (NumSignBits > DestBits-MidBits)
+ if (N0->getFlags().hasNoSignedWrap() ||
+ DAG.ComputeNumSignBits(Op) > OpBits - MidBits) {
----------------
goldsteinn wrote:
Still think the way to do this is just set `nsw`/`nuw` in `visitTRUNC` and drop the `compute...`
https://github.com/llvm/llvm-project/pull/113808
More information about the llvm-commits
mailing list