This is an archive of the discontinued LLVM Phabricator instance.

Refine the notion of MayThrow in LICM to include a header specific version
ClosedPublic

Authored by reames on Dec 18 2014, 11:07 AM.

Details

Summary

In LICM, we have a check for an instruction which is guaranteed to execute and thus can't introduce any new faults if moved to the preheader. To handle a function which might unconditionally throw when first called, we check for any potentially throwing call in the loop and give up.

This is unfortunate when the potentially throwing condition is down a rare path. It prevents essentially all LICM of potentially faulting instructions where the faulting condition is checked outside the loop. It also greatly diminishes the utility of loop unswitching since control dependent instructions - which are now likely in the loops header block - will not be lifted by subsequent LICM runs.

define void @nothrow_header(i64 %x, i64 %y, i1 %cond) {
; CHECK-LABEL: nothrow_header
; CHECK-LABEL: entry
; CHECK: %div = udiv i64 %x, %y
; CHECK-LABEL: loop
; CHECK: call void @use(i64 %div)
entry:

br label %loop

loop: ; preds = %entry, %for.inc

%div = udiv i64 %x, %y
br i1 %cond, label %loop-if, label %exit

loop-if:

call void @use(i64 %div)
br label %loop

exit:

ret void

}

The current patch really only helps with non-memory instructions (i.e. divs, etc..) since the maythrow call down the rare path will be considered to alias an otherwise invariant load.

Diff Detail

Repository
rL LLVM

Event Timeline

reames updated this revision to Diff 17454.Dec 18 2014, 11:07 AM
reames retitled this revision from to Refine the notion of MayThrow in LICM to include a header specific version.
reames updated this object.
reames edited the test plan for this revision. (Show Details)
reames added reviewers: hfinkel, nlewycky.
reames set the repository for this revision to rL LLVM.
reames added a subscriber: Unknown Object (MLST).
reames updated this revision to Diff 17457.Dec 18 2014, 11:11 AM

Forgot to include the tests in the last version

hfinkel accepted this revision.Dec 23 2014, 4:55 PM
hfinkel edited edge metadata.

LGTM.

This revision is now accepted and ready to land.Dec 23 2014, 4:55 PM
This revision was automatically updated to reflect the committed changes.