This is an archive of the discontinued LLVM Phabricator instance.

[Profile] Lower expect intrinsic properly for select instruction
ClosedPublic

Authored by davidxl on Sep 1 2016, 4:18 PM.

Details

Summary

builtin expect passed to select instruction gets ignored. This patch fixes the issue.

Diff Detail

Repository
rL LLVM

Event Timeline

davidxl updated this revision to Diff 70091.Sep 1 2016, 4:18 PM
davidxl retitled this revision from to [Profile] Lower expect intrinsic properly for select instruction.
davidxl updated this object.
davidxl added reviewers: vsk, spatel.
davidxl added a subscriber: llvm-commits.
davidxl updated this revision to Diff 70133.Sep 1 2016, 9:43 PM

Make the implementation more efficient -- avoid traversing IR twice.

spatel added inline comments.Sep 2 2016, 8:07 AM
lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
86 ↗(On Diff #70133)

Neat trick. :)
But can you add a comment and/or rename BI, so it is clear that this isn't strictly for a 'BI' (BranchInst) any more?

159 ↗(On Diff #70133)

Fix comment to indicate why we are using reverse iterator (and that we're also handling selects in this loop).

160 ↗(On Diff #70133)

Use 'auto' to avoid 80-col ugliness?

test/Transforms/LowerExpectIntrinsic/basic.ll
276–287 ↗(On Diff #70133)

Minimize test?

define i32 @test10(i64 %t6) {
  %t7 = call i64 @llvm.expect.i64(i64 %t6, i64 0)
  %t8 = icmp ne i64 %t7, 0
  %t9 = select i1 %t8, i32 42, i32 43
  ret i32 %t9
}
davidxl updated this revision to Diff 70208.Sep 2 2016, 12:26 PM
davidxl marked 3 inline comments as done.

Addressed review comments.

spatel accepted this revision.Sep 2 2016, 12:33 PM
spatel edited edge metadata.

LGTM.

This revision is now accepted and ready to land.Sep 2 2016, 12:33 PM
This revision was automatically updated to reflect the committed changes.