This is an archive of the discontinued LLVM Phabricator instance.

Summary: Add support for XAR instruction generation to the AArch64 backend
Needs ReviewPublic

Authored by BK1603 on May 7 2023, 2:49 PM.

Details

Event Timeline

BK1603 created this revision.May 7 2023, 2:49 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 7 2023, 2:49 PM
BK1603 requested review of this revision.May 7 2023, 2:49 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 7 2023, 2:49 PM

Thanks for working on this, it looks good.

llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
438

Add 'try' to the start, like the other methods here?

4281

These can be SDValue

4284

It is clearer to use N0->getOpcode() != AArch64ISD::VSHL ||

4287

Check that N0.getOperand(0) == N1.getOperand(0), and that N0.getOperand(0).getOpcode() == ISD::XOR, to make sure they are the same XOR node.

4295

There is a getConstantOperandVal, which is useful when we know the value is a constant and we want to get the value.

4302

MVT::i64 should be VT I think, from N->getValueType(0)
You may need to use getTargetConstant for the immediate too.

llvm/test/CodeGen/AArch64/xar.ll
11

I believe the #54 should be part of the instruction

I was just scrolling through GitHub issues and stumbled on this. Looks like a nice little addition, any plans on picking this up?

BK1603 updated this revision to Diff 558221.Sun, Dec 10, 3:37 AM
BK1603 marked 6 inline comments as done.

Summary: Add support for XAR instruction generation to the AArch64 backend

BK1603 added inline comments.Sun, Dec 10, 3:38 AM
llvm/test/CodeGen/AArch64/xar.ll
11

I don't think that 54 would be a part of the instruction, since the instruction itself (as defined in arm's reference) is XAR. I think the issue is with the naming here, I've renamed xar_54 to xar.

BK1603 updated this revision to Diff 558222.Sun, Dec 10, 4:17 AM

Summary: Add support for XAR instruction generation to the AArch64 backend

Thanks for the update, this is looking OK to me. But I'm not 100% sure that we will receive notifications for phabricator any more as most work has moved to github pull requests.

llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
4284

This doesn't need quite as many brackets.

4287

I think I would use

if (N0->getOperand(0)->getOpcode() != N1->getOperand(0)->getOpcode() ||
    N1->getOperand(0)->getOpcode() != ISD::XOR)

But does something need to check that N0->getOperand(0) == N1->getOperand(0)?

4299

This looks like it needs a clang-format for the patch.
imm -> Imm

4301

if (ShAmt + HsAmt != 64)

4375–4377

Maybe if (Subtarget->hasSHA3() && trySelectXAR(Node))

BK1603 updated this revision to Diff 558224.Mon, Dec 11, 2:31 AM
BK1603 marked 4 inline comments as done.

Summary: Add support for XAR instruction generation to the AArch64 backend

Thanks for the review @dmgreen

I ran clang-format on the patch and have resolved other comments.
As for notifications for this patch, I'll ping you on the github issue as well.
I'll submit github PRs for any new patches that I make from here on out.

llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
4287

I feel what you suggest should be enough, we would only check for the second condition (N1->getOperand(0)->getOpcode() != ISD::XOR) if the first one is false,
which would imply that N0->getOperand(0)->getOpcode() == N1->getOperand(0)->getOpcode()

I ran clang-format on the patch and have resolved other comments.
As for notifications for this patch, I'll ping you on the github issue as well.
I'll submit github PRs for any new patches that I make from here on out.

Thanks. Can you create a github pr for this patch so I can use the submit button in the github UI?

llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
4287

I mean something like this:

define <2 x i64> @xar(<2 x i64> %x, <2 x i64> %y, <2 x i64> %z) {                                 
    %a1 = xor <2 x i64> %x, %y                                                                    
    %a2 = xor <2 x i64> %x, %z                                                                    
    %b = call <2 x i64> @llvm.fshl.v2i64(<2 x i64> %a1, <2 x i64> %a2, <2 x i64> <i64 10, i64 10>)
    ret <2 x i64> %b                                                                              
}

I think it will mis-compile at the moment.

BK1603 added inline comments.Mon, Dec 11, 7:21 AM
llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
4287

Oh right got it, misread the previous comment. I’ll incorporate this change into the GitHub PR as well