365 lines
		
	
	
		
			7.8 KiB
		
	
	
	
		
			LLVM
		
	
	
	
			
		
		
	
	
			365 lines
		
	
	
		
			7.8 KiB
		
	
	
	
		
			LLVM
		
	
	
	
| ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
 | |
| ; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
 | |
| 
 | |
| define i8 @smax_min_limit(i8 %x) {
 | |
| ; CHECK-LABEL: @smax_min_limit(
 | |
| ; CHECK-NEXT:    ret i8 [[X:%.*]]
 | |
| ;
 | |
|   %cmp = icmp sgt i8 %x, -128
 | |
|   %sel = select i1 %cmp, i8 %x, i8 -128
 | |
|   ret i8 %sel
 | |
| }
 | |
| 
 | |
| define i8 @smin_max_limit(i8 %x) {
 | |
| ; CHECK-LABEL: @smin_max_limit(
 | |
| ; CHECK-NEXT:    ret i8 [[X:%.*]]
 | |
| ;
 | |
|   %cmp = icmp slt i8 %x, 127
 | |
|   %sel = select i1 %cmp, i8 %x, i8 127
 | |
|   ret i8 %sel
 | |
| }
 | |
| 
 | |
| define <2 x i8> @umax_min_limit(<2 x i8> %x) {
 | |
| ; CHECK-LABEL: @umax_min_limit(
 | |
| ; CHECK-NEXT:    ret <2 x i8> [[X:%.*]]
 | |
| ;
 | |
|   %cmp = icmp ugt <2 x i8> %x, zeroinitializer
 | |
|   %sel = select <2 x i1> %cmp, <2 x i8> %x, <2 x i8> zeroinitializer
 | |
|   ret <2 x i8> %sel
 | |
| }
 | |
| 
 | |
| define i8 @umin_max_limit(i8 %x) {
 | |
| ; CHECK-LABEL: @umin_max_limit(
 | |
| ; CHECK-NEXT:    ret i8 [[X:%.*]]
 | |
| ;
 | |
|   %cmp = icmp ult i8 %x, 255
 | |
|   %sel = select i1 %cmp, i8 %x, i8 255
 | |
|   ret i8 %sel
 | |
| }
 | |
| 
 | |
| ; negative test - wrong limit
 | |
| 
 | |
| define i8 @smax_not_min_limit(i8 %x) {
 | |
| ; CHECK-LABEL: @smax_not_min_limit(
 | |
| ; CHECK-NEXT:    [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], -127
 | |
| ; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[CMP]], i8 [[X]], i8 -127
 | |
| ; CHECK-NEXT:    ret i8 [[SEL]]
 | |
| ;
 | |
|   %cmp = icmp sgt i8 %x, -127
 | |
|   %sel = select i1 %cmp, i8 %x, i8 -127
 | |
|   ret i8 %sel
 | |
| }
 | |
| 
 | |
| ; negative test - wrong limit
 | |
| 
 | |
| define i8 @smin_not_min_limit(i8 %x) {
 | |
| ; CHECK-LABEL: @smin_not_min_limit(
 | |
| ; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0
 | |
| ; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[CMP]], i8 [[X]], i8 0
 | |
| ; CHECK-NEXT:    ret i8 [[SEL]]
 | |
| ;
 | |
|   %cmp = icmp slt i8 %x, 0
 | |
|   %sel = select i1 %cmp, i8 %x, i8 0
 | |
|   ret i8 %sel
 | |
| }
 | |
| 
 | |
| define i1 @max1(i32 %x, i32 %y) {
 | |
| ; CHECK-LABEL: @max1(
 | |
| ; CHECK-NEXT:    ret i1 false
 | |
| ;
 | |
|   %c = icmp sgt i32 %x, %y
 | |
|   %m = select i1 %c, i32 %x, i32 %y
 | |
|   %r = icmp slt i32 %m, %x
 | |
|   ret i1 %r
 | |
| }
 | |
| 
 | |
| define i1 @max2(i32 %x, i32 %y) {
 | |
| ; CHECK-LABEL: @max2(
 | |
| ; CHECK-NEXT:    ret i1 true
 | |
| ;
 | |
|   %c = icmp sge i32 %x, %y
 | |
|   %m = select i1 %c, i32 %x, i32 %y
 | |
|   %r = icmp sge i32 %m, %x
 | |
|   ret i1 %r
 | |
| }
 | |
| 
 | |
| define i1 @max3(i32 %x, i32 %y) {
 | |
| ; CHECK-LABEL: @max3(
 | |
| ; CHECK-NEXT:    ret i1 false
 | |
| ;
 | |
|   %c = icmp ugt i32 %x, %y
 | |
|   %m = select i1 %c, i32 %x, i32 %y
 | |
|   %r = icmp ult i32 %m, %x
 | |
|   ret i1 %r
 | |
| }
 | |
| 
 | |
| define i1 @max4(i32 %x, i32 %y) {
 | |
| ; CHECK-LABEL: @max4(
 | |
| ; CHECK-NEXT:    ret i1 true
 | |
| ;
 | |
|   %c = icmp uge i32 %x, %y
 | |
|   %m = select i1 %c, i32 %x, i32 %y
 | |
|   %r = icmp uge i32 %m, %x
 | |
|   ret i1 %r
 | |
| }
 | |
| 
 | |
| define i1 @max5(i32 %x, i32 %y) {
 | |
| ; CHECK-LABEL: @max5(
 | |
| ; CHECK-NEXT:    ret i1 false
 | |
| ;
 | |
|   %c = icmp sgt i32 %x, %y
 | |
|   %m = select i1 %c, i32 %x, i32 %y
 | |
|   %r = icmp sgt i32 %x, %m
 | |
|   ret i1 %r
 | |
| }
 | |
| 
 | |
| define i1 @max6(i32 %x, i32 %y) {
 | |
| ; CHECK-LABEL: @max6(
 | |
| ; CHECK-NEXT:    ret i1 true
 | |
| ;
 | |
|   %c = icmp sge i32 %x, %y
 | |
|   %m = select i1 %c, i32 %x, i32 %y
 | |
|   %r = icmp sle i32 %x, %m
 | |
|   ret i1 %r
 | |
| }
 | |
| 
 | |
| define i1 @max7(i32 %x, i32 %y) {
 | |
| ; CHECK-LABEL: @max7(
 | |
| ; CHECK-NEXT:    ret i1 false
 | |
| ;
 | |
|   %c = icmp ugt i32 %x, %y
 | |
|   %m = select i1 %c, i32 %x, i32 %y
 | |
|   %r = icmp ugt i32 %x, %m
 | |
|   ret i1 %r
 | |
| }
 | |
| 
 | |
| define i1 @max8(i32 %x, i32 %y) {
 | |
| ; CHECK-LABEL: @max8(
 | |
| ; CHECK-NEXT:    ret i1 true
 | |
| ;
 | |
|   %c = icmp uge i32 %x, %y
 | |
|   %m = select i1 %c, i32 %x, i32 %y
 | |
|   %r = icmp ule i32 %x, %m
 | |
|   ret i1 %r
 | |
| }
 | |
| 
 | |
| define i1 @min1(i32 %x, i32 %y) {
 | |
| ; CHECK-LABEL: @min1(
 | |
| ; CHECK-NEXT:    ret i1 false
 | |
| ;
 | |
|   %c = icmp sgt i32 %x, %y
 | |
|   %m = select i1 %c, i32 %y, i32 %x
 | |
|   %r = icmp sgt i32 %m, %x
 | |
|   ret i1 %r
 | |
| }
 | |
| 
 | |
| define i1 @min2(i32 %x, i32 %y) {
 | |
| ; CHECK-LABEL: @min2(
 | |
| ; CHECK-NEXT:    ret i1 true
 | |
| ;
 | |
|   %c = icmp sge i32 %x, %y
 | |
|   %m = select i1 %c, i32 %y, i32 %x
 | |
|   %r = icmp sle i32 %m, %x
 | |
|   ret i1 %r
 | |
| }
 | |
| 
 | |
| define i1 @min3(i32 %x, i32 %y) {
 | |
| ; CHECK-LABEL: @min3(
 | |
| ; CHECK-NEXT:    ret i1 false
 | |
| ;
 | |
|   %c = icmp ugt i32 %x, %y
 | |
|   %m = select i1 %c, i32 %y, i32 %x
 | |
|   %r = icmp ugt i32 %m, %x
 | |
|   ret i1 %r
 | |
| }
 | |
| 
 | |
| define i1 @min4(i32 %x, i32 %y) {
 | |
| ; CHECK-LABEL: @min4(
 | |
| ; CHECK-NEXT:    ret i1 true
 | |
| ;
 | |
|   %c = icmp uge i32 %x, %y
 | |
|   %m = select i1 %c, i32 %y, i32 %x
 | |
|   %r = icmp ule i32 %m, %x
 | |
|   ret i1 %r
 | |
| }
 | |
| 
 | |
| define i1 @min5(i32 %x, i32 %y) {
 | |
| ; CHECK-LABEL: @min5(
 | |
| ; CHECK-NEXT:    ret i1 false
 | |
| ;
 | |
|   %c = icmp sgt i32 %x, %y
 | |
|   %m = select i1 %c, i32 %y, i32 %x
 | |
|   %r = icmp slt i32 %x, %m
 | |
|   ret i1 %r
 | |
| }
 | |
| 
 | |
| define i1 @min6(i32 %x, i32 %y) {
 | |
| ; CHECK-LABEL: @min6(
 | |
| ; CHECK-NEXT:    ret i1 true
 | |
| ;
 | |
|   %c = icmp sge i32 %x, %y
 | |
|   %m = select i1 %c, i32 %y, i32 %x
 | |
|   %r = icmp sge i32 %x, %m
 | |
|   ret i1 %r
 | |
| }
 | |
| 
 | |
| define i1 @min7(i32 %x, i32 %y) {
 | |
| ; CHECK-LABEL: @min7(
 | |
| ; CHECK-NEXT:    ret i1 false
 | |
| ;
 | |
|   %c = icmp ugt i32 %x, %y
 | |
|   %m = select i1 %c, i32 %y, i32 %x
 | |
|   %r = icmp ult i32 %x, %m
 | |
|   ret i1 %r
 | |
| }
 | |
| 
 | |
| define i1 @min8(i32 %x, i32 %y) {
 | |
| ; CHECK-LABEL: @min8(
 | |
| ; CHECK-NEXT:    ret i1 true
 | |
| ;
 | |
|   %c = icmp uge i32 %x, %y
 | |
|   %m = select i1 %c, i32 %y, i32 %x
 | |
|   %r = icmp uge i32 %x, %m
 | |
|   ret i1 %r
 | |
| }
 | |
| 
 | |
| define i1 @maxmin1(i32 %x, i32 %y, i32 %z) {
 | |
| ; CHECK-LABEL: @maxmin1(
 | |
| ; CHECK-NEXT:    ret i1 true
 | |
| ;
 | |
|   %c1 = icmp sge i32 %x, %y
 | |
|   %max = select i1 %c1, i32 %x, i32 %y
 | |
|   %c2 = icmp sge i32 %x, %z
 | |
|   %min = select i1 %c2, i32 %z, i32 %x
 | |
|   %c = icmp sge i32 %max, %min
 | |
|   ret i1 %c
 | |
| }
 | |
| 
 | |
| define i1 @maxmin2(i32 %x, i32 %y, i32 %z) {
 | |
| ; CHECK-LABEL: @maxmin2(
 | |
| ; CHECK-NEXT:    ret i1 false
 | |
| ;
 | |
|   %c1 = icmp sge i32 %x, %y
 | |
|   %max = select i1 %c1, i32 %x, i32 %y
 | |
|   %c2 = icmp sge i32 %x, %z
 | |
|   %min = select i1 %c2, i32 %z, i32 %x
 | |
|   %c = icmp sgt i32 %min, %max
 | |
|   ret i1 %c
 | |
| }
 | |
| 
 | |
| define i1 @maxmin3(i32 %x, i32 %y, i32 %z) {
 | |
| ; CHECK-LABEL: @maxmin3(
 | |
| ; CHECK-NEXT:    ret i1 true
 | |
| ;
 | |
|   %c1 = icmp sge i32 %x, %y
 | |
|   %max = select i1 %c1, i32 %x, i32 %y
 | |
|   %c2 = icmp sge i32 %x, %z
 | |
|   %min = select i1 %c2, i32 %z, i32 %x
 | |
|   %c = icmp sle i32 %min, %max
 | |
|   ret i1 %c
 | |
| }
 | |
| 
 | |
| define i1 @maxmin4(i32 %x, i32 %y, i32 %z) {
 | |
| ; CHECK-LABEL: @maxmin4(
 | |
| ; CHECK-NEXT:    ret i1 false
 | |
| ;
 | |
|   %c1 = icmp sge i32 %x, %y
 | |
|   %max = select i1 %c1, i32 %x, i32 %y
 | |
|   %c2 = icmp sge i32 %x, %z
 | |
|   %min = select i1 %c2, i32 %z, i32 %x
 | |
|   %c = icmp slt i32 %max, %min
 | |
|   ret i1 %c
 | |
| }
 | |
| 
 | |
| define i1 @maxmin5(i32 %x, i32 %y, i32 %z) {
 | |
| ; CHECK-LABEL: @maxmin5(
 | |
| ; CHECK-NEXT:    ret i1 true
 | |
| ;
 | |
|   %c1 = icmp uge i32 %x, %y
 | |
|   %max = select i1 %c1, i32 %x, i32 %y
 | |
|   %c2 = icmp uge i32 %x, %z
 | |
|   %min = select i1 %c2, i32 %z, i32 %x
 | |
|   %c = icmp uge i32 %max, %min
 | |
|   ret i1 %c
 | |
| }
 | |
| 
 | |
| define i1 @maxmin6(i32 %x, i32 %y, i32 %z) {
 | |
| ; CHECK-LABEL: @maxmin6(
 | |
| ; CHECK-NEXT:    ret i1 false
 | |
| ;
 | |
|   %c1 = icmp uge i32 %x, %y
 | |
|   %max = select i1 %c1, i32 %x, i32 %y
 | |
|   %c2 = icmp uge i32 %x, %z
 | |
|   %min = select i1 %c2, i32 %z, i32 %x
 | |
|   %c = icmp ugt i32 %min, %max
 | |
|   ret i1 %c
 | |
| }
 | |
| 
 | |
| define i1 @maxmin7(i32 %x, i32 %y, i32 %z) {
 | |
| ; CHECK-LABEL: @maxmin7(
 | |
| ; CHECK-NEXT:    ret i1 true
 | |
| ;
 | |
|   %c1 = icmp uge i32 %x, %y
 | |
|   %max = select i1 %c1, i32 %x, i32 %y
 | |
|   %c2 = icmp uge i32 %x, %z
 | |
|   %min = select i1 %c2, i32 %z, i32 %x
 | |
|   %c = icmp ule i32 %min, %max
 | |
|   ret i1 %c
 | |
| }
 | |
| 
 | |
| define i1 @maxmin8(i32 %x, i32 %y, i32 %z) {
 | |
| ; CHECK-LABEL: @maxmin8(
 | |
| ; CHECK-NEXT:    ret i1 false
 | |
| ;
 | |
|   %c1 = icmp uge i32 %x, %y
 | |
|   %max = select i1 %c1, i32 %x, i32 %y
 | |
|   %c2 = icmp uge i32 %x, %z
 | |
|   %min = select i1 %c2, i32 %z, i32 %x
 | |
|   %c = icmp ult i32 %max, %min
 | |
|   ret i1 %c
 | |
| }
 | |
| 
 | |
| define i1 @eqcmp1(i32 %x, i32 %y) {
 | |
| ; CHECK-LABEL: @eqcmp1(
 | |
| ; CHECK-NEXT:    [[C:%.*]] = icmp sge i32 [[X:%.*]], [[Y:%.*]]
 | |
| ; CHECK-NEXT:    ret i1 [[C]]
 | |
| ;
 | |
|   %c = icmp sge i32 %x, %y
 | |
|   %max = select i1 %c, i32 %x, i32 %y
 | |
|   %r = icmp eq i32 %max, %x
 | |
|   ret i1 %r
 | |
| }
 | |
| 
 | |
| define i1 @eqcmp2(i32 %x, i32 %y) {
 | |
| ; CHECK-LABEL: @eqcmp2(
 | |
| ; CHECK-NEXT:    [[C:%.*]] = icmp sge i32 [[X:%.*]], [[Y:%.*]]
 | |
| ; CHECK-NEXT:    ret i1 [[C]]
 | |
| ;
 | |
|   %c = icmp sge i32 %x, %y
 | |
|   %max = select i1 %c, i32 %x, i32 %y
 | |
|   %r = icmp eq i32 %x, %max
 | |
|   ret i1 %r
 | |
| }
 | |
| 
 | |
| define i1 @eqcmp3(i32 %x, i32 %y) {
 | |
| ; CHECK-LABEL: @eqcmp3(
 | |
| ; CHECK-NEXT:    [[C:%.*]] = icmp uge i32 [[X:%.*]], [[Y:%.*]]
 | |
| ; CHECK-NEXT:    ret i1 [[C]]
 | |
| ;
 | |
|   %c = icmp uge i32 %x, %y
 | |
|   %max = select i1 %c, i32 %x, i32 %y
 | |
|   %r = icmp eq i32 %max, %x
 | |
|   ret i1 %r
 | |
| }
 | |
| 
 | |
| define i1 @eqcmp4(i32 %x, i32 %y) {
 | |
| ; CHECK-LABEL: @eqcmp4(
 | |
| ; CHECK-NEXT:    [[C:%.*]] = icmp uge i32 [[X:%.*]], [[Y:%.*]]
 | |
| ; CHECK-NEXT:    ret i1 [[C]]
 | |
| ;
 | |
|   %c = icmp uge i32 %x, %y
 | |
|   %max = select i1 %c, i32 %x, i32 %y
 | |
|   %r = icmp eq i32 %x, %max
 | |
|   ret i1 %r
 | |
| }
 |