[llvm] [DAGCombiner] Add basic support for `trunc nsw/nuw` (PR #113808)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 30 21:31:08 PDT 2024
================
@@ -13807,23 +13809,25 @@ 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) {
+ 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.
return Op;
- } else if (OpBits < DestBits) {
- // Op is i32, Mid is i8, and Dest is i64. If Op has more than 24 sign
- // bits, just sext from i32.
- if (NumSignBits > OpBits-MidBits)
+ } else if (OpBits < DestBits) {
----------------
topperc wrote:
Drop else after return?
https://github.com/llvm/llvm-project/pull/113808
More information about the llvm-commits
mailing list