[llvm] [DAGCombiner] Add basic support for `trunc nsw/nuw` (PR #113808)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 31 08:00:16 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) {
----------------
dtcxzyw wrote:
Unlike in InstCombine, we don't infer poison generating flags in SDAG. Without recursive analysis we may miss some optimization opportunities.
https://github.com/llvm/llvm-project/pull/113808
More information about the llvm-commits
mailing list