[cfe-dev] How to configure clang, to get const functions out of the loop (like on FreeBSD) ?
Nat! via cfe-dev
cfe-dev at lists.llvm.org
Thu Aug 17 08:18:20 PDT 2017
I think I know now, what the problem is. This summary is also in
https://bugs.llvm.org/show_bug.cgi?id=34208#c4 preceeded by a lot of
other comments, how I got there.
Note: The loop header is essentially the loop body in this test case.
Summary
=======
A plain C function `bar` answers NO to I.mayThrow(), but YES to
isGuaranteedToTransferExecutionToSuccessor(&*I). This poisons the whole
loop header as SafetyInfo->HeaderMayThrow gets set to YES.
(See: llvm::computeLoopSafetyInfo
https://github.com/llvm-mirror/llvm/blob/987e30d8673d9d1a683ef811e9b7e32d2fadeb8a/lib/Transforms/Scalar/LICM.cpp#L496)
When llvm::canSinkOrHoistInst asks llvm::isGuaranteedToExecute about foo
(via isSafeToExecuteUnconditionally), this poisioning of the loop header
inhibits the hoisting of this const function (with constant argument).
(https://github.com/llvm-mirror/llvm/blob/987e30d8673d9d1a683ef811e9b7e32d2fadeb8a/lib/Transforms/Scalar/LICM.cpp#L483)
```
if (Inst.getParent() == CurLoop->getHeader())
// If there's a throw in the header block, we can't guarantee we'll
reach
// Inst.
return !SafetyInfo->HeaderMayThrow;
```
The setting SafetyInfo->HeaderMayThrow is now overly broad. Ideally I
think loop headers should be split into a non-throw part and a throw part.
As an alternative non-throwing const Functions with constant arguments,
could always be considered hoistable regardless of
SafetyInfo->HeaderMayThrow.
---
So what to do next ?
Ciao
Nat!
More information about the cfe-dev
mailing list