110 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=instcombine -S | FileCheck %s3 4; Fold5; (-1 u/ %x) u>= %y6; to7; @llvm.umul.with.overflow(%x, %y) + extractvalue + not8 9define i1 @t0_basic(i8 %x, i8 %y) {10; CHECK-LABEL: @t0_basic(11; CHECK-NEXT: [[MUL:%.*]] = call { i8, i1 } @llvm.umul.with.overflow.i8(i8 [[X:%.*]], i8 [[Y:%.*]])12; CHECK-NEXT: [[MUL_OV:%.*]] = extractvalue { i8, i1 } [[MUL]], 113; CHECK-NEXT: [[MUL_NOT_OV:%.*]] = xor i1 [[MUL_OV]], true14; CHECK-NEXT: ret i1 [[MUL_NOT_OV]]15;16 %t0 = udiv i8 -1, %x17 %r = icmp uge i8 %t0, %y18 ret i1 %r19}20 21define <2 x i1> @t1_vec(<2 x i8> %x, <2 x i8> %y) {22; CHECK-LABEL: @t1_vec(23; CHECK-NEXT: [[MUL:%.*]] = call { <2 x i8>, <2 x i1> } @llvm.umul.with.overflow.v2i8(<2 x i8> [[X:%.*]], <2 x i8> [[Y:%.*]])24; CHECK-NEXT: [[MUL_OV:%.*]] = extractvalue { <2 x i8>, <2 x i1> } [[MUL]], 125; CHECK-NEXT: [[MUL_NOT_OV:%.*]] = xor <2 x i1> [[MUL_OV]], splat (i1 true)26; CHECK-NEXT: ret <2 x i1> [[MUL_NOT_OV]]27;28 %t0 = udiv <2 x i8> <i8 -1, i8 -1>, %x29 %r = icmp uge <2 x i8> %t0, %y30 ret <2 x i1> %r31}32 33define <3 x i1> @t2_vec_poison(<3 x i8> %x, <3 x i8> %y) {34; CHECK-LABEL: @t2_vec_poison(35; CHECK-NEXT: [[MUL:%.*]] = call { <3 x i8>, <3 x i1> } @llvm.umul.with.overflow.v3i8(<3 x i8> [[X:%.*]], <3 x i8> [[Y:%.*]])36; CHECK-NEXT: [[MUL_OV:%.*]] = extractvalue { <3 x i8>, <3 x i1> } [[MUL]], 137; CHECK-NEXT: [[MUL_NOT_OV:%.*]] = xor <3 x i1> [[MUL_OV]], splat (i1 true)38; CHECK-NEXT: ret <3 x i1> [[MUL_NOT_OV]]39;40 %t0 = udiv <3 x i8> <i8 -1, i8 poison, i8 -1>, %x41 %r = icmp uge <3 x i8> %t0, %y42 ret <3 x i1> %r43}44 45declare i8 @gen8()46 47define i1 @t3_commutative(i8 %x) {48; CHECK-LABEL: @t3_commutative(49; CHECK-NEXT: [[Y:%.*]] = call i8 @gen8()50; CHECK-NEXT: [[MUL:%.*]] = call { i8, i1 } @llvm.umul.with.overflow.i8(i8 [[X:%.*]], i8 [[Y]])51; CHECK-NEXT: [[MUL_OV:%.*]] = extractvalue { i8, i1 } [[MUL]], 152; CHECK-NEXT: [[MUL_NOT_OV:%.*]] = xor i1 [[MUL_OV]], true53; CHECK-NEXT: ret i1 [[MUL_NOT_OV]]54;55 %t0 = udiv i8 -1, %x56 %y = call i8 @gen8()57 %r = icmp ule i8 %y, %t0 ; swapped58 ret i1 %r59}60 61; Negative tests62 63declare void @use8(i8)64 65define i1 @n4_extrause(i8 %x, i8 %y) {66; CHECK-LABEL: @n4_extrause(67; CHECK-NEXT: [[T0:%.*]] = udiv i8 -1, [[X:%.*]]68; CHECK-NEXT: call void @use8(i8 [[T0]])69; CHECK-NEXT: [[R:%.*]] = icmp uge i8 [[T0]], [[Y:%.*]]70; CHECK-NEXT: ret i1 [[R]]71;72 %t0 = udiv i8 -1, %x73 call void @use8(i8 %t0)74 %r = icmp uge i8 %t0, %y75 ret i1 %r76}77 78define i1 @n5_not_negone(i8 %x, i8 %y) {79; CHECK-LABEL: @n5_not_negone(80; CHECK-NEXT: [[T0:%.*]] = udiv i8 -2, [[X:%.*]]81; CHECK-NEXT: [[R:%.*]] = icmp uge i8 [[T0]], [[Y:%.*]]82; CHECK-NEXT: ret i1 [[R]]83;84 %t0 = udiv i8 -2, %x ; not -185 %r = icmp uge i8 %t0, %y86 ret i1 %r87}88 89define i1 @n6_wrong_pred0(i8 %x, i8 %y) {90; CHECK-LABEL: @n6_wrong_pred0(91; CHECK-NEXT: [[T0:%.*]] = udiv i8 -1, [[X:%.*]]92; CHECK-NEXT: [[R:%.*]] = icmp ule i8 [[T0]], [[Y:%.*]]93; CHECK-NEXT: ret i1 [[R]]94;95 %t0 = udiv i8 -1, %x96 %r = icmp ule i8 %t0, %y ; not uge97 ret i1 %r98}99 100define i1 @n6_wrong_pred1(i8 %x, i8 %y) {101; CHECK-LABEL: @n6_wrong_pred1(102; CHECK-NEXT: [[T0:%.*]] = udiv i8 -1, [[X:%.*]]103; CHECK-NEXT: [[R:%.*]] = icmp ugt i8 [[T0]], [[Y:%.*]]104; CHECK-NEXT: ret i1 [[R]]105;106 %t0 = udiv i8 -1, %x107 %r = icmp ugt i8 %t0, %y ; not uge108 ret i1 %r109}110