1db7a2f34SJuneyoung Lee; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2*acdc419cSBjorn Pettersson; RUN: opt < %s -passes=instcombine -S | FileCheck %s 3db7a2f34SJuneyoung Lee 4db7a2f34SJuneyoung Lee; Tests to verify proper functioning of the icmp folding implemented in 5db7a2f34SJuneyoung Lee; InstCombiner::foldICmpBitCastConstant 6db7a2f34SJuneyoung Lee; Specifically, folding: 7db7a2f34SJuneyoung Lee; icmp <pred> iN X, C 8db7a2f34SJuneyoung Lee; where X = bitcast <M x iK> (shufflevector <M x iK> %vec, undef, SC)) to iN 9db7a2f34SJuneyoung Lee; and C is a splat of a K-bit pattern 10db7a2f34SJuneyoung Lee; and SC is a constant vector = <C', C', C', ..., C'> 11db7a2f34SJuneyoung Lee; Into: 12db7a2f34SJuneyoung Lee; %E = extractelement <M x iK> %vec, i32 C' 13db7a2f34SJuneyoung Lee; icmp <pred> iK %E, trunc(C) 14db7a2f34SJuneyoung Lee 15db7a2f34SJuneyoung Leedefine i1 @test_i1_0(i1 %val) { 16db7a2f34SJuneyoung Lee; CHECK-LABEL: @test_i1_0( 17db7a2f34SJuneyoung Lee; CHECK-NEXT: [[COND:%.*]] = xor i1 [[VAL:%.*]], true 18db7a2f34SJuneyoung Lee; CHECK-NEXT: ret i1 [[COND]] 19db7a2f34SJuneyoung Lee; 20db7a2f34SJuneyoung Lee %insvec = insertelement <4 x i1> poison, i1 %val, i32 0 21ae6e8932SJuneyoung Lee %vec = shufflevector <4 x i1> %insvec, <4 x i1> poison, <4 x i32> zeroinitializer 22db7a2f34SJuneyoung Lee %cast = bitcast <4 x i1> %vec to i4 23db7a2f34SJuneyoung Lee %cond = icmp eq i4 %cast, 0 24db7a2f34SJuneyoung Lee ret i1 %cond 25db7a2f34SJuneyoung Lee} 26db7a2f34SJuneyoung Lee 27db7a2f34SJuneyoung Leedefine i1 @test_i1_0_2(i1 %val) { 28db7a2f34SJuneyoung Lee; CHECK-LABEL: @test_i1_0_2( 29db7a2f34SJuneyoung Lee; CHECK-NEXT: [[COND:%.*]] = xor i1 [[VAL:%.*]], true 30db7a2f34SJuneyoung Lee; CHECK-NEXT: ret i1 [[COND]] 31db7a2f34SJuneyoung Lee; 32db7a2f34SJuneyoung Lee %insvec = insertelement <4 x i1> poison, i1 %val, i32 2 33ae6e8932SJuneyoung Lee %vec = shufflevector <4 x i1> %insvec, <4 x i1> poison, <4 x i32> <i32 2, i32 2, i32 2, i32 2> 34db7a2f34SJuneyoung Lee %cast = bitcast <4 x i1> %vec to i4 35db7a2f34SJuneyoung Lee %cond = icmp eq i4 %cast, 0 36db7a2f34SJuneyoung Lee ret i1 %cond 37db7a2f34SJuneyoung Lee} 38db7a2f34SJuneyoung Lee 39db7a2f34SJuneyoung Leedefine i1 @test_i1_m1(i1 %val) { 40db7a2f34SJuneyoung Lee; CHECK-LABEL: @test_i1_m1( 41db7a2f34SJuneyoung Lee; CHECK-NEXT: ret i1 [[VAL:%.*]] 42db7a2f34SJuneyoung Lee; 43db7a2f34SJuneyoung Lee %insvec = insertelement <4 x i1> poison, i1 %val, i32 0 44ae6e8932SJuneyoung Lee %vec = shufflevector <4 x i1> %insvec, <4 x i1> poison, <4 x i32> zeroinitializer 45db7a2f34SJuneyoung Lee %cast = bitcast <4 x i1> %vec to i4 46db7a2f34SJuneyoung Lee %cond = icmp eq i4 %cast, -1 47db7a2f34SJuneyoung Lee ret i1 %cond 48db7a2f34SJuneyoung Lee} 49db7a2f34SJuneyoung Lee 50db7a2f34SJuneyoung Leedefine i1 @test_i8_pattern(i8 %val) { 51db7a2f34SJuneyoung Lee; CHECK-LABEL: @test_i8_pattern( 52db7a2f34SJuneyoung Lee; CHECK-NEXT: [[COND:%.*]] = icmp eq i8 [[VAL:%.*]], 72 53db7a2f34SJuneyoung Lee; CHECK-NEXT: ret i1 [[COND]] 54db7a2f34SJuneyoung Lee; 55db7a2f34SJuneyoung Lee %insvec = insertelement <4 x i8> poison, i8 %val, i32 0 56ae6e8932SJuneyoung Lee %vec = shufflevector <4 x i8> %insvec, <4 x i8> poison, <4 x i32> zeroinitializer 57db7a2f34SJuneyoung Lee %cast = bitcast <4 x i8> %vec to i32 58db7a2f34SJuneyoung Lee %cond = icmp eq i32 %cast, 1212696648 59db7a2f34SJuneyoung Lee ret i1 %cond 60db7a2f34SJuneyoung Lee} 61db7a2f34SJuneyoung Lee 62db7a2f34SJuneyoung Leedefine i1 @test_i8_pattern_2(i8 %val) { 63db7a2f34SJuneyoung Lee; CHECK-LABEL: @test_i8_pattern_2( 64db7a2f34SJuneyoung Lee; CHECK-NEXT: [[COND:%.*]] = icmp eq i8 [[VAL:%.*]], 72 65db7a2f34SJuneyoung Lee; CHECK-NEXT: ret i1 [[COND]] 66db7a2f34SJuneyoung Lee; 67db7a2f34SJuneyoung Lee %insvec = insertelement <4 x i8> poison, i8 %val, i32 2 68ae6e8932SJuneyoung Lee %vec = shufflevector <4 x i8> %insvec, <4 x i8> poison, <4 x i32> <i32 2, i32 2, i32 2, i32 2> 69db7a2f34SJuneyoung Lee %cast = bitcast <4 x i8> %vec to i32 70db7a2f34SJuneyoung Lee %cond = icmp eq i32 %cast, 1212696648 71db7a2f34SJuneyoung Lee ret i1 %cond 72db7a2f34SJuneyoung Lee} 73db7a2f34SJuneyoung Lee 74db7a2f34SJuneyoung Lee; Make sure we don't try to fold if the shufflemask has differing element values 75db7a2f34SJuneyoung Leedefine i1 @test_i8_pattern_3(<4 x i8> %invec) { 76db7a2f34SJuneyoung Lee; CHECK-LABEL: @test_i8_pattern_3( 77ae6e8932SJuneyoung Lee; CHECK-NEXT: [[VEC:%.*]] = shufflevector <4 x i8> [[INVEC:%.*]], <4 x i8> poison, <4 x i32> <i32 1, i32 0, i32 3, i32 2> 78db7a2f34SJuneyoung Lee; CHECK-NEXT: [[CAST:%.*]] = bitcast <4 x i8> [[VEC]] to i32 79db7a2f34SJuneyoung Lee; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[CAST]], 1212696648 80db7a2f34SJuneyoung Lee; CHECK-NEXT: ret i1 [[COND]] 81db7a2f34SJuneyoung Lee; 82ae6e8932SJuneyoung Lee %vec = shufflevector <4 x i8> %invec, <4 x i8> poison, <4 x i32> <i32 1, i32 0, i32 3, i32 2> 83db7a2f34SJuneyoung Lee %cast = bitcast <4 x i8> %vec to i32 84db7a2f34SJuneyoung Lee %cond = icmp eq i32 %cast, 1212696648 85db7a2f34SJuneyoung Lee ret i1 %cond 86db7a2f34SJuneyoung Lee} 87db7a2f34SJuneyoung Lee 88db7a2f34SJuneyoung Lee; Make sure we don't try to fold if the compared-to constant isn't a splatted value 89db7a2f34SJuneyoung Leedefine i1 @test_i8_nopattern(i8 %val) { 90db7a2f34SJuneyoung Lee; CHECK-LABEL: @test_i8_nopattern( 91e6ad9ef4SPhilip Reames; CHECK-NEXT: [[INSVEC:%.*]] = insertelement <4 x i8> poison, i8 [[VAL:%.*]], i64 0 92ae6e8932SJuneyoung Lee; CHECK-NEXT: [[VEC:%.*]] = shufflevector <4 x i8> [[INSVEC]], <4 x i8> poison, <4 x i32> zeroinitializer 93db7a2f34SJuneyoung Lee; CHECK-NEXT: [[CAST:%.*]] = bitcast <4 x i8> [[VEC]] to i32 94db7a2f34SJuneyoung Lee; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[CAST]], 1212696647 95db7a2f34SJuneyoung Lee; CHECK-NEXT: ret i1 [[COND]] 96db7a2f34SJuneyoung Lee; 97db7a2f34SJuneyoung Lee %insvec = insertelement <4 x i8> poison, i8 %val, i32 0 98ae6e8932SJuneyoung Lee %vec = shufflevector <4 x i8> %insvec, <4 x i8> poison, <4 x i32> zeroinitializer 99db7a2f34SJuneyoung Lee %cast = bitcast <4 x i8> %vec to i32 100db7a2f34SJuneyoung Lee %cond = icmp eq i32 %cast, 1212696647 101db7a2f34SJuneyoung Lee ret i1 %cond 102db7a2f34SJuneyoung Lee} 103db7a2f34SJuneyoung Lee 104db7a2f34SJuneyoung Lee; Verify that we fold more than just the eq predicate 105db7a2f34SJuneyoung Leedefine i1 @test_i8_ult_pattern(i8 %val) { 106db7a2f34SJuneyoung Lee; CHECK-LABEL: @test_i8_ult_pattern( 107db7a2f34SJuneyoung Lee; CHECK-NEXT: [[COND:%.*]] = icmp ult i8 [[VAL:%.*]], 72 108db7a2f34SJuneyoung Lee; CHECK-NEXT: ret i1 [[COND]] 109db7a2f34SJuneyoung Lee; 110db7a2f34SJuneyoung Lee %insvec = insertelement <4 x i8> poison, i8 %val, i32 0 111ae6e8932SJuneyoung Lee %vec = shufflevector <4 x i8> %insvec, <4 x i8> poison, <4 x i32> zeroinitializer 112db7a2f34SJuneyoung Lee %cast = bitcast <4 x i8> %vec to i32 113db7a2f34SJuneyoung Lee %cond = icmp ult i32 %cast, 1212696648 114db7a2f34SJuneyoung Lee ret i1 %cond 115db7a2f34SJuneyoung Lee} 116db7a2f34SJuneyoung Lee 117db7a2f34SJuneyoung Leedefine i1 @extending_shuffle_with_weird_types(<2 x i9> %v) { 118db7a2f34SJuneyoung Lee; CHECK-LABEL: @extending_shuffle_with_weird_types( 119e6ad9ef4SPhilip Reames; CHECK-NEXT: [[TMP1:%.*]] = extractelement <2 x i9> [[V:%.*]], i64 0 120db7a2f34SJuneyoung Lee; CHECK-NEXT: [[CMP:%.*]] = icmp slt i9 [[TMP1]], 1 121db7a2f34SJuneyoung Lee; CHECK-NEXT: ret i1 [[CMP]] 122db7a2f34SJuneyoung Lee; 123ae6e8932SJuneyoung Lee %splat = shufflevector <2 x i9> %v, <2 x i9> poison, <3 x i32> zeroinitializer 124db7a2f34SJuneyoung Lee %cast = bitcast <3 x i9> %splat to i27 125db7a2f34SJuneyoung Lee %cmp = icmp slt i27 %cast, 262657 ; 0x040201 126db7a2f34SJuneyoung Lee ret i1 %cmp 127db7a2f34SJuneyoung Lee} 128