Index: llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp =================================================================== --- llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp +++ llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp @@ -2029,6 +2029,7 @@ case TargetOpcode::G_ATOMICRMW_ADD: case TargetOpcode::G_ATOMICRMW_SUB: case TargetOpcode::G_ATOMICRMW_AND: + case TargetOpcode::G_ATOMICRMW_NAND: case TargetOpcode::G_ATOMICRMW_OR: case TargetOpcode::G_ATOMICRMW_XOR: case TargetOpcode::G_ATOMICRMW_MIN: Index: llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp =================================================================== --- llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp +++ llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp @@ -4174,4 +4174,40 @@ EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF; } +// ATOMICRMW_NAND widening. +TEST_F(AArch64GISelMITest, WidenATOMICRMW_NAND) { + setUp(); + if (!TM) + return; + + LLT S64 = LLT::scalar(64); + // Declare your legalization info + DefineLegalizerInfo(A, { + getActionDefinitionsBuilder(G_ATOMICRMW_NAND) + .legalFor({{s64, LLT::pointer(0, 64)}}); + }); + + auto OldValRes = MRI->createGenericVirtualRegister(LLT::scalar(32)); + auto Val = B.buildConstant(LLT::scalar(32), 1).getReg(0); + auto Addr = B.buildConstant(LLT::pointer(0, 64), 1).getReg(0); + MachineMemOperand *MMO = MF->getMachineMemOperand( + MachinePointerInfo(), + MachineMemOperand::MOLoad | MachineMemOperand::MOStore, 8, Align(8), + AAMDNodes(), nullptr, SyncScope::System, AtomicOrdering::Unordered); + + auto MIBAtomicRMWNand = B.buildAtomicRMWNand(OldValRes, Addr, Val, *MMO); + AInfo Info(MF->getSubtarget()); + DummyGISelObserver Observer; + LegalizerHelper Helper(*MF, Info, Observer, B); + EXPECT_TRUE(Helper.widenScalar(*MIBAtomicRMWNand, 0, S64) == + LegalizerHelper::LegalizeResult::Legalized); + + auto CheckStr = R"( + CHECK: [[ATMNAND:%[0-9]+]]:_(s64) = G_ATOMICRMW_NAND %{{[0-9]+}}:_(p0), %{{[0-9]+}}:_ :: (load store unordered (s64)) + )"; + + // Check + EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF; +} + } // namespace