[llvm] [DAGCombiner] Add basic support for `trunc nsw/nuw` (PR #113808)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 28 17:27:56 PDT 2024
================
@@ -2572,14 +2572,23 @@ bool TargetLowering::SimplifyDemandedBits(
}
case ISD::TRUNCATE: {
SDValue Src = Op.getOperand(0);
+ SDNodeFlags Flags = Op->getFlags();
// Simplify the input, using demanded bit information, and compute the known
// zero/one bits live out.
unsigned OperandBitWidth = Src.getScalarValueSizeInBits();
APInt TruncMask = DemandedBits.zext(OperandBitWidth);
if (SimplifyDemandedBits(Src, TruncMask, DemandedElts, Known, TLO,
- Depth + 1))
+ Depth + 1)) {
+ if (Flags.hasNoSignedWrap() || Flags.hasNoUnsignedWrap()) {
+ // Disable the nsw and nuw flags. We can no longer guarantee that we
+ // won't wrap after simplification.
+ Flags.setNoSignedWrap(false);
+ Flags.setNoUnsignedWrap(false);
+ Op->setFlags(Flags);
----------------
arsenm wrote:
The API for SDNodeFlags is much worse than FastMathFlags. Can we get a wrapper with bit operations so you can just do a ~WrapFlags?
https://github.com/llvm/llvm-project/pull/113808
More information about the llvm-commits
mailing list