diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -4436,7 +4436,7 @@ if (DAG.isKnownNeverZero(N1) && !TLI.isIntDivCheap(VT, Attr)) { SDValue OptimizedDiv = isSigned ? visitSDIVLike(N0, N1, N) : visitUDIVLike(N0, N1, N); - if (OptimizedDiv.getNode()) { + if (OptimizedDiv.getNode() && OptimizedDiv.getNode() != N) { // If the equivalent Div node also exists, update its users. unsigned DivOpcode = isSigned ? ISD::SDIV : ISD::UDIV; if (SDNode *DivNode = DAG.getNodeIfExists(DivOpcode, N->getVTList(), diff --git a/llvm/test/CodeGen/AArch64/sve-srem-combine-loop.ll b/llvm/test/CodeGen/AArch64/sve-srem-combine-loop.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/AArch64/sve-srem-combine-loop.ll @@ -0,0 +1,19 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py +; RUN: llc < %s | FileCheck %s + +target triple = "aarch64-unknown-linux-gnu" + +define @srem_combine_loop( %a) #0 { +; CHECK-LABEL: srem_combine_loop: +; CHECK: // %bb.0: +; CHECK-NEXT: mov z1.d, z0.d +; CHECK-NEXT: ptrue p0.s +; CHECK-NEXT: asrd z1.s, p0/m, z1.s, #1 +; CHECK-NEXT: mov z2.s, #2 // =0x2 +; CHECK-NEXT: mls z0.s, p0/m, z1.s, z2.s +; CHECK-NEXT: ret + %rem = srem %a, shufflevector ( insertelement ( poison, i32 2, i32 0), poison, zeroinitializer) + ret %rem +} + +attributes #0 = { "target-features"="+sve" }