Skip to content

[DAG] SelectionDAGBuilder - add ISD::TRUNCATE NSW/NUW flags support and initial testing #89237

@RKSimon

Description

@RKSimon

This should do it:

void SelectionDAGBuilder::visitTrunc(const User &I) {
  // TruncInst cannot be a no-op cast because sizeof(src) > sizeof(dest).
  SDValue N = getValue(I.getOperand(0));
  EVT DestVT = DAG.getTargetLoweringInfo().getValueType(DAG.getDataLayout(),
                                                        I.getType());

  SDNodeFlags Flags;
  if (auto *TI = dyn_cast<TruncInst>(&I)) {
    Flags.setNoSignedWrap(TI->hasNoSignedWrap());
    Flags.setNoUnsignedWrap(TI->hasNoUnsignedWrap());
  }

  setValue(&I, DAG.getNode(ISD::TRUNCATE, getCurSDLoc(), DestVT, N, Flags));
}

But then we need to add a lot of general test coverage: https://alive2.llvm.org/ce/z/-wXZPE (a couple of trivial examples)

CC @elhewaty @nikic @goldsteinn

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions