-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[PowerPC] Implement llvm.set.rounding intrinsic #67302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
According to LangRef, llvm.set.rounding sets rounding mode by integer argument: 0 - toward zero 1 - to nearest, ties to even 2 - toward positive infinity 3 - toward negative infinity 4 - to nearest, ties away from zero While PowerPC ISA says: 0 - to nearest 1 - toward zero 2 - toward positive infinity 3 - toward negative infinity This patch maps the argument and write into last two bits of FPSCR (rounding mode).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The patch looks good but I am not familiar with PPC instructions enough. Could you please run the runtime tests from here: https://github.com/llvm/llvm-test-suite/tree/main/MultiSource/UnitTests/Float/rounding? You just need to build application from two files: clang rounding.c rounding-dynamic.c
.
Sure. All passed on |
LGTM. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can do some perf test between this expansion for set rounding mode and the system library's version for fesetround()
. On AIX, I saw some improvements were introduced in the system library's implementation.
SDValue Chain = Op.getOperand(0); | ||
|
||
// If requested mode is constant, just use simpler mtfsb. | ||
if (auto *CVal = dyn_cast<ConstantSDNode>(Op.getOperand(1))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use DAG.computeKnownBits()
to handle more cases instead of just the constant inputs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we want to make sure higher bits are all zeroes. KnownBits and constant don't make an difference?
return SDValue(SetLo, 0); | ||
} | ||
|
||
// Use x ^ (~(x >> 1) & 1) to transform LLVM rounding mode to Power format. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment does not match below logic. x should be (x & 3)?
And the LLVM mode 4(4 - to nearest, ties away from zero
) is mapped to Power mode 1(1 - toward zero
)? I think LLVM mode 4 should map to Power mode 0(0- Round to Nearest)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we are using a at-best-effort approach. The meaning looks implementation-defined:
The
llvm.set.rounding
intrinsic sets the current rounding mode. It is similar to C library function ‘fesetround’, however this intrinsic does not return any value and uses platform-independent representation of IEEE rounding modes.
// Use x ^ (~(x >> 1) & 1) to transform LLVM rounding mode to Power format. | ||
SDValue One = DAG.getConstant(1, Dl, MVT::i32); | ||
SDValue SrcFlag = DAG.getNode(ISD::AND, Dl, MVT::i32, Op.getOperand(1), | ||
DAG.getConstant(3, Dl, MVT::i32)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add an assert here too if compiler can infer that the high 29 bits of operand 1 is non-zero?
They are faster than system |
Ping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/73/builds/5247 Here is the relevant piece of the build log for the reference
|
According to LangRef, llvm.set.rounding sets rounding mode by integer argument:
While PowerPC ISA says:
This patch maps the argument and write into last two bits of FPSCR (rounding mode).
Migrated from https://reviews.llvm.org/D154933