Shift operation expansion


My target supports shift with amount 1 only i.e. to shift a value by 5 bits, I need to have a loop with shift in the body. Similarly for the unknown amount of shift we need to have a loop for shift.

  1. How can I insert this loop in DAG for shift operation?

  2. Is there a way where I can have a call to a function and later expand to the shift code?

Which would be the better way to implement this?



You can expand nodes into a serious of instructions, even with control flow. Take a look at how the PowerPC target lower atomic operations. Look for usesCustomDAGSchedInserter in, PPCTargetLowering::EmitAtomicBinary.