This is an archive of the discontinued LLVM Phabricator instance.

[Polly] Runtime check elimination
ClosedPublic

Authored by jdoerfert on Sep 10 2015, 9:04 AM.

Details

Summary
Hoist runtime checks in the loop nest if they will cause an exception
like event. Such events are recognized as blocks with an unreachable
terminator possibly (but only) preceded by a function calls which
will never return. No other instructions are allowed in these
exception blocks and they have to be executed conditionally. As there
won't be a statement build for these blocks and the control that flows
into them is never flowing into another block we basically model the
SCoP as if they would never be executed. Also in the generated AST and
consequently IR they will simply disappear. To be sound we add the
assumption that no such block can ever be executed to our assumed
context.

+ ubsan out of bound handling will be treated as exception block.

Diff Detail

Event Timeline

jdoerfert updated this revision to Diff 34452.Sep 10 2015, 9:04 AM
jdoerfert retitled this revision from to [Polly] Runtime check elimination.
jdoerfert added reviewers: grosser, Meinersbur.
jdoerfert updated this object.
jdoerfert added a subscriber: Restricted Project.
grosser accepted this revision.Sep 10 2015, 10:15 AM
grosser edited edge metadata.

Hi Johannes,

this patch looks nice and clean! Very cool. Just some smaller comments inline. Besides those, I think it would be good to add an ASAN test case and a multi-dimensional array test case.

Best,
Tobias

lib/Analysis/ScopDetection.cpp
320

Also, It does not seem to matter what the instructions do. As long as the block is unreachable, I think we can decide to ignore it.

322

I generally prefer to have 'return false' as the default at the end and then only return true for the cases we indeed want to handle.

Also, it is unclear to me why the last three checks are needed. You seem to very detailed check that this is really an exception block. I would just handle anything that ends in an unreachable as such.

401

I would not check the content of an exception block at all. It will anyhow never be executed.

929

I would skip exception blocks already here. There content does not really matter, no?

test/ScopInfo/BoundChecks/single-loop.ll
32

Nice!

This revision is now accepted and ready to land.Sep 10 2015, 10:15 AM
Meinersbur edited edge metadata.Sep 10 2015, 10:31 AM

I am missing a definition (in the source) what a "exception-like block" is and why it can be ignored.

Also, why is UBSan special that it cannot be handled like other exception-like blocks?

Can you give an motivating example?

include/polly/ScopDetection.h
349

Wouldn't it be better to define static methods as normal functions unless it needs access private static members?

lib/Analysis/ScopDetection.cpp
299

Judging from when the code calling this, this has nothing to do with exceptions (i.e. "invoke" statement), but just error condition checking.

300

empty line?

305

Isn't it possible that __ubsan_handle_out_of_bounds is merged with other code on the same condition?

323

Could you elaborate why all these conditions are necessary?

401

isValidExceptionBlock also requires that the block has an unreachable terminator, which probably doesn't matter here.

Also, what about such (stupid) code?

abort()
__ubsan_handle_out_of_bounds()
br somewhere_else
710

unrelated change

jdoerfert marked 9 inline comments as done.Sep 10 2015, 10:52 AM

@grosser @Meinersbur Thanks for the comments! I'll push an updated value directly into the repo.

lib/Analysis/ScopDetection.cpp
300

Yes.

305

That does not matter for the whole scheme. We will never model or execute the block anyway.

323

Simplified and listed conditions in header description.

401

Simplified this wrt to the comments from Tobias.

jdoerfert closed this revision.Sep 10 2015, 11:07 AM
jdoerfert marked an inline comment as done.