Please let me know how to detect the presence of instructions with nsw and nuw flags set on them in the LLVM IR.
Asked
Active
Viewed 1,585 times
1 Answers
3
OverflowingBinaryOperator
has the hasNoUnsignedWrap
and hasNoSignedWrap
predicates for this purpose.
More specifically, given some instruction ii
:
if (OverflowingBinaryOperator *op = dyn_cast<OverflowingBinaryOperator>(ii)) {
if (op->hasNoUnsignedWrap())
errs() << " has nuw\n";
else if (op->hasNoSignedWrap())
errs() << " has nsw\n";
}
}

Eli Bendersky
- 263,248
- 89
- 350
- 412