[LLVMdev] Target description flags for instructions which may trap

Evan Cheng evan.cheng at apple.com
Thu Oct 30 08:57:01 PDT 2008

On Oct 30, 2008, at 7:08 AM, Richard Osborne wrote:

> 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
> follows:
>  // Ignore stuff that we obviously can't hoist.
>  if (TID.mayStore() || TID.isCall() || TID.isReturn() ||  
> TID.isBranch() ||
>      TID.hasUnmodeledSideEffects())
>    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.

All such side effects that are not explicitly modeled fall under the  
hasSideEffects bucket. It's something you can use now.

That said, there has been a lot of interest in enhancing LLVM with  
modeling trapping instructions. You should do a search on llvmdev.


> Richard Osborne | XMOS
> http://www.xmos.com
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

More information about the llvm-dev mailing list