
SCCP can use PredicateInfo to constrain ranges based on assume and branch conditions. Currently, this is only enabled during IPSCCP. This enables it for SCCP as well, which runs after functions have already been simplified, while IPSCCP runs pre-inline. To a large degree, CVP already handles range-based optimizations, but SCCP is more reliable for the cases it can handle. In particular, SCCP works reliably inside loops, which is something that CVP struggles with due to LVI cycles. I have made various optimizations to make PredicateInfo more efficient, but unfortunately this still has significant compile-time cost (around 0.1-0.2%).
46 lines
1.4 KiB
LLVM
46 lines
1.4 KiB
LLVM
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
|
|
; RUN: opt -passes=sccp -S < %s | FileCheck %s
|
|
|
|
define i32 @main() {
|
|
; CHECK-LABEL: define range(i32 33554432, 0) i32 @main() {
|
|
; CHECK-NEXT: [[ENTRY:.*]]:
|
|
; CHECK-NEXT: br label %[[LBL_1154:.*]]
|
|
; CHECK: [[LBL_1154]]:
|
|
; CHECK-NEXT: [[B0_0:%.*]] = phi i32 [ -119, %[[ENTRY]] ], [ 0, %[[LBL_1154]] ]
|
|
; CHECK-NEXT: [[CMP11:%.*]] = icmp slt i32 [[B0_0]], 0
|
|
; CHECK-NEXT: [[SHL_OP:%.*]] = shl nuw nsw i32 33554432, [[B0_0]]
|
|
; CHECK-NEXT: [[CMP1445:%.*]] = icmp ult i32 [[SHL_OP]], 33554432
|
|
; CHECK-NEXT: [[CMP14:%.*]] = or i1 [[CMP11]], [[CMP1445]]
|
|
; CHECK-NEXT: br i1 [[CMP14]], label %[[LBL_1154]], label %[[IF_END19:.*]]
|
|
; CHECK: [[IF_END19]]:
|
|
; CHECK-NEXT: br i1 [[CMP11]], label %[[IF_THEN22:.*]], label %[[CLEANUP26:.*]]
|
|
; CHECK: [[IF_THEN22]]:
|
|
; CHECK-NEXT: tail call void @abort()
|
|
; CHECK-NEXT: unreachable
|
|
; CHECK: [[CLEANUP26]]:
|
|
; CHECK-NEXT: ret i32 [[SHL_OP]]
|
|
;
|
|
entry:
|
|
br label %lbl_1154
|
|
|
|
lbl_1154:
|
|
%b0.0 = phi i32 [ -119, %entry ], [ 0, %lbl_1154 ]
|
|
%cmp11 = icmp slt i32 %b0.0, 0
|
|
%shl.op = shl i32 33554432, %b0.0
|
|
%cmp1445 = icmp ult i32 %shl.op, 33554432
|
|
%cmp14 = or i1 %cmp11, %cmp1445
|
|
br i1 %cmp14, label %lbl_1154, label %if.end19
|
|
|
|
if.end19:
|
|
br i1 %cmp11, label %if.then22, label %cleanup26
|
|
|
|
if.then22:
|
|
tail call void @abort()
|
|
unreachable
|
|
|
|
cleanup26:
|
|
ret i32 %shl.op
|
|
}
|
|
|
|
declare void @abort()
|