<div dir="ltr"><div>Hi Tim,</div><div><br></div><div>Thank you a lot for your reply. So IIUC, optimization passes in opt do not reorder IR instructions, only passes in llc that move MIR instructions around. Is it correct?</div><div><br></div><div>On the back-end (llc) side, hasSideEffects might prevent some reordering. But I just learn about TargetInstrInfo::isSchedulingBoundary. Can you tell me what are the differences between the two please?</div><div><br></div><div>Thank you very much (again),</div><div><br></div><div><div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Son Tuan Vu</div></div></div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Sep 17, 2018 at 12:13 PM Tim Northover <<a href="mailto:t.p.northover@gmail.com">t.p.northover@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
On Sun, 16 Sep 2018 at 22:02, Son Tuan VU via llvm-dev<br>
<<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
> I want to add a custom intrinsic to the LLVM IR which would be lowered into a pseudo instruction since it doesn't correspond to any real instruction defined by the architecture. The speciality of this intrinsic/pseudo instruction that it should behave like a scheduling barrier: every instruction before the intrinsic has to be emitted before the intrinsic, the same goes for all instructions after the intrinsic, and this should hold after any optimization in opt and llc.<br>
<br>
That's going to be very difficult. LLVM allows intrinsics to have<br>
unmodelled side-effects that prevent reordering with instructions that<br>
might also have side-effects (including loads and stores). But it<br>
assumes that simple arithmetic instructions (like "add") have no<br>
effect other than what's in the IR so they can be freely moved past<br>
anything.<br>
<br>
The difference occasionally comes up when people want begin-benchmark<br>
and end-benchmark intrinsics, but really the whole concept of what's<br>
calculated between two points is pretty fuzzy.<br>
<br>
> Which bit should be set to 1? isBarrier or hasSideEffects or both?<br>
<br>
hasSideEffects is the closest, with the caveats above.<br>
<br>
isBarrier has nothing to do with fences. It's applied to unconditional<br>
branches so that LLVM knows that a basic-block ending with that<br>
instruction won't fall-through.<br>
<br>
Cheers.<br>
<br>
Tim.<br>
</blockquote></div>