From: Anton Sidorenko Date: Fri, 18 Nov 2022 09:33:02 +0000 (+0300) Subject: [MachineTraceMetrics] Pick the trace successor for an entry block X-Git-Tag: upstream/17.0.6~27007 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fb47bb37e4fe7b67bde31bca93d9b31dd55c0caa;p=platform%2Fupstream%2Fllvm.git [MachineTraceMetrics] Pick the trace successor for an entry block We generate erroneous trace for a basic block if it does not have at least one predecessor when MinInstr strategy is used. Currently only this strategy is implemented, so we always have a wrong trace for any entry block. This results in wrong instructions heights calculation and also leads to wrong critical path. The described behavior is demonstrated on a simple test. It shows that early if-conv pass makes wrong decisions due to incorrectly calculated critical path lenght. Differential Revision: https://reviews.llvm.org/D138272 --- diff --git a/llvm/lib/CodeGen/MachineTraceMetrics.cpp b/llvm/lib/CodeGen/MachineTraceMetrics.cpp index 715e5da..dc6746e 100644 --- a/llvm/lib/CodeGen/MachineTraceMetrics.cpp +++ b/llvm/lib/CodeGen/MachineTraceMetrics.cpp @@ -352,7 +352,7 @@ MinInstrCountEnsemble::pickTracePred(const MachineBasicBlock *MBB) { // Select the preferred successor for MBB. const MachineBasicBlock* MinInstrCountEnsemble::pickTraceSucc(const MachineBasicBlock *MBB) { - if (MBB->pred_empty()) + if (MBB->succ_empty()) return nullptr; const MachineLoop *CurLoop = getLoopFor(MBB); const MachineBasicBlock *Best = nullptr; diff --git a/llvm/test/CodeGen/X86/machine-trace-metrics-entryBB-critpath.ll b/llvm/test/CodeGen/X86/machine-trace-metrics-entryBB-critpath.ll index f841465..045d26e 100644 --- a/llvm/test/CodeGen/X86/machine-trace-metrics-entryBB-critpath.ll +++ b/llvm/test/CodeGen/X86/machine-trace-metrics-entryBB-critpath.ll @@ -6,27 +6,27 @@ ; MinInstr strategy is used. The behavior is demonstrated on early if conversion ; pass. -; CHECK: TBB: MinInstr trace %bb.0 --> %bb.0 --> %bb.0: 4 instrs. 1 cycles. +; CHECK: TBB: MinInstr trace %bb.0 --> %bb.0 --> %bb.2: 8 instrs. 30 cycles. ; CHECK: %bb.0 +; CHECK: -> %bb.2 ; CHECK: FBB: MinInstr trace %bb.0 --> %bb.1 --> %bb.2: 10 instrs. 32 cycles. ; CHECK: %bb.1 <- %bb.0 ; CHECK: -> %bb.2 -; CHECK: Resource length 10, minimal critical path 1 -; CHECK: Not enough available ILP. +; CHECK: Resource length 10, minimal critical path 30 +; CHECK: If-converting define i32 @_Z3fooiidd(i32 %a, i32 %b, double %d, double %e) #0 { ; CHECK-LABEL: _Z3fooiidd: ; CHECK: # %bb.0: # %entry -; CHECK-NEXT: movl %esi, %eax -; CHECK-NEXT: addl %edi, %eax -; CHECK-NEXT: cmpl $3, %edi -; CHECK-NEXT: jl .LBB0_2 -; CHECK-NEXT: # %bb.1: # %if.then -; CHECK-NEXT: cvttsd2si %xmm0, %ecx +; CHECK-NEXT: # kill: def $esi killed $esi def $rsi +; CHECK-NEXT: # kill: def $edi killed $edi def $rdi +; CHECK-NEXT: leal (%rsi,%rdi), %ecx +; CHECK-NEXT: cvttsd2si %xmm0, %eax ; CHECK-NEXT: addl %ecx, %eax -; CHECK-NEXT: .LBB0_2: # %if.end +; CHECK-NEXT: cmpl $3, %edi +; CHECK-NEXT: cmovll %ecx, %eax ; CHECK-NEXT: cvttsd2si %xmm1, %ecx ; CHECK-NEXT: cltd ; CHECK-NEXT: idivl %ecx