39 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=instcombine -S | FileCheck %s3 4; Test that this transform works:5; udiv X, (Select Cond, C1, C2) --> Select Cond, (shr X, C1), (shr X, C2)6 7define i64 @test(i64 %X, i1 %Cond ) {8; CHECK-LABEL: @test(9; CHECK-NEXT: [[QUOTIENT11:%.*]] = lshr i64 [[X:%.*]], 410; CHECK-NEXT: [[QUOTIENT22:%.*]] = lshr i64 [[X]], 311; CHECK-NEXT: [[SUM:%.*]] = add nuw nsw i64 [[QUOTIENT11]], [[QUOTIENT22]]12; CHECK-NEXT: ret i64 [[SUM]]13;14 %divisor1 = select i1 %Cond, i64 16, i64 815 %quotient1 = udiv i64 %X, %divisor116 %divisor2 = select i1 %Cond, i64 8, i64 017 %quotient2 = udiv i64 %X, %divisor218 %sum = add i64 %quotient1, %quotient219 ret i64 %sum20}21 22; https://bugs.llvm.org/show_bug.cgi?id=3485623; This would assert/crash because we didn't propagate the condition with the correct vector type.24 25define <2 x i32> @PR34856(<2 x i32> %t0, <2 x i32> %t1) {26; CHECK-LABEL: @PR34856(27; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt <2 x i32> [[T1:%.*]], splat (i32 -8)28; CHECK-NEXT: [[DIV1:%.*]] = zext <2 x i1> [[TMP1]] to <2 x i32>29; CHECK-NEXT: ret <2 x i32> [[DIV1]]30;31 %cmp = icmp eq <2 x i32> %t0, <i32 1, i32 1>32 %zext = zext <2 x i1> %cmp to <2 x i32>33 %neg = select <2 x i1> %cmp, <2 x i32> zeroinitializer, <2 x i32> <i32 -7, i32 -7>34 %div1 = udiv <2 x i32> %t1, %neg35 %use_cmp_again = add <2 x i32> %div1, %zext36 ret <2 x i32> %use_cmp_again37}38 39