; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
; RUN: opt -S -passes=instcombine < %s | FileCheck %s
; Make sure that the result of computeKnownBits for %indvar is correct.
define i16 @pr100298() {
; CHECK-LABEL: define i16 @pr100298() {
; CHECK-NEXT: [[ENTRY:.*]]:
; CHECK-NEXT: br label %[[FOR_INC:.*]]
; CHECK: [[FOR_INC]]:
; CHECK-NEXT: [[INDVAR:%.*]] = phi i32 [ -15, %[[ENTRY]] ], [ [[MASK:%.*]], %[[FOR_INC]] ]
; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[INDVAR]], 9
; CHECK-NEXT: [[MASK]] = and i32 [[ADD]], 65535
; CHECK-NEXT: [[CMP1:%.*]] = icmp ugt i32 [[MASK]], 5
; CHECK-NEXT: br i1 [[CMP1]], label %[[FOR_INC]], label %[[FOR_END:.*]]
; CHECK: [[FOR_END]]:
; CHECK-NEXT: [[CONV:%.*]] = trunc i32 [[ADD]] to i16
; CHECK-NEXT: [[CMP2:%.*]] = icmp ugt i32 [[MASK]], 3
; CHECK-NEXT: [[SHL:%.*]] = shl nuw i16 [[CONV]], 14
; CHECK-NEXT: [[RES:%.*]] = select i1 [[CMP2]], i16 [[CONV]], i16 [[SHL]]
; CHECK-NEXT: ret i16 [[RES]]
;
entry:
br label %for.inc
for.inc:
%indvar = phi i32 [ -15, %entry ], [ %mask, %for.inc ]
%add = add nsw i32 %indvar, 9
%mask = and i32 %add, 65535
%cmp1 = icmp ugt i32 %mask, 5
br i1 %cmp1, label %for.inc, label %for.end
for.end:
%conv = trunc i32 %add to i16
%cmp2 = icmp ugt i32 %mask, 3
%shl = shl nuw i16 %conv, 14
%res = select i1 %cmp2, i16 %conv, i16 %shl
ret i16 %res
}