This is an archive of the discontinued LLVM Phabricator instance.

Only unswitch loops with uniform conditions
ClosedPublic

Authored by rampitec on Mar 9 2017, 3:33 PM.

Details

Summary

Loop unswitching can be extremely harmful for a SIMT target. In case
if hoisted condition is not uniform a SIMT machine will execute both
clones of a loop sequentially. Therefor LoopUnswitch checks if the
condition is non-divergent.

Since DivergenceAnalysis adds an expensive PostDominatorTree analysis
not needed for non-SIMT targets a new option is added to avoid unneded
analysis initialization. The method getAnalysisUsage is called when
TargetTransformInfo is not yet available and we cannot use it here.
For that reason a new field DivergentTarget is added to PassManagerBuilder
to control the behavior and set this field from a target.

Diff Detail

Repository
rL LLVM

Event Timeline

rampitec created this revision.Mar 9 2017, 3:33 PM
efriedma added inline comments.
test/Transforms/LoopUnswitch/AMDGPU/divergent-unswitch.ll
2 ↗(On Diff #91226)

This will break if the user compiles LLVM with only the AMDGPU target enabled.

rampitec added inline comments.Mar 9 2017, 3:44 PM
test/Transforms/LoopUnswitch/AMDGPU/divergent-unswitch.ll
2 ↗(On Diff #91226)

Indeed. I guess I can remove non AMDGPU test as the first test already checks that unswitch happens.

rampitec updated this revision to Diff 91234.Mar 9 2017, 4:00 PM

Removed non-AMD part of the test. It still tests both when unswitching is needed and inhibited, but works if AMDGPU is the only enabled target.

rampitec marked 2 inline comments as done.Mar 9 2017, 4:00 PM
vpykhtin accepted this revision.Mar 16 2017, 1:33 PM

LGTM.

This revision is now accepted and ready to land.Mar 16 2017, 1:33 PM
This revision was automatically updated to reflect the committed changes.