3

Please let me know how to detect the presence of instructions with nsw and nuw flags set on them in the LLVM IR.

Adarsh Konchady
  • 2,577
  • 5
  • 30
  • 50

1 Answers1

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