Files
clang-p2996/llvm/test/Transforms/SimpleLoopUnswitch/2007-08-01-LCSSA.ll
Nikita Popov d77067d08a [ValueTracking] Add dominating condition support in computeKnownBits() (#73662)
This adds support for using dominating conditions in computeKnownBits()
when called from InstCombine. The implementation uses a
DomConditionCache, which stores which branches may provide information
that is relevant for a given value.

DomConditionCache is similar to AssumptionCache, but does not try to do
any kind of automatic tracking. Relevant branches have to be explicitly
registered and invalidated values explicitly removed. The necessary
tracking is done inside InstCombine.

The reason why this doesn't just do exactly the same thing as
AssumptionCache is that a lot more transforms touch branches and branch
conditions than assumptions. AssumptionCache is an immutable analysis
and mostly gets away with this because only a handful of places have to
register additional assumptions (mostly as a result of cloning). This is
very much not the case for branches.

This change regresses compile-time by about ~0.2%. It also improves
stage2-O0-g builds by about ~0.2%, which indicates that this change results
in additional optimizations inside clang itself.

Fixes https://github.com/llvm/llvm-project/issues/74242.
2023-12-06 14:17:18 +01:00

74 lines
2.5 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
; RUN: opt < %s -S -passes='loop(simple-loop-unswitch),instcombine<no-verify-fixpoint>' -verify-memoryssa | FileCheck %s
; We do not reach a fixpoint, because we first have to infer nsw on the IV add,
; and could eliminate the icmp slt afterwards, but don't revisit it.
@.str9 = external constant [1 x i8]
declare i32 @strcmp(ptr, ptr)
define i32 @_ZN9Generator6strregEPKc(ptr %this, ptr %s) {
; CHECK-LABEL: define i32 @_ZN9Generator6strregEPKc(
; CHECK-SAME: ptr [[THIS:%.*]], ptr [[S:%.*]]) {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[TMP122:%.*]] = icmp eq ptr [[S]], null
; CHECK-NEXT: br label [[BB184:%.*]]
; CHECK: bb55:
; CHECK-NEXT: ret i32 0
; CHECK: bb88:
; CHECK-NEXT: br i1 [[TMP122]], label [[BB154:%.*]], label [[BB128:%.*]]
; CHECK: bb128:
; CHECK-NEXT: [[TMP138:%.*]] = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) null, ptr noundef nonnull dereferenceable(1) [[S]])
; CHECK-NEXT: [[IFTMP_37_0_IN4:%.*]] = icmp eq i32 [[TMP138]], 0
; CHECK-NEXT: br i1 [[IFTMP_37_0_IN4]], label [[BB250:%.*]], label [[BB166:%.*]]
; CHECK: bb154:
; CHECK-NEXT: br i1 false, label [[BB250]], label [[BB166]]
; CHECK: bb166:
; CHECK-NEXT: [[TMP175:%.*]] = add i32 [[IDX_0:%.*]], 1
; CHECK-NEXT: [[TMP183:%.*]] = add nsw i32 [[I33_0:%.*]], 1
; CHECK-NEXT: br label [[BB184]]
; CHECK: bb184:
; CHECK-NEXT: [[I33_0]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[TMP183]], [[BB166]] ]
; CHECK-NEXT: [[IDX_0]] = phi i32 [ 0, [[ENTRY]] ], [ [[TMP175]], [[BB166]] ]
; CHECK-NEXT: [[TMP49:%.*]] = icmp slt i32 [[I33_0]], 0
; CHECK-NEXT: br i1 [[TMP49]], label [[BB88:%.*]], label [[BB55:%.*]]
; CHECK: bb250:
; CHECK-NEXT: ret i32 [[IDX_0]]
;
entry:
%s_addr.0 = select i1 false, ptr @.str9, ptr %s
%tmp122 = icmp eq ptr %s_addr.0, null
br label %bb184
bb55:
ret i32 0
bb88:
br i1 %tmp122, label %bb154, label %bb128
bb128:
%tmp138 = call i32 @strcmp( ptr null, ptr %s_addr.0 )
%iftmp.37.0.in4 = icmp eq i32 %tmp138, 0
br i1 %iftmp.37.0.in4, label %bb250, label %bb166
bb154:
br i1 false, label %bb250, label %bb166
bb166:
%tmp175 = add i32 %idx.0, 1
%tmp177 = add i32 %tmp175, 0
%tmp181 = add i32 %tmp177, 0
%tmp183 = add i32 %i33.0, 1
br label %bb184
bb184:
%i33.0 = phi i32 [ 0, %entry ], [ %tmp183, %bb166 ]
%idx.0 = phi i32 [ 0, %entry ], [ %tmp181, %bb166 ]
%tmp49 = icmp slt i32 %i33.0, 0
br i1 %tmp49, label %bb88, label %bb55
bb250:
ret i32 %idx.0
}