112 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt -S -passes=instcombine < %s | FileCheck %s3 4@g = external global i325 6define i1 @smin(i32 %other) {7; CHECK-LABEL: @smin(8; CHECK-NEXT: [[TEST:%.*]] = icmp sgt i32 [[OTHER:%.*]], 09; CHECK-NEXT: ret i1 [[TEST]]10;11 %positive = load i32, ptr @g, !range !{i32 1, i32 2048}12 %cmp = icmp slt i32 %positive, %other13 %sel = select i1 %cmp, i32 %positive, i32 %other14 %test = icmp sgt i32 %sel, 015 ret i1 %test16}17 18define i1 @smin_int(i32 %other) {19; CHECK-LABEL: @smin_int(20; CHECK-NEXT: [[TEST:%.*]] = icmp sgt i32 [[OTHER:%.*]], 021; CHECK-NEXT: ret i1 [[TEST]]22;23 %positive = load i32, ptr @g, !range !{i32 1, i32 2048}24 %smin = call i32 @llvm.smin.i32(i32 %positive, i32 %other)25 %test = icmp sgt i32 %smin, 026 ret i1 %test27}28declare i32 @llvm.smin.i32(i32, i32)29 30; Range metadata doesn't work for vectors, so find another way to trigger isKnownPositive().31 32define <2 x i1> @smin_vec(<2 x i32> %x, <2 x i32> %other) {33; CHECK-LABEL: @smin_vec(34; CHECK-NEXT: [[TEST:%.*]] = icmp sgt <2 x i32> [[OTHER:%.*]], zeroinitializer35; CHECK-NEXT: ret <2 x i1> [[TEST]]36;37 %notneg = and <2 x i32> %x, <i32 7, i32 7>38 %positive = or <2 x i32> %notneg, <i32 1, i32 1>39 %cmp = icmp slt <2 x i32> %positive, %other40 %sel = select <2 x i1> %cmp, <2 x i32> %positive, <2 x i32> %other41 %test = icmp sgt <2 x i32> %sel, zeroinitializer42 ret <2 x i1> %test43}44 45define i1 @smin_commute(i32 %other) {46; CHECK-LABEL: @smin_commute(47; CHECK-NEXT: [[TEST:%.*]] = icmp sgt i32 [[OTHER:%.*]], 048; CHECK-NEXT: ret i1 [[TEST]]49;50 %positive = load i32, ptr @g, !range !{i32 1, i32 2048}51 %cmp = icmp slt i32 %other, %positive52 %sel = select i1 %cmp, i32 %other, i32 %positive53 %test = icmp sgt i32 %sel, 054 ret i1 %test55}56 57define <2 x i1> @smin_commute_vec(<2 x i32> %x, <2 x i32> %other) {58; CHECK-LABEL: @smin_commute_vec(59; CHECK-NEXT: [[TEST:%.*]] = icmp sgt <2 x i32> [[OTHER:%.*]], zeroinitializer60; CHECK-NEXT: ret <2 x i1> [[TEST]]61;62 %notneg = and <2 x i32> %x, <i32 7, i32 7>63 %positive = or <2 x i32> %notneg, <i32 1, i32 1>64 %cmp = icmp slt <2 x i32> %other, %positive65 %sel = select <2 x i1> %cmp, <2 x i32> %other, <2 x i32> %positive66 %test = icmp sgt <2 x i32> %sel, zeroinitializer67 ret <2 x i1> %test68}69 70define <2 x i1> @smin_commute_vec_poison_elts(<2 x i32> %x, <2 x i32> %other) {71; CHECK-LABEL: @smin_commute_vec_poison_elts(72; CHECK-NEXT: [[TEST:%.*]] = icmp sgt <2 x i32> [[OTHER:%.*]], <i32 0, i32 poison>73; CHECK-NEXT: ret <2 x i1> [[TEST]]74;75 %notneg = and <2 x i32> %x, <i32 7, i32 7>76 %positive = or <2 x i32> %notneg, <i32 1, i32 1>77 %cmp = icmp slt <2 x i32> %other, %positive78 %sel = select <2 x i1> %cmp, <2 x i32> %other, <2 x i32> %positive79 %test = icmp sgt <2 x i32> %sel, <i32 0, i32 poison>80 ret <2 x i1> %test81}82; %positive might be zero83 84define i1 @maybe_not_positive(i32 %other) {85; CHECK-LABEL: @maybe_not_positive(86; CHECK-NEXT: [[POSITIVE:%.*]] = load i32, ptr @g, align 4, !range [[RNG0:![0-9]+]]87; CHECK-NEXT: [[SEL:%.*]] = call i32 @llvm.smin.i32(i32 [[POSITIVE]], i32 [[OTHER:%.*]])88; CHECK-NEXT: [[TEST:%.*]] = icmp sgt i32 [[SEL]], 089; CHECK-NEXT: ret i1 [[TEST]]90;91 %positive = load i32, ptr @g, !range !{i32 0, i32 2048}92 %cmp = icmp slt i32 %positive, %other93 %sel = select i1 %cmp, i32 %positive, i32 %other94 %test = icmp sgt i32 %sel, 095 ret i1 %test96}97 98define <2 x i1> @maybe_not_positive_vec(<2 x i32> %x, <2 x i32> %other) {99; CHECK-LABEL: @maybe_not_positive_vec(100; CHECK-NEXT: [[NOTNEG:%.*]] = and <2 x i32> [[X:%.*]], splat (i32 7)101; CHECK-NEXT: [[SEL:%.*]] = call <2 x i32> @llvm.smin.v2i32(<2 x i32> [[NOTNEG]], <2 x i32> [[OTHER:%.*]])102; CHECK-NEXT: [[TEST:%.*]] = icmp sgt <2 x i32> [[SEL]], zeroinitializer103; CHECK-NEXT: ret <2 x i1> [[TEST]]104;105 %notneg = and <2 x i32> %x, <i32 7, i32 7>106 %cmp = icmp slt <2 x i32> %notneg, %other107 %sel = select <2 x i1> %cmp, <2 x i32> %notneg, <2 x i32> %other108 %test = icmp sgt <2 x i32> %sel, zeroinitializer109 ret <2 x i1> %test110}111 112