Skip to content

Commit e9dfe08

Browse files
aleks-tmbAleksander Popov
and
Aleksander Popov
authored
[GuardUtils] Revert llvm::isWidenableBranch change (llvm#66411)
In the d6e7c16 was introduced util to to extract widenable conditions from branch. That util was applied in the llvm::isWidenableBranch to check if branch is widenable. So we consider branch is widenable if it has widenable condition anywhere in the condition tree. But that will be true when we finish GuardWidening reworking from branch widening to widenable conditions widening. For now we still need to check that widenable branch is in the form of: `br(widenable_condition & (...))`, because that form is assumed by LoopPredication and GuardWidening algorithms. Fixes: llvm#66418 Co-authored-by: Aleksander Popov <[email protected]>
1 parent 4670777 commit e9dfe08

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

Diff for: llvm/lib/Analysis/GuardUtils.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ bool llvm::isWidenableCondition(const Value *V) {
2424
}
2525

2626
bool llvm::isWidenableBranch(const User *U) {
27-
return extractWidenableCondition(U) != nullptr;
27+
Value *Condition, *WidenableCondition;
28+
BasicBlock *GuardedBB, *DeoptBB;
29+
return parseWidenableBranch(U, Condition, WidenableCondition, GuardedBB,
30+
DeoptBB);
2831
}
2932

3033
bool llvm::isGuardAsWidenableBranch(const User *U) {

Diff for: llvm/test/Transforms/LoopPredication/basic_widenable_branch_guards.ll

+50
Original file line numberDiff line numberDiff line change
@@ -2144,6 +2144,56 @@ exit: ; preds = %guarded, %entry
21442144
ret i32 %result
21452145
}
21462146

2147+
; TODO: Support widenable branch in the form of br((wc and cond0) and cond1)
2148+
; At present LoopPredication assumes the form of br(wc && (...)) only.
2149+
define i32 @wc_deep_in_expression_tree(i1 %cond0, i1 %cond1, i32 %limit) {
2150+
; CHECK-LABEL: @wc_deep_in_expression_tree(
2151+
; CHECK-NEXT: entry:
2152+
; CHECK-NEXT: [[WC:%.*]] = call i1 @llvm.experimental.widenable.condition()
2153+
; CHECK-NEXT: [[AND0:%.*]] = and i1 [[WC]], [[COND0:%.*]]
2154+
; CHECK-NEXT: [[AND1:%.*]] = and i1 [[AND0]], [[COND1:%.*]]
2155+
; CHECK-NEXT: br i1 [[AND1]], label [[LOOP_PREHEADER:%.*]], label [[DEOPT:%.*]]
2156+
; CHECK: loop.preheader:
2157+
; CHECK-NEXT: br label [[LOOP:%.*]]
2158+
; CHECK: loop:
2159+
; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[IV_NEXT:%.*]], [[GUARDED:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
2160+
; CHECK-NEXT: [[GUARD_COND:%.*]] = icmp sgt i32 [[IV]], 100
2161+
; CHECK-NEXT: br i1 [[GUARD_COND]], label [[DEOPT_LOOPEXIT:%.*]], label [[GUARDED]]
2162+
; CHECK: guarded:
2163+
; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], 1
2164+
; CHECK-NEXT: [[EXIT_COND:%.*]] = icmp ult i32 [[IV]], [[LIMIT:%.*]]
2165+
; CHECK-NEXT: br i1 [[EXIT_COND]], label [[LOOP]], label [[EXIT:%.*]]
2166+
; CHECK: deopt.loopexit:
2167+
; CHECK-NEXT: br label [[DEOPT]]
2168+
; CHECK: deopt:
2169+
; CHECK-NEXT: [[DEOPTCALL:%.*]] = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ]
2170+
; CHECK-NEXT: ret i32 [[DEOPTCALL]]
2171+
; CHECK: exit:
2172+
; CHECK-NEXT: ret i32 0
2173+
;
2174+
entry:
2175+
%wc = call i1 @llvm.experimental.widenable.condition()
2176+
%and0 = and i1 %wc, %cond0
2177+
%and1 = and i1 %and0, %cond1
2178+
br i1 %and1, label %loop, label %deopt
2179+
2180+
loop:
2181+
%iv = phi i32 [ %iv.next, %guarded ], [ 0, %entry ]
2182+
%guard.cond = icmp sgt i32 %iv, 100
2183+
br i1 %guard.cond, label %deopt, label %guarded
2184+
2185+
guarded:
2186+
%iv.next = add i32 %iv, 1
2187+
%exit.cond = icmp ult i32 %iv, %limit
2188+
br i1 %exit.cond, label %loop, label %exit
2189+
2190+
deopt:
2191+
%deoptcall = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ]
2192+
ret i32 %deoptcall
2193+
exit:
2194+
ret i32 0
2195+
}
2196+
21472197
declare i32 @llvm.experimental.deoptimize.i32(...)
21482198

21492199
; Function Attrs: inaccessiblememonly nounwind

0 commit comments

Comments
 (0)