This is an archive of the discontinued LLVM Phabricator instance.

[DebugInfo][LCSSA] Rewrite pre-existing debug values outside loop
ClosedPublic

Authored by dstenb on Oct 11 2018, 2:10 AM.

Details

Summary

Extend LCSSA so that debug values outside loops are rewritten to
use the PHI nodes that the pass creates.

This fixes PR39019. In that case, we ran LCSSA on a loop that
was later on vectorized, which left us with something like this:

for.cond.cleanup:
  %add.lcssa = phi i32 [ %add, %for.body ], [ %34, %middle.block ]
  call void @llvm.dbg.value(metadata i32 %add,
  ret i32 %add.lcssa

for.body:
  %add =
  [...]
  br i1 %exitcond, label %for.cond.cleanup, label %for.body

which later resulted in the debug.value becoming undef when
removing the scalar loop (and the location would have probably
been wrong for the vectorized case otherwise).

As we now may need to query the AvailableVals cache more than
once for a basic block, FindAvailableVals() in SSAUpdaterImpl is
changed so that it updates the cache for blocks that we do not
create a PHI node for, regardless of the block's number of
predecessors. The debug value in the attached IR reproducer
would not be properly rewritten without this.

Debug values residing in blocks where we have not inserted any
PHI nodes are currently left as-is by this patch. I'm not sure
what should be done with those uses.

Diff Detail

Repository
rL LLVM

Event Timeline

dstenb created this revision.Oct 11 2018, 2:10 AM
jmorse added a subscriber: jmorse.Oct 11 2018, 2:58 AM
aprantl accepted this revision.Oct 11 2018, 8:40 AM

Thanks, this looks reasonable to me.

This revision is now accepted and ready to land.Oct 11 2018, 8:40 AM
mattd added a comment.EditedOct 11 2018, 8:46 AM

This LGTM.

lib/Transforms/Utils/LCSSA.cpp
117 ↗(On Diff #169172)

Can we move this container and accompanying findDbgValue call closer to where it's used, around line 208, or is it necessary that we get the debug value early before we create the new PHIs?

mattd accepted this revision.Oct 11 2018, 8:48 AM
dstenb updated this revision to Diff 169384.Oct 12 2018, 6:12 AM

Move DbgValues and the findDbgValues() call closer to the use.

dstenb added inline comments.Oct 12 2018, 6:19 AM
lib/Transforms/Utils/LCSSA.cpp
117 ↗(On Diff #169172)

I have moved it now! We should not drop nor add any metadata uses of I between this and the use, so it should be equivalent.

The only reason I put it here was to keep the collection of I's uses near each other, but yes, it is probably better to move DbgValues closer to its use!

mattd added inline comments.Oct 12 2018, 9:08 AM
lib/Transforms/Utils/LCSSA.cpp
117 ↗(On Diff #169172)

Great, thanks!

Thanks for the reviews! I'm planning on submitting this shortly.

This revision was automatically updated to reflect the committed changes.