This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine][CodeGenPrep] Create llvm.uadd.with.overflow in CGP.
ClosedPublic

Authored by sanjoy on Apr 7 2015, 8:32 PM.

Details

Summary

This change moves creating calls to llvm.uadd.with.overflow to from
InstCombine to CodeGenPrep. Combining overflow check patterns into
calls to the said intrinsic in InstCombine inhibits optimization because
it introduces an intrinsic call that not all other transforms and
analyses understand.

Depends on D8888.

Diff Detail

Repository
rL LLVM

Event Timeline

sanjoy updated this revision to Diff 23391.Apr 7 2015, 8:32 PM
sanjoy retitled this revision from to [InstCombine][CodeGenPrep] Create llvm.uadd.with.overflow in CGP..
sanjoy updated this object.
sanjoy edited the test plan for this revision. (Show Details)
sanjoy added reviewers: majnemer, atrick.
sanjoy added a subscriber: Unknown Object (MLST).
majnemer edited edge metadata.Apr 7 2015, 8:51 PM

Just some quick drive-by comments.

lib/CodeGen/CodeGenPrepare.cpp
756–757 ↗(On Diff #23391)

We should probably have an m_Instruction.

778 ↗(On Diff #23391)

Please capitalize sink.

atrick edited edge metadata.Apr 7 2015, 9:36 PM

What happens if the 'add' and 'cmp' are in different blocks? If we're doing this for codegen, I don't think we want to reorder flag producing instructions.

sanjoy updated this revision to Diff 23393.Apr 7 2015, 9:43 PM
sanjoy edited edge metadata.

Address David's comments:

  • introduce m_Instruction and use it
  • fix comment
sanjoy updated this revision to Diff 23401.Apr 7 2015, 11:36 PM

Address Andy's review:

  • do the transform only if the call to uadd.with.overflow can be inserted in the same basic block as the compare. This prevents us from moving flag-producing instructions.
  • try sinking an icmp before trying to combine it.
  • add test cases that exercise both of the above.
sanjoy added a comment.Apr 9 2015, 6:49 PM

gentle ping.

atrick added a comment.Apr 9 2015, 7:35 PM

The logic looks good. The purpose of the lambda escapes me.

lib/CodeGen/CodeGenPrepare.cpp
754–755 ↗(On Diff #23401)

What am I missing here? Are we going to need a lambda somewhere?

sanjoy added inline comments.Apr 9 2015, 8:24 PM
lib/CodeGen/CodeGenPrepare.cpp
754–755 ↗(On Diff #23401)

This is because I was going to add a CombineSAddWithOverflow (a separate lambda) in the future. Right now this is not required, and I'll remove it.

sanjoy updated this revision to Diff 23569.Apr 9 2015, 11:51 PM
  • Address Andy's review -- remove the nested lambda.
atrick accepted this revision.Apr 9 2015, 11:57 PM
atrick edited edge metadata.

LGTM

This revision is now accepted and ready to land.Apr 9 2015, 11:57 PM
This revision was automatically updated to reflect the committed changes.