This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] calculate sadd/ssub overflow by sign bits
Needs ReviewPublic

Authored by tingwang on Jun 6 2023, 10:48 PM.

Details

Reviewers
shchenz
nemanjai
Group Reviewers
Restricted Project
Summary

This patch propose to calculate overflow by using sign bits.

Take signed-add as example: (LHS + RHS = Result), the original approach compare Result with LHS (this compare could involve multiple bits of information), and RHS with 0.
@llvm.sadd.with.overflow.i64 generates following instructions on P9:

ld 3, 0(3)
ld 4, 0(4)
add 6, 3, 4
rldicl 8, 3, 1, 63
rldicl 4, 4, 1, 63
sradi 7, 6, 63
subc    3, 6, 3
std 6, 0(5)
adde 3, 8, 7
xori 3, 3, 1
xor 3, 4, 3
blr

Alternative approach proposed here only use sign bits from LHS, RHS, and Result to decide overflow condition.

ld 3, 0(3)
ld 4, 0(4)
add 6, 3, 4
xor 4, 4, 6
xor 3, 3, 6
std 6, 0(5)
and 3, 3, 4
rldicl 3, 3, 1, 63
blr

Diff Detail