This is an archive of the discontinued LLVM Phabricator instance.

[clang] add __builtin_unpredictable and convert to metadata
ClosedPublic

Authored by spatel on Aug 28 2015, 4:43 PM.

Details

Summary

This patch depends on D12341 ('unpredictable' metadata type for LLVM).

For now, I am ignoring the horrible thought that this builtin might take an extra parameter to distinguish different hardware. :)

The goal is to make LLVM generate different code for these functions for a target that has cheap branches (see PR23827 for more details):

int foo();
int normal(int x, int y, int z) {
   if (x != 0 && y != 0) return foo();
   return 1;
}

int crazy(int x, int y) {
   if (__builtin_unpredictable(x != 0 && y != 0)) return foo();
   return 1;
}

Diff Detail

Repository
rL LLVM

Event Timeline

spatel updated this revision to Diff 33491.Aug 28 2015, 4:43 PM
spatel retitled this revision from to [clang] add __builtin_unpredictable and convert to metadata.
spatel updated this object.
spatel added a subscriber: cfe-commits.
kparzysz added inline comments.Aug 31 2015, 5:54 AM
lib/CodeGen/CodeGenFunction.cpp
1238 ↗(On Diff #33491)

Is the definition of CreateCondBr actually updated somewhere? I didn't see it in any other patch.

spatel added inline comments.Aug 31 2015, 7:56 AM
lib/CodeGen/CodeGenFunction.cpp
1238 ↗(On Diff #33491)

Yes - please see the 2nd hunk in IRBuilder.h in D12341.

spatel added inline comments.Aug 31 2015, 8:34 AM
lib/CodeGen/CodeGenFunction.cpp
1238 ↗(On Diff #33491)

[the previous reply didn't make it to the commits list...trying again]
Yes - please see the 2nd hunk in IRBuilder.h in D12341.

kparzysz edited edge metadata.Aug 31 2015, 8:52 AM

LGTM

lib/CodeGen/CodeGenFunction.cpp
1238 ↗(On Diff #33491)

You're right. I see it.

This revision was automatically updated to reflect the committed changes.