Non-determenism is fixed. Guard widening optimization is able to move the condition from one guard to the previous one. As a result if the condition is poison and orginal second guard is never executed but the first one does, we introduce undefined behavior which was not observed in original program. To resolve the issue we must freeze the condition we are moving. However optimization itself does not know how to work with freeze. Additionally optimization is written in incremental way. For example we have three guards G1(base + 8 < L) G2(base + 16 < L) G3(base + 24 < L) On the first step GW will combine G1 and G2 as G1(base + 8 < L && freeze(base + 16 < L)) G2(true) G3(base + 24 < L) while combining G1 and G3 base appears to be different. To keep optimization enabled after freezing the moving condition, the freeze instruction is pushed as much as possible and later all uses of freezed values are replaced with frozen version. This is similar what instruction combining does but more aggressevely.
76 lines
3.3 KiB
LLVM
76 lines
3.3 KiB
LLVM
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
|
; RUN: opt -S -guard-widening-widen-branch-guards=true -passes=guard-widening < %s | FileCheck %s
|
|
; RUN: opt -S -guard-widening-widen-branch-guards=true -passes=guard-widening < %s | FileCheck %s
|
|
|
|
; Interaction between intrinsic and widenable condition guards.
|
|
|
|
declare void @llvm.experimental.guard(i1,...)
|
|
|
|
declare void @llvm.experimental.deoptimize.isVoid(...)
|
|
|
|
; Function Attrs: inaccessiblememonly nounwind
|
|
declare i1 @llvm.experimental.widenable.condition() #0
|
|
|
|
; Widen condition of intrinsic guard with a condition from widenable branch.
|
|
define void @test_01(i1 %cond_0, i1 %cond_1) {
|
|
; CHECK-LABEL: @test_01(
|
|
; CHECK-NEXT: entry:
|
|
; CHECK-NEXT: [[COND_1_GW_FR:%.*]] = freeze i1 [[COND_1:%.*]]
|
|
; CHECK-NEXT: [[WIDE_CHK:%.*]] = and i1 [[COND_0:%.*]], [[COND_1_GW_FR]]
|
|
; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 [[WIDE_CHK]]) [ "deopt"() ]
|
|
; CHECK-NEXT: [[WIDENABLE_COND3:%.*]] = call i1 @llvm.experimental.widenable.condition()
|
|
; CHECK-NEXT: [[EXIPLICIT_GUARD_COND4:%.*]] = and i1 [[COND_1_GW_FR]], [[WIDENABLE_COND3]]
|
|
; CHECK-NEXT: br i1 true, label [[GUARDED1:%.*]], label [[DEOPT2:%.*]], !prof [[PROF0:![0-9]+]]
|
|
; CHECK: deopt2:
|
|
; CHECK-NEXT: call void (...) @llvm.experimental.deoptimize.isVoid() [ "deopt"() ]
|
|
; CHECK-NEXT: ret void
|
|
; CHECK: guarded1:
|
|
; CHECK-NEXT: ret void
|
|
;
|
|
entry:
|
|
call void (i1, ...) @llvm.experimental.guard(i1 %cond_0) [ "deopt"() ]
|
|
%widenable_cond3 = call i1 @llvm.experimental.widenable.condition()
|
|
%exiplicit_guard_cond4 = and i1 %cond_1, %widenable_cond3
|
|
br i1 %exiplicit_guard_cond4, label %guarded1, label %deopt2, !prof !0
|
|
|
|
deopt2: ; preds = %guarded
|
|
call void (...) @llvm.experimental.deoptimize.isVoid() [ "deopt"() ]
|
|
ret void
|
|
|
|
guarded1: ; preds = %guarded
|
|
ret void
|
|
}
|
|
|
|
; Widen condition of widenable condition guard with a condition from intrinsic.
|
|
define void @test_02(i1 %cond_0, i1 %cond_1) {
|
|
; CHECK-LABEL: @test_02(
|
|
; CHECK-NEXT: entry:
|
|
; CHECK-NEXT: [[COND_1_GW_FR:%.*]] = freeze i1 [[COND_1:%.*]]
|
|
; CHECK-NEXT: [[WIDE_CHK:%.*]] = and i1 [[COND_0:%.*]], [[COND_1_GW_FR]]
|
|
; CHECK-NEXT: [[WIDENABLE_COND:%.*]] = call i1 @llvm.experimental.widenable.condition()
|
|
; CHECK-NEXT: [[EXIPLICIT_GUARD_COND:%.*]] = and i1 [[WIDE_CHK]], [[WIDENABLE_COND]]
|
|
; CHECK-NEXT: br i1 [[EXIPLICIT_GUARD_COND]], label [[GUARDED:%.*]], label [[DEOPT:%.*]], !prof [[PROF0]]
|
|
; CHECK: deopt:
|
|
; CHECK-NEXT: call void (...) @llvm.experimental.deoptimize.isVoid() [ "deopt"() ]
|
|
; CHECK-NEXT: ret void
|
|
; CHECK: guarded:
|
|
; CHECK-NEXT: ret void
|
|
;
|
|
entry:
|
|
%widenable_cond = call i1 @llvm.experimental.widenable.condition()
|
|
%exiplicit_guard_cond = and i1 %cond_0, %widenable_cond
|
|
br i1 %exiplicit_guard_cond, label %guarded, label %deopt, !prof !0
|
|
|
|
deopt: ; preds = %entry
|
|
call void (...) @llvm.experimental.deoptimize.isVoid() [ "deopt"() ]
|
|
ret void
|
|
|
|
guarded: ; preds = %entry
|
|
call void (i1, ...) @llvm.experimental.guard(i1 %cond_1) [ "deopt"() ]
|
|
ret void
|
|
}
|
|
|
|
attributes #0 = { inaccessiblememonly nounwind }
|
|
|
|
!0 = !{!"branch_weights", i32 1048576, i32 1}
|