This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Use replaceOperand() in more places
ClosedPublic

Authored by nikic on Feb 3 2020, 12:49 PM.

Details

Summary

This is a followup to D73803, which uses the replaceOperand() helper in more places.

In some cases, I have instead replaced multiple setOperand() calls with creating a new instruction (those cases where we set multiple operands, and there is nothing subtle going on with preservation of instruction flags or so). That seems to be more idiomatic nowadays. This is also what causes the test changes. Is this reasonable, or do we prefer in-place modification here?

Diff Detail

Event Timeline

nikic created this revision.Feb 3 2020, 12:49 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 3 2020, 12:49 PM
spatel added a comment.Feb 4 2020, 9:28 AM

Seems like good cleanup. I suspect the implementation differences are based on historical prefs, but it's possible there's some compile-time perf difference in new instruction vs. recycling. I doubt that would rise above the noise, but to be safe, I'd split this up:

  1. Make the select swapValues() changes - should be NFC.
  2. Change the multi-operand set patterns to Create*.
  3. Use replaceOperand().
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
1383–1385

This is different than the CreateXor() changes below because of overflow flag propagation? If yes, it's worth a code comment.

llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
2402

Better to make this an independent patch.

2781

Similar to above - pre-commit the swapValues() diff? Or maybe better to create a new instruction here similar to the earlier binop changes?

nikic updated this revision to Diff 243372.Feb 8 2020, 8:12 AM
nikic marked 3 inline comments as done.

Rebase

nikic marked an inline comment as done.Feb 8 2020, 8:14 AM

I've now landed the swapValues use (rG9d03b7d0d008) and the creation of new insts (rGd4627b90a046) separately, and rebased this patch, so it now only includes the changes related to replaceOperand() use.

llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
1383–1385

That's right. I've now added a comment to indicate this.

spatel accepted this revision.Feb 11 2020, 8:17 AM

LGTM

This revision is now accepted and ready to land.Feb 11 2020, 8:17 AM
This revision was automatically updated to reflect the committed changes.