[llvm] [PowerPC] eliminate RLWINM instruction following LBARX as possible (PR #144089)
zhijian lin via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 20 06:35:51 PDT 2025
================
@@ -4961,6 +4961,21 @@ bool PPCDAGToDAGISel::tryAsSingleRLWINM(SDNode *N) {
// If this is just a masked value where the input is not handled, and
// is not a rotate-left (handled by a pattern in the .td file), emit rlwinm
if (isRunOfOnes(Imm, MB, ME) && Val.getOpcode() != ISD::ROTL) {
+ // The result of LBARX/LHARX do not need to be cleared as the instructions
+ // implicitly clear the upper bits.
+ unsigned AlreadyCleared = 0;
+ if (Val.getOpcode() == ISD::INTRINSIC_W_CHAIN) {
+ auto IntrinsicID = Val.getConstantOperandVal(1);
+ if (IntrinsicID == Intrinsic::ppc_lbarx)
+ AlreadyCleared = 24;
+ else if (IntrinsicID == Intrinsic::ppc_lharx)
+ AlreadyCleared = 16;
+ if (AlreadyCleared != 0 && AlreadyCleared == MB) {
----------------
diggerlin wrote:
since there is AlreadyCleared != 0 , that is means , it is Intrinsic::ppc_lharx or Intrinsic::ppc_lbarx only, if it is the first operand of `and` is `Intrinsic::ppc_lharx` or `IntrinsicID::ppc_lbarx` , it means the second operand of the `and` SDNOD is 0xff(for Intrinsic::ppc_lbarx) or 0xffff(for Intrinsic::ppc_lharx). I think I can add assert after line 4973
`assert(ME == 31 && "ME must be 31");`
https://github.com/llvm/llvm-project/pull/144089
More information about the llvm-commits
mailing list