- Notifications
You must be signed in to change notification settings - Fork 15.3k
Closed
Labels
llvm:instcombineCovers the InstCombine, InstSimplify and AggressiveInstCombine passesCovers the InstCombine, InstSimplify and AggressiveInstCombine passesmissed-optimization
Description
For unsigned integers to check if an addition overflowed (get carry bit) it is enough to compare the sum with one of its arguments carry = sum < a. However, it is not obvious that it is enough to only check one of the arguments and we may encounter a pattern where both arguments are checked.
define i1 @src(i64 %a, i64 %b){ %s = add i64 %a, %b %cond_a = icmp ult i64 %s, %a %cond_b = icmp ult i64 %s, %b %cond = or i1 %cond_a, %cond_b ret i1 %cond } define i1 @tgt(i64 %a, i64 %b){ %s = add i64 %a, %b %cond_a = icmp ult i64 %s, %a ret i1 %cond_a }Playground: https://godbolt.org/z/TW8enc6zo
Proof: https://alive2.llvm.org/ce/z/iPAE7t
Metadata
Metadata
Assignees
Labels
llvm:instcombineCovers the InstCombine, InstSimplify and AggressiveInstCombine passesCovers the InstCombine, InstSimplify and AggressiveInstCombine passesmissed-optimization