Index: llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp =================================================================== --- llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp +++ llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp @@ -4040,7 +4040,8 @@ MachineIRBuilder &MIRBuilder) const { MachineRegisterInfo &MRI = MIRBuilder.getMF().getRegInfo(); bool Is32Bit = (MRI.getType(LHS.getReg()).getSizeInBits() == 32); - return emitADDS(Is32Bit ? AArch64::WZR : AArch64::XZR, LHS, RHS, MIRBuilder); + auto RC = Is32Bit ? &AArch64::GPR32RegClass : &AArch64::GPR64RegClass; + return emitADDS(MRI.createVirtualRegister(RC), LHS, RHS, MIRBuilder); } MachineInstr * Index: llvm/test/CodeGen/AArch64/GlobalISel/opt-fold-compare.mir =================================================================== --- llvm/test/CodeGen/AArch64/GlobalISel/opt-fold-compare.mir +++ llvm/test/CodeGen/AArch64/GlobalISel/opt-fold-compare.mir @@ -45,7 +45,7 @@ ; CHECK: [[COPY:%[0-9]+]]:gpr32 = COPY $w0 ; CHECK: [[COPY1:%[0-9]+]]:gpr32 = COPY $w1 ; CHECK: [[COPY2:%[0-9]+]]:gpr32 = COPY $wzr - ; CHECK: $wzr = ADDSWrr [[COPY]], [[COPY1]], implicit-def $nzcv + ; CHECK: [[ADDSWrr:%[0-9]+]]:gpr32 = ADDSWrr [[COPY]], [[COPY1]], implicit-def $nzcv ; CHECK: [[CSINCWr:%[0-9]+]]:gpr32 = CSINCWr [[COPY2]], $wzr, 0, implicit $nzcv ; CHECK: $w0 = COPY [[CSINCWr]] ; CHECK: RET_ReallyLR implicit $w0 @@ -76,7 +76,7 @@ ; CHECK: [[COPY:%[0-9]+]]:gpr32 = COPY $w0 ; CHECK: [[COPY1:%[0-9]+]]:gpr32 = COPY $w1 ; CHECK: [[COPY2:%[0-9]+]]:gpr32 = COPY $wzr - ; CHECK: $wzr = ADDSWrr [[COPY]], [[COPY1]], implicit-def $nzcv + ; CHECK: [[ADDSWrr:%[0-9]+]]:gpr32 = ADDSWrr [[COPY]], [[COPY1]], implicit-def $nzcv ; CHECK: [[CSINCWr:%[0-9]+]]:gpr32 = CSINCWr [[COPY2]], $wzr, 0, implicit $nzcv ; CHECK: $w0 = COPY [[CSINCWr]] ; CHECK: RET_ReallyLR implicit $w0 @@ -171,7 +171,7 @@ ; CHECK: [[COPY:%[0-9]+]]:gpr64 = COPY $x0 ; CHECK: [[COPY1:%[0-9]+]]:gpr64 = COPY $x1 ; CHECK: [[COPY2:%[0-9]+]]:gpr64 = COPY $xzr - ; CHECK: $xzr = ADDSXrr [[COPY]], [[COPY1]], implicit-def $nzcv + ; CHECK: [[ADDSXrr:%[0-9]+]]:gpr64 = ADDSXrr [[COPY]], [[COPY1]], implicit-def $nzcv ; CHECK: [[CSINCXr:%[0-9]+]]:gpr64 = CSINCXr [[COPY2]], $xzr, 0, implicit $nzcv ; CHECK: $x0 = COPY [[CSINCXr]] ; CHECK: RET_ReallyLR implicit $x0 @@ -202,7 +202,7 @@ ; CHECK: [[COPY:%[0-9]+]]:gpr64 = COPY $x0 ; CHECK: [[COPY1:%[0-9]+]]:gpr64 = COPY $x1 ; CHECK: [[COPY2:%[0-9]+]]:gpr64 = COPY $xzr - ; CHECK: $xzr = ADDSXrr [[COPY]], [[COPY1]], implicit-def $nzcv + ; CHECK: [[ADDSXrr:%[0-9]+]]:gpr64 = ADDSXrr [[COPY]], [[COPY1]], implicit-def $nzcv ; CHECK: [[CSINCXr:%[0-9]+]]:gpr64 = CSINCXr [[COPY2]], $xzr, 0, implicit $nzcv ; CHECK: $x0 = COPY [[CSINCXr]] ; CHECK: RET_ReallyLR implicit $x0 @@ -572,7 +572,7 @@ ; CHECK-LABEL: name: cmn_s32_neg_imm ; CHECK: liveins: $w0, $w1 ; CHECK: %reg0:gpr32sp = COPY $w0 - ; CHECK: $wzr = SUBSWri %reg0, 1, 0, implicit-def $nzcv + ; CHECK: [[SUBSWri:%[0-9]+]]:gpr32 = SUBSWri %reg0, 1, 0, implicit-def $nzcv ; CHECK: %cmp:gpr32 = CSINCWr $wzr, $wzr, 0, implicit $nzcv ; CHECK: $w0 = COPY %cmp ; CHECK: RET_ReallyLR implicit $w0 @@ -600,7 +600,7 @@ ; CHECK: liveins: $w0, $x0, $x1 ; CHECK: %reg0:gpr64sp = COPY $x0 ; CHECK: %reg1:gpr32 = COPY $w0 - ; CHECK: $xzr = ADDSXrx %reg0, %reg1, 50, implicit-def $nzcv + ; CHECK: [[ADDSXrx:%[0-9]+]]:gpr64 = ADDSXrx %reg0, %reg1, 50, implicit-def $nzcv ; CHECK: %cmp:gpr32 = CSINCWr $wzr, $wzr, 0, implicit $nzcv ; CHECK: $w0 = COPY %cmp ; CHECK: RET_ReallyLR implicit $w0