Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ConstraintElim] Support adding facts from switch terminators. #67061

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,18 @@ void State::addInfoFor(BasicBlock &BB) {
GuaranteedToExecute &= isGuaranteedToTransferExecutionToSuccessor(&I);
}

if (auto *Switch = dyn_cast<SwitchInst>(BB.getTerminator())) {
for (auto &Case : Switch->cases()) {
BasicBlock *Succ = Case.getCaseSuccessor();
Value *V = Case.getCaseValue();
if (!canAddSuccessor(BB, Succ))
continue;
WorkList.emplace_back(FactOrCheck::getConditionFact(
DT.getNode(Succ), CmpInst::ICMP_EQ, Switch->getCondition(), V));
}
return;
}

auto *Br = dyn_cast<BranchInst>(BB.getTerminator());
if (!Br || !Br->isConditional())
return;
Expand Down
12 changes: 3 additions & 9 deletions llvm/test/Transforms/ConstraintElimination/switch.ll
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,10 @@ define i1 @simplify_based_on_switch(i8 %x) {
; CHECK-NEXT: [[RES_1:%.*]] = xor i1 [[C_1]], [[C_2]]
; CHECK-NEXT: ret i1 [[RES_1]]
; CHECK: exit.2:
; CHECK-NEXT: [[T_1:%.*]] = icmp ult i8 [[X]], 7
; CHECK-NEXT: [[F_1:%.*]] = icmp ult i8 [[X]], 6
; CHECK-NEXT: [[RES_2:%.*]] = xor i1 [[T_1]], [[F_1]]
; CHECK-NEXT: [[RES_2:%.*]] = xor i1 true, false
; CHECK-NEXT: ret i1 [[RES_2]]
; CHECK: exit.3:
; CHECK-NEXT: [[T_2:%.*]] = icmp ult i8 [[X]], 11
; CHECK-NEXT: [[F_2:%.*]] = icmp ult i8 [[X]], 10
; CHECK-NEXT: [[RES_3:%.*]] = xor i1 [[T_2]], [[F_2]]
; CHECK-NEXT: [[RES_3:%.*]] = xor i1 true, false
; CHECK-NEXT: ret i1 [[RES_3]]
;
entry:
Expand Down Expand Up @@ -105,9 +101,7 @@ define i1 @simplify_based_on_switch_successor_branches(i8 %x) {
; CHECK-NEXT: [[RES_1:%.*]] = xor i1 [[C_1]], [[C_2]]
; CHECK-NEXT: ret i1 [[RES_1]]
; CHECK: exit.2:
; CHECK-NEXT: [[T_1:%.*]] = icmp ult i8 [[X]], 7
; CHECK-NEXT: [[F_1:%.*]] = icmp ult i8 [[X]], 6
; CHECK-NEXT: [[RES_2:%.*]] = xor i1 [[T_1]], [[F_1]]
; CHECK-NEXT: [[RES_2:%.*]] = xor i1 true, false
; CHECK-NEXT: call void @use(i1 [[RES_2]])
; CHECK-NEXT: br label [[EXIT_3]]
; CHECK: exit.3:
Expand Down