Index: lib/CodeGen/MachineInstr.cpp =================================================================== --- lib/CodeGen/MachineInstr.cpp +++ lib/CodeGen/MachineInstr.cpp @@ -1202,7 +1202,10 @@ unsigned Flag = getOperand(FlagIdx).getImm(); unsigned RCID; - if (InlineAsm::hasRegClassConstraint(Flag, RCID)) + if ((InlineAsm::getKind(Flag) == InlineAsm::Kind_RegUse || + InlineAsm::getKind(Flag) == InlineAsm::Kind_RegDef || + InlineAsm::getKind(Flag) == InlineAsm::Kind_RegDefEarlyClobber) && + InlineAsm::hasRegClassConstraint(Flag, RCID)) return TRI->getRegClass(RCID); // Assume that all registers in a memory operand are pointers. Index: lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp =================================================================== --- lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -1951,15 +1951,15 @@ // Otherwise, this is a memory operand. Ask the target to select it. std::vector SelOps; - if (SelectInlineAsmMemoryOperand(InOps[i+1], - InlineAsm::getMemoryConstraintID(Flags), - SelOps)) + unsigned ConstraintID = InlineAsm::getMemoryConstraintID(Flags); + if (SelectInlineAsmMemoryOperand(InOps[i+1], ConstraintID, SelOps)) report_fatal_error("Could not match memory address. Inline asm" " failure!"); // Add this to the output node. unsigned NewFlags = InlineAsm::getFlagWord(InlineAsm::Kind_Mem, SelOps.size()); + NewFlags = InlineAsm::getFlagWordForMem(NewFlags, ConstraintID); Ops.push_back(CurDAG->getTargetConstant(NewFlags, DL, MVT::i32)); Ops.insert(Ops.end(), SelOps.begin(), SelOps.end()); i += 2; Index: lib/Target/Mips/MipsSERegisterInfo.cpp =================================================================== --- lib/Target/Mips/MipsSERegisterInfo.cpp +++ lib/Target/Mips/MipsSERegisterInfo.cpp @@ -60,10 +60,12 @@ return &Mips::GPR64RegClass; } -/// Get the size of the offset supported by the given load/store. +/// Get the size of the offset supported by the given load/store/inline asm. /// The result includes the effects of any scale factors applied to the /// instruction immediate. -static inline unsigned getLoadStoreOffsetSizeInBits(const unsigned Opcode) { +static inline unsigned getLoadStoreOffsetSizeInBits(const unsigned Opcode, + MachineOperand MO) { + unsigned ConstraintID; switch (Opcode) { case Mips::LD_B: case Mips::ST_B: @@ -77,6 +79,14 @@ case Mips::LD_D: case Mips::ST_D: return 10 + 3 /* scale factor */; + case Mips::INLINEASM: + ConstraintID = InlineAsm::getMemoryConstraintID(MO.getImm()); + switch (ConstraintID) { + case InlineAsm::Constraint_ZC: + return 9; + default: + return 16; + } default: return 16; } @@ -166,7 +176,7 @@ // Make sure Offset fits within the field available. // For MSA instructions, this is a 10-bit signed immediate (scaled by // element size), otherwise it is a 16-bit signed immediate. - unsigned OffsetBitSize = getLoadStoreOffsetSizeInBits(MI.getOpcode()); + unsigned OffsetBitSize = getLoadStoreOffsetSizeInBits(MI.getOpcode(), MI.getOperand(OpNo-1)); unsigned OffsetAlign = getLoadStoreOffsetAlign(MI.getOpcode()); if (OffsetBitSize < 16 && isInt<16>(Offset) && Index: test/CodeGen/Mips/inlineasm-constraint_ZC_2.ll =================================================================== --- /dev/null +++ test/CodeGen/Mips/inlineasm-constraint_ZC_2.ll @@ -0,0 +1,27 @@ +; RUN: llc -march=mips -mcpu=mips32r6 < %s | FileCheck %s +; RUN: llc -march=mips -mcpu=mips64r6 < %s | FileCheck %s + +%struct.anon = type { [63 x i32], i32, i32 } + +define i32 @Atomic() { +; CHECK-LABEL: Atomic: +entry: + %s = alloca %struct.anon, align 4 + %0 = bitcast %struct.anon* %s to i8* + %count = getelementptr inbounds %struct.anon, %struct.anon* %s, i64 0, i32 1 + store i32 0, i32* %count, align 4 + +; CHECK: #APP +; CHECK: ll ${{[0-9]+}}, 0(${{[0-9a-z]+}}) +; CHECK: sc ${{[0-9]+}}, 0(${{[0-9a-z]+}}) +; CHECK: #NO_APP + + %1 = call { i32, i32 } asm sideeffect ".set push\0A.set noreorder\0A1:\0All $0, $2\0Aaddu $1, $0, $3\0Asc $1, $2\0Abeqz $1, 1b\0Aaddu $1, $0, $3\0A.set pop\0A", "=&r,=&r,=*^ZC,Ir,*^ZC,~{memory},~{$1}"(i32* %count, i32 10, i32* %count) + %asmresult1.i = extractvalue { i32, i32 } %1, 1 + %cmp = icmp ne i32 %asmresult1.i, 10 + %conv = zext i1 %cmp to i32 + %call2 = call i32 @f(i32 signext %conv) + ret i32 %call2 +} + +declare i32 @f(i32 signext)