[LLVMdev] Target description flags for instructions which may trap

Richard Osborne richard at xmos.com
Thu Oct 30 07:08:15 PDT 2008

What are the correct target description side effect flags for 
instructions which may trap (e.g. divide / remainder)? The divide 
instruction in my backend currently has no flags set. I've enabled the 
MachineLICM pass and it's causing a miscompilation by hoisting a divide 
by zero instruction out of the loop. Clearly this pass needs to be made 
aware that this is not safe. The current test in the MachineLICM is as 

  // Ignore stuff that we obviously can't hoist.
  if (TID.mayStore() || TID.isCall() || TID.isReturn() || TID.isBranch() ||
    return false;

Setting hasSideEffects = 1 seems to work, but I'm not sure if that's the 
intended use of this flag. I notice that divide / remainder instructions 
for other architectures are not marked in this way. Also it is also 
pessimistic: if the divisor is know to be non zero then the instruction 
couldn't trap and would be safe to motion.

Richard Osborne | XMOS

More information about the llvm-dev mailing list