C++: Handle 'unlikely' in IRGuards.

This commit is contained in:
Mathias Vorreiter Pedersen
2024-05-21 16:30:57 +01:00
parent 000a81fd29
commit 9c98652116

View File

@@ -762,6 +762,12 @@ private predicate compares_eq(
exists(AbstractValue dual | value = dual.getDualValue() |
compares_eq(test.(LogicalNotInstruction).getUnary(), left, right, k, areEqual, dual)
)
or
exists(CallInstruction call |
test = call and
call.getStaticCallTarget().hasName("__builtin_expect") and
compares_eq(call.getArgument(0).(ConvertInstruction).getUnary(), left, right, k, areEqual, value)
)
}
/**
@@ -831,6 +837,13 @@ private predicate unary_compares_eq(
int_value(const) = k1 and
k = k1 + k2
)
or
exists(CallInstruction call, Instruction arg |
test = call and
call.getStaticCallTarget().hasName("__builtin_expect") and
arg = call.getArgument(0) and
unary_compares_eq(arg.(ConvertInstruction).getUnary(), op, k, areEqual, inNonZeroCase, value)
)
}
/** Rearrange various simple comparisons into `left == right + k` form. */