From ce199667f65bcddc31c8c4be2b723f9132815fe6 Mon Sep 17 00:00:00 2001 From: Jessica Paquette Date: Tue, 1 Dec 2020 16:21:41 -0800 Subject: [PATCH] [AArch64][GlobalISel] Don't explicitly write to the zero register in emitCMN This case was missed in 78ccb0359d8da3269636d85933dd8afe50a2211f. Differential Revision: https://reviews.llvm.org/D92438 --- llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp | 3 ++- llvm/test/CodeGen/AArch64/GlobalISel/opt-fold-compare.mir | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp b/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp index f23743b..493167e 100644 --- a/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp +++ b/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp @@ -4067,7 +4067,8 @@ AArch64InstructionSelector::emitCMN(MachineOperand &LHS, MachineOperand &RHS, 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 * diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/opt-fold-compare.mir b/llvm/test/CodeGen/AArch64/GlobalISel/opt-fold-compare.mir index 81cebc5..f6e4038 100644 --- a/llvm/test/CodeGen/AArch64/GlobalISel/opt-fold-compare.mir +++ b/llvm/test/CodeGen/AArch64/GlobalISel/opt-fold-compare.mir @@ -45,7 +45,7 @@ body: | ; 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 @@ body: | ; 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 @@ body: | ; 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 @@ body: | ; 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 @@ body: | ; 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 @@ body: | ; 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 -- 2.7.4