forked from OSchip/llvm-project
[LoopDeletion] Support selects when symbolically evaluating 1st iteration
Adds support for selects for which we know value on the 1st iteration. Differential Revision: https://reviews.llvm.org/D104111 Reviewed By: nikic
This commit is contained in:
parent
49ca01047f
commit
4c0da23663
|
@ -197,6 +197,14 @@ getValueOnFirstIteration(Value *V, DenseMap<Value *, Value *> &FirstIterValue,
|
||||||
Value *RHS =
|
Value *RHS =
|
||||||
getValueOnFirstIteration(Cmp->getOperand(1), FirstIterValue, SQ);
|
getValueOnFirstIteration(Cmp->getOperand(1), FirstIterValue, SQ);
|
||||||
FirstIterV = SimplifyICmpInst(Cmp->getPredicate(), LHS, RHS, SQ);
|
FirstIterV = SimplifyICmpInst(Cmp->getPredicate(), LHS, RHS, SQ);
|
||||||
|
} else if (auto *Select = dyn_cast<SelectInst>(V)) {
|
||||||
|
Value *Cond =
|
||||||
|
getValueOnFirstIteration(Select->getCondition(), FirstIterValue, SQ);
|
||||||
|
if (auto *C = dyn_cast<ConstantInt>(Cond)) {
|
||||||
|
auto *Selected = C->isAllOnesValue() ? Select->getTrueValue()
|
||||||
|
: Select->getFalseValue();
|
||||||
|
FirstIterV = getValueOnFirstIteration(Selected, FirstIterValue, SQ);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!FirstIterV)
|
if (!FirstIterV)
|
||||||
FirstIterV = V;
|
FirstIterV = V;
|
||||||
|
|
|
@ -979,25 +979,24 @@ failure:
|
||||||
unreachable
|
unreachable
|
||||||
}
|
}
|
||||||
|
|
||||||
; TODO: We can break the backedge here.
|
|
||||||
define i32 @test_select_const(i32 %x) {
|
define i32 @test_select_const(i32 %x) {
|
||||||
; CHECK-LABEL: @test_select_const(
|
; CHECK-LABEL: @test_select_const(
|
||||||
; CHECK-NEXT: entry:
|
; CHECK-NEXT: entry:
|
||||||
; CHECK-NEXT: br label [[LOOP:%.*]]
|
; CHECK-NEXT: br label [[LOOP:%.*]]
|
||||||
; CHECK: loop:
|
; CHECK: loop:
|
||||||
; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[SUM_NEXT:%.*]], [[BACKEDGE:%.*]] ]
|
; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ]
|
||||||
; CHECK-NEXT: [[SUB:%.*]] = sub i32 4, [[SUM]]
|
; CHECK-NEXT: [[SUB:%.*]] = sub i32 4, [[SUM]]
|
||||||
; CHECK-NEXT: [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
|
; CHECK-NEXT: [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
|
||||||
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[IS_POSITIVE]], i32 [[SUB]], i32 [[X:%.*]]
|
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[IS_POSITIVE]], i32 [[SUB]], i32 [[X:%.*]]
|
||||||
; CHECK-NEXT: [[SEL_COND:%.*]] = icmp sgt i32 [[SEL]], 0
|
; CHECK-NEXT: [[SEL_COND:%.*]] = icmp sgt i32 [[SEL]], 0
|
||||||
; CHECK-NEXT: br i1 [[SEL_COND]], label [[BACKEDGE]], label [[IF_FALSE:%.*]]
|
; CHECK-NEXT: br i1 [[SEL_COND]], label [[BACKEDGE:%.*]], label [[IF_FALSE:%.*]]
|
||||||
; CHECK: if.false:
|
; CHECK: if.false:
|
||||||
; CHECK-NEXT: br label [[BACKEDGE]]
|
; CHECK-NEXT: br label [[BACKEDGE]]
|
||||||
; CHECK: backedge:
|
; CHECK: backedge:
|
||||||
; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE]] ], [ [[SUB]], [[LOOP]] ]
|
; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE]] ], [ [[SUB]], [[LOOP]] ]
|
||||||
; CHECK-NEXT: [[SUM_NEXT]] = add i32 [[SUM]], [[MERGE_PHI]]
|
; CHECK-NEXT: [[SUM_NEXT:%.*]] = add i32 [[SUM]], [[MERGE_PHI]]
|
||||||
; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ne i32 [[SUM_NEXT]], 4
|
; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ne i32 [[SUM_NEXT]], 4
|
||||||
; CHECK-NEXT: br i1 [[LOOP_COND]], label [[LOOP]], label [[DONE:%.*]]
|
; CHECK-NEXT: br label [[DONE:%.*]]
|
||||||
; CHECK: done:
|
; CHECK: done:
|
||||||
; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
|
; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
|
||||||
; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
|
; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
|
||||||
|
|
Loading…
Reference in New Issue