CQCL / hugr-llvm

http://crates.io/crates/hugr-llvm
Apache License 2.0
5 stars 2 forks source link

Consider doing bounds checks and branching on the result #102

Open croyzor opened 2 months ago

croyzor commented 2 months ago

In some places, we use a pattern (e.g. in the conversions trunc operations) where we run an llvm operaration, and do checks in parallel to see whether we can get away with using the result.

We could instead build a control flow graph where we perform the checks and then branch on the result

Originally posted by @mark-koch in https://github.com/CQCL/hugr-llvm/pull/94#pullrequestreview-2296155819

doug-q commented 2 months ago

My understanding is that our usual select pattern is best because a data dependency is better than a control flow dependency.

Select can be lowered to a conditional move instruction, which is usually better than a conditional branch instruction.

I don't think it really matters, I expect the optimiser can translate between the two representations. We should emit whichever is more convenient. I think that's select.

Note that we could certainly emit https://llvm.org/docs/LangRef.html#llvm-expect-intrinsic to tell LLVM that the bounds check will very likely succeed.