Index: llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp =================================================================== --- llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp +++ llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp @@ -1980,16 +1980,11 @@ I.eraseFromParent(); return constrainSelectedInstRegOperands(*TestBit, TII, TRI, RBI); } else { - auto CMP = BuildMI(MBB, I, I.getDebugLoc(), TII.get(AArch64::ANDSWri)) - .addDef(AArch64::WZR) - .addUse(CondReg) + auto CMP = MIB.buildInstr(AArch64::ANDSWri, {LLT::scalar(32)}, {CondReg}) .addImm(1); - constrainSelectedInstRegOperands(*CMP.getInstr(), TII, TRI, RBI); + constrainSelectedInstRegOperands(*CMP, TII, TRI, RBI); auto Bcc = - BuildMI(MBB, I, I.getDebugLoc(), TII.get(AArch64::Bcc)) - .addImm(AArch64CC::EQ) - .addMBB(DestMBB); - + MIB.buildInstr(AArch64::Bcc).addImm(AArch64CC::EQ).addMBB(DestMBB); I.eraseFromParent(); return constrainSelectedInstRegOperands(*Bcc.getInstr(), TII, TRI, RBI); } Index: llvm/test/CodeGen/AArch64/GlobalISel/speculative-hardening-brcond.mir =================================================================== --- /dev/null +++ llvm/test/CodeGen/AArch64/GlobalISel/speculative-hardening-brcond.mir @@ -0,0 +1,64 @@ +# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py +# RUN: llc -mtriple aarch64-unknown-unknown -run-pass=instruction-select -verify-machineinstrs %s -o - | FileCheck %s\ +# +# Verify that when a function has the speculative_load_hardening attribute we +# never produce a CB(N)Z or TB(N)Z. +# + +--- | + define void @no_tbnz() speculative_load_hardening { ret void } + define void @no_cbz() speculative_load_hardening { ret void } +... + +--- +name: no_tbnz +legalized: true +regBankSelected: true +body: | + ; CHECK-LABEL: name: no_tbnz + ; CHECK: bb.0: + ; CHECK: successors: %bb.0(0x40000000), %bb.1(0x40000000) + ; CHECK: %reg:gpr32 = COPY $w0 + ; CHECK: [[ANDSWri:%[0-9]+]]:gpr32 = ANDSWri %reg, 1, implicit-def $nzcv + ; CHECK: Bcc 0, %bb.1, implicit $nzcv + ; CHECK: B %bb.0 + ; CHECK: bb.1: + ; CHECK: RET_ReallyLR + bb.0: + liveins: $w0 + successors: %bb.0, %bb.1 + %reg:gpr(s32) = COPY $w0 + %cond:gpr(s1) = G_TRUNC %reg + G_BRCOND %cond(s1), %bb.1 + G_BR %bb.0 + bb.1: + RET_ReallyLR +... +--- +name: no_cbz +legalized: true +regBankSelected: true +body: | + ; CHECK-LABEL: name: no_cbz + ; CHECK: bb.0: + ; CHECK: successors: %bb.0(0x40000000), %bb.1(0x40000000) + ; CHECK: %reg:gpr32sp = COPY $w0 + ; CHECK: [[SUBSWri:%[0-9]+]]:gpr32 = SUBSWri %reg, 0, 0, implicit-def $nzcv + ; CHECK: %cmp:gpr32 = CSINCWr $wzr, $wzr, 1, implicit $nzcv + ; CHECK: [[ANDSWri:%[0-9]+]]:gpr32 = ANDSWri %cmp, 1, implicit-def $nzcv + ; CHECK: Bcc 0, %bb.1, implicit $nzcv + ; CHECK: B %bb.0 + ; CHECK: bb.1: + ; CHECK: RET_ReallyLR + bb.0: + liveins: $w0 + successors: %bb.0, %bb.1 + %reg:gpr(s32) = COPY $w0 + %zero:gpr(s32) = G_CONSTANT i32 0 + %cmp:gpr(s32) = G_ICMP intpred(eq), %reg, %zero + %cond:gpr(s1) = G_TRUNC %cmp(s32) + G_BRCOND %cond(s1), %bb.1 + G_BR %bb.0 + bb.1: + RET_ReallyLR +...