mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 11:13:28 +01:00
509d4884e7
Summary: Currently, `rewriteLoopExitValues()`'s logic is roughly as following: > Loop over each incoming value in each PHI node. > Query whether the SCEV for that incoming value is high-cost. > Expand the SCEV. > Perform sanity check (`isValidRewrite()`, D51582) > Record the info > Afterwards, see if we can drop the loop given replacements. > Maybe perform replacements. The problem is that we interleave SCEV cost checking and expansion. This is A Problem, because `isHighCostExpansion()` takes special care to not bill for the expansions that were already expanded, and we can reuse. While it makes sense in general - if we know that we will expand some SCEV, all the other SCEV's costs should account for that, which might cause some of them to become non-high-cost too, and cause chain reaction. But that isn't what we are doing here. We expand *all* SCEV's, unconditionally. So every next SCEV's cost will be affected by the already-performed expansions for previous SCEV's. Even if we are not planning on keeping some of the expansions we performed. Worse yet, this current "bonus" depends on the exact PHI node incoming value processing order. This is completely wrong. As an example of an issue, see @dmajor's `pr45835.ll` - if we happen to have a PHI node with two(!) identical high-cost incoming values for the same basic blocks, we would decide first time around that it is high-cost, expand it, and immediately decide that it is not high-cost because we have an expansion that we could reuse (because we expanded it right before, temporarily), and replace the second incoming value but not the first one; thus resulting in a broken PHI. What we instead should do for now, is not perform any expansions until after we've queried all the costs. Later, in particular after `isValidRewrite()` is an assertion (D51582) we could improve upon that, but in a more coherent fashion. See [[ https://bugs.llvm.org/show_bug.cgi?id=45835 | PR45835 ]] Reviewers: dmajor, reames, mkazantsev, fhahn, efriedma Reviewed By: dmajor, mkazantsev Subscribers: smeenai, nikic, hiraditya, javed.absar, llvm-commits, dmajor Tags: #llvm Differential Revision: https://reviews.llvm.org/D79787
39 lines
1.3 KiB
LLVM
39 lines
1.3 KiB
LLVM
; RUN: opt < %s -indvars -replexitval=always -S | FileCheck %s --check-prefix=ALWAYS
|
|
; RUN: opt < %s -indvars -replexitval=never -S | FileCheck %s --check-prefix=NEVER
|
|
; RUN: opt < %s -indvars -replexitval=cheap -scev-cheap-expansion-budget=1 -S | FileCheck %s --check-prefix=CHEAP
|
|
|
|
; rewriteLoopExitValues() must rewrite all or none of a PHI's values from a given block.
|
|
|
|
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
|
|
|
|
@a = common global i8 0, align 1
|
|
|
|
define internal fastcc void @d(i8* %c) unnamed_addr #0 {
|
|
entry:
|
|
%cmp = icmp ule i8* %c, getelementptr inbounds (i8, i8* @a, i64 65535)
|
|
%add.ptr = getelementptr inbounds i8, i8* %c, i64 -65535
|
|
br label %while.cond
|
|
|
|
while.cond:
|
|
br i1 icmp ne (i8 0, i8 0), label %cont, label %while.end
|
|
|
|
cont:
|
|
%a.mux = select i1 %cmp, i8* @a, i8* %add.ptr
|
|
switch i64 0, label %while.cond [
|
|
i64 -1, label %handler.pointer_overflow.i
|
|
i64 0, label %handler.pointer_overflow.i
|
|
]
|
|
|
|
handler.pointer_overflow.i:
|
|
%a.mux.lcssa4 = phi i8* [ %a.mux, %cont ], [ %a.mux, %cont ]
|
|
; ALWAYS: [ %scevgep, %cont ], [ %scevgep, %cont ]
|
|
; NEVER: [ %a.mux, %cont ], [ %a.mux, %cont ]
|
|
; In cheap mode, use either one as long as it's consistent.
|
|
; CHEAP: [ %[[VAL:.*]], %cont ], [ %[[VAL]], %cont ]
|
|
%x5 = ptrtoint i8* %a.mux.lcssa4 to i64
|
|
br label %while.end
|
|
|
|
while.end:
|
|
ret void
|
|
}
|