diff --git a/llvm/lib/CodeGen/MachinePipeliner.cpp b/llvm/lib/CodeGen/MachinePipeliner.cpp --- a/llvm/lib/CodeGen/MachinePipeliner.cpp +++ b/llvm/lib/CodeGen/MachinePipeliner.cpp @@ -2277,20 +2277,28 @@ assert(!OffsetSIsScalable && !OffsetDIsScalable && "Expected offsets to be byte offsets"); - if (!BaseOpS->isIdenticalTo(*BaseOpD)) + MachineInstr *DefS = MRI.getVRegDef(BaseOpS->getReg()); + MachineInstr *DefD = MRI.getVRegDef(BaseOpD->getReg()); + if (!DefS || !DefD || !DefS->isPHI() || !DefD->isPHI()) + return true; + + unsigned InitValS = 0; + unsigned LoopValS = 0; + unsigned InitValD = 0; + unsigned LoopValD = 0; + getPhiRegs(*DefS, BB, InitValS, LoopValS); + getPhiRegs(*DefD, BB, InitValD, LoopValD); + MachineInstr *InitDefS = MRI.getVRegDef(InitValS); + MachineInstr *InitDefD = MRI.getVRegDef(InitValD); + + if (!InitDefS->isIdenticalTo(*InitDefD)) return true; // Check that the base register is incremented by a constant value for each // iteration. - MachineInstr *Def = MRI.getVRegDef(BaseOpS->getReg()); - if (!Def || !Def->isPHI()) - return true; - unsigned InitVal = 0; - unsigned LoopVal = 0; - getPhiRegs(*Def, BB, InitVal, LoopVal); - MachineInstr *LoopDef = MRI.getVRegDef(LoopVal); + MachineInstr *LoopDefS = MRI.getVRegDef(LoopValS); int D = 0; - if (!LoopDef || !TII->getIncrementValue(*LoopDef, D)) + if (!LoopDefS || !TII->getIncrementValue(*LoopDefS, D)) return true; uint64_t AccessSizeS = (*SI->memoperands_begin())->getSize(); diff --git a/llvm/test/CodeGen/Hexagon/swp-carried-dep3.mir b/llvm/test/CodeGen/Hexagon/swp-carried-dep3.mir new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/Hexagon/swp-carried-dep3.mir @@ -0,0 +1,107 @@ +# RUN: llc -mtriple=hexagon -run-pass pipeliner -debug-only=pipeliner %s -o /dev/null 2>&1 -pipeliner-experimental-cg=true | FileCheck %s +# REQUIRES: asserts + +# Test that the loop carried dependence check correctly identifies a recurrence +# when load and store use distinct increment for their pointer. + +# CHECK: Rec NodeSet +# CHECK: Rec NodeSet +# CHECK: Rec NodeSet +# CHECK: Rec NodeSet +# CHECK: Rec NodeSet +# CHECK-NEXT: SU(5) +# CHECK-NEXT: SU(7) + +--- | + + %struct.A = type { i16, i16 } + + define i32 @test(%struct.A* noalias nocapture %s, i16* noalias nocapture readonly %r, i32 %n) { + entry: + %cmp19 = icmp eq i32 %n, 2 + br i1 %cmp19, label %for.end, label %for.body.preheader + + for.body.preheader: + %0 = add i32 %n, -2 + %cgep = getelementptr %struct.A, %struct.A* %s, i32 2, i32 1 + %scevgep1 = bitcast i16* %cgep to %struct.A* + %cgep9 = getelementptr i16, i16* %r, i32 2 + br label %for.body + + for.body: + %lsr.iv7 = phi i16* [ %cgep9, %for.body.preheader ], [ %cgep12, %for.body ] + %lsr.iv2 = phi %struct.A* [ %scevgep1, %for.body.preheader ], [ %cgep11, %for.body ] + %lsr.iv = phi i32 [ %0, %for.body.preheader ], [ %lsr.iv.next, %for.body ] + %sum.020 = phi i32 [ %add7, %for.body ], [ 0, %for.body.preheader ] + %lsr.iv24 = bitcast %struct.A* %lsr.iv2 to i16* + %1 = load i16, i16* %lsr.iv7, align 2 + %conv = sext i16 %1 to i32 + %cgep10 = getelementptr i16, i16* %lsr.iv24, i32 -4 + %2 = load i16, i16* %cgep10, align 2 + %conv2 = sext i16 %2 to i32 + %add = add i16 %1, 10 + store i16 %add, i16* %lsr.iv24, align 2 + %add6 = add i32 %sum.020, %conv + %add7 = add i32 %add6, %conv2 + %lsr.iv.next = add i32 %lsr.iv, -1 + %cmp = icmp eq i32 %lsr.iv.next, 0 + %cgep11 = getelementptr %struct.A, %struct.A* %lsr.iv2, i32 1 + %cgep12 = getelementptr i16, i16* %lsr.iv7, i32 1 + br i1 %cmp, label %for.end, label %for.body + + for.end: + %sum.0.lcssa = phi i32 [ 0, %entry ], [ %add7, %for.body ] + ret i32 %sum.0.lcssa + } + +... +--- +name: test +tracksRegLiveness: true + +body: | + bb.0: + successors: %bb.3, %bb.1 + liveins: $r0, $r1, $r2 + + %14:intregs = COPY $r2 + %13:intregs = COPY $r1 + %12:intregs = COPY $r0 + %16:predregs = C2_cmpeqi %14, 2 + %15:intregs = A2_tfrsi 0 + J2_jumpt killed %16, %bb.3, implicit-def dead $pc + J2_jump %bb.1, implicit-def dead $pc + + bb.1: + successors: %bb.2 + + %0:intregs = A2_addi %14, -2 + %1:intregs = A2_addi %12, 10 + %2:intregs = A2_addi %13, 4 + %17:intregs = A2_tfrsi 0 + %23:intregs = COPY %0 + J2_loop0r %bb.2, %23, implicit-def $lc0, implicit-def $sa0, implicit-def $usr + + bb.2 (machine-block-address-taken): + successors: %bb.3, %bb.2 + + %3:intregs = PHI %2, %bb.1, %10, %bb.2 + %4:intregs = PHI %1, %bb.1, %9, %bb.2 + %21:intregs = PHI %1, %bb.1, %22, %bb.2 + %6:intregs = PHI %17, %bb.1, %7, %bb.2 + %18:intregs, %10:intregs = L2_loadrh_pi %3, 2 :: (load (s16) from %ir.lsr.iv7) + %19:intregs = L2_loadrh_io %21, -8 :: (load (s16) from %ir.cgep10) + %20:intregs = A2_addi %18, 10 + S2_storerh_io %4, 0, killed %20 :: (store (s16) into %ir.lsr.iv24) + %7:intregs = M2_acci %19, %6, %18 + %9:intregs = A2_addi %4, 4 + %22:intregs = A2_addi %21, 4 + ENDLOOP0 %bb.2, implicit-def $pc, implicit-def $lc0, implicit $sa0, implicit $lc0 + J2_jump %bb.3, implicit-def dead $pc + + bb.3: + %11:intregs = PHI %15, %bb.0, %7, %bb.2 + $r0 = COPY %11 + PS_jmpret $r31, implicit-def dead $pc, implicit $r0 + +...