Index: llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp =================================================================== --- llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp +++ llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp @@ -3269,24 +3269,12 @@ // For the 32-bit -> 64-bit case, we can emit a mov (ORRWrs) // + SUBREG_TO_REG. - // - // If we are zero extending from 32 bits to 64 bits, it's possible that - // the instruction implicitly does the zero extend for us. In that case, - // we only need the SUBREG_TO_REG. if (IsGPR && SrcSize == 32 && DstSize == 64) { - // Unlike with the G_LOAD case, we don't want to look through copies - // here. (See isDef32.) - MachineInstr *Def = MRI.getVRegDef(SrcReg); - Register SubregToRegSrc = SrcReg; - - // Does the instruction implicitly zero extend? - if (!Def || !isDef32(*Def)) { - // No. Zero out using an OR. - Register OrDst = MRI.createVirtualRegister(&AArch64::GPR32RegClass); - const Register ZReg = AArch64::WZR; - MIB.buildInstr(AArch64::ORRWrs, {OrDst}, {ZReg, SrcReg}).addImm(0); - SubregToRegSrc = OrDst; - } + Register SubregToRegSrc = + MRI.createVirtualRegister(&AArch64::GPR32RegClass); + const Register ZReg = AArch64::WZR; + MIB.buildInstr(AArch64::ORRWrs, {SubregToRegSrc}, {ZReg, SrcReg}) + .addImm(0); MIB.buildInstr(AArch64::SUBREG_TO_REG, {DefReg}, {}) .addImm(0) Index: llvm/test/CodeGen/AArch64/pr58431.ll =================================================================== --- /dev/null +++ llvm/test/CodeGen/AArch64/pr58431.ll @@ -0,0 +1,19 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py +; RUN: llc < %s -mtriple=aarch64-none-linux-gnu -global-isel -global-isel-abort=0 | FileCheck %s + +define i32 @f(i64 %0) { +; CHECK-LABEL: f: +; CHECK: // %bb.0: +; CHECK-NEXT: mov w8, #10 +; CHECK-NEXT: mov w9, w0 +; CHECK-NEXT: udiv x10, x9, x8 +; CHECK-NEXT: msub x0, x10, x8, x9 +; CHECK-NEXT: // kill: def $w0 killed $w0 killed $x0 +; CHECK-NEXT: ret + %2 = trunc i64 %0 to i32 + %3 = freeze i32 %2 + %4 = zext i32 %3 to i64 + %5 = urem i64 %4, 10 + %6 = trunc i64 %5 to i32 + ret i32 %6 +}