brintos

brintos / llvm-project-archived public Read only

0
0
Text · 9.5 KiB · f873551 Raw
257 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=instcombine -S | FileCheck %s3 4target datalayout = "e-p:40:64:64:32-p1:16:16:16-p2:32:32:32-p3:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"5 6declare i32 @test58_d(i64 )7 8define i1 @test59(ptr %foo) {9; CHECK-LABEL: @test59(10; CHECK-NEXT:    [[GEP1:%.*]] = getelementptr inbounds nuw i8, ptr [[FOO:%.*]], i32 811; CHECK-NEXT:    [[TMP1:%.*]] = ptrtoint ptr [[GEP1]] to i4012; CHECK-NEXT:    [[USE:%.*]] = zext i40 [[TMP1]] to i6413; CHECK-NEXT:    [[CALL:%.*]] = call i32 @test58_d(i64 [[USE]])14; CHECK-NEXT:    ret i1 true15;16  %gep1 = getelementptr inbounds i32, ptr %foo, i64 217  %gep2 = getelementptr inbounds i8, ptr %foo, i64 1018  %cmp = icmp ult ptr %gep1, %gep219  %use = ptrtoint ptr %gep1 to i6420  %call = call i32 @test58_d(i64 %use)21  ret i1 %cmp22}23 24define i1 @test59_as1(ptr addrspace(1) %foo) {25; CHECK-LABEL: @test59_as1(26; CHECK-NEXT:    [[GEP1:%.*]] = getelementptr inbounds nuw i8, ptr addrspace(1) [[FOO:%.*]], i16 827; CHECK-NEXT:    [[TMP1:%.*]] = ptrtoint ptr addrspace(1) [[GEP1]] to i1628; CHECK-NEXT:    [[USE:%.*]] = zext i16 [[TMP1]] to i6429; CHECK-NEXT:    [[CALL:%.*]] = call i32 @test58_d(i64 [[USE]])30; CHECK-NEXT:    ret i1 true31;32  %gep1 = getelementptr inbounds i32, ptr addrspace(1) %foo, i64 233  %gep2 = getelementptr inbounds i8, ptr addrspace(1) %foo, i64 1034  %cmp = icmp ult ptr addrspace(1) %gep1, %gep235  %use = ptrtoint ptr addrspace(1) %gep1 to i6436  %call = call i32 @test58_d(i64 %use)37  ret i1 %cmp38}39 40define i1 @test60(ptr %foo, i64 %i, i64 %j) {41; CHECK-LABEL: @test60(42; CHECK-NEXT:    [[TMP1:%.*]] = trunc nsw i64 [[I:%.*]] to i3243; CHECK-NEXT:    [[GEP1_IDX:%.*]] = shl nsw i32 [[TMP1]], 244; CHECK-NEXT:    [[TMP2:%.*]] = trunc nsw i64 [[J:%.*]] to i3245; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[GEP1_IDX]], [[TMP2]]46; CHECK-NEXT:    ret i1 [[CMP]]47;48  %gep1 = getelementptr inbounds i32, ptr %foo, i64 %i49  %gep2 = getelementptr inbounds i8, ptr %foo, i64 %j50  %cmp = icmp ult ptr %gep1, %gep251  ret i1 %cmp52}53 54define i1 @test60_as1(ptr addrspace(1) %foo, i64 %i, i64 %j) {55; CHECK-LABEL: @test60_as1(56; CHECK-NEXT:    [[TMP1:%.*]] = trunc nsw i64 [[I:%.*]] to i1657; CHECK-NEXT:    [[GEP1_IDX:%.*]] = shl nsw i16 [[TMP1]], 258; CHECK-NEXT:    [[TMP2:%.*]] = trunc nsw i64 [[J:%.*]] to i1659; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i16 [[GEP1_IDX]], [[TMP2]]60; CHECK-NEXT:    ret i1 [[CMP]]61;62  %gep1 = getelementptr inbounds i32, ptr addrspace(1) %foo, i64 %i63  %gep2 = getelementptr inbounds i8, ptr addrspace(1) %foo, i64 %j64  %cmp = icmp ult ptr addrspace(1) %gep1, %gep265  ret i1 %cmp66}67 68; Same as test60, but look through an addrspacecast instead of a69; bitcast. This uses the same sized addrspace.70define i1 @test60_addrspacecast(ptr %foo, i64 %i, i64 %j) {71; CHECK-LABEL: @test60_addrspacecast(72; CHECK-NEXT:    [[TMP1:%.*]] = trunc nsw i64 [[J:%.*]] to i3273; CHECK-NEXT:    [[I_TR:%.*]] = trunc i64 [[I:%.*]] to i3274; CHECK-NEXT:    [[TMP2:%.*]] = shl i32 [[I_TR]], 275; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[TMP2]], [[TMP1]]76; CHECK-NEXT:    ret i1 [[CMP]]77;78  %bit = addrspacecast ptr %foo to ptr addrspace(3)79  %gep1 = getelementptr inbounds i32, ptr addrspace(3) %bit, i64 %i80  %gep2 = getelementptr inbounds i8, ptr %foo, i64 %j81  %cast1 = addrspacecast ptr addrspace(3) %gep1 to ptr82  %cmp = icmp ult ptr %cast1, %gep283  ret i1 %cmp84}85 86define i1 @test60_addrspacecast_smaller(ptr %foo, i16 %i, i64 %j) {87; CHECK-LABEL: @test60_addrspacecast_smaller(88; CHECK-NEXT:    [[GEP1_IDX:%.*]] = shl nsw i16 [[I:%.*]], 289; CHECK-NEXT:    [[TMP1:%.*]] = trunc i64 [[J:%.*]] to i1690; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i16 [[GEP1_IDX]], [[TMP1]]91; CHECK-NEXT:    ret i1 [[CMP]]92;93  %bit = addrspacecast ptr %foo to ptr addrspace(1)94  %gep1 = getelementptr inbounds i32, ptr addrspace(1) %bit, i16 %i95  %gep2 = getelementptr inbounds i8, ptr %foo, i64 %j96  %cast1 = addrspacecast ptr addrspace(1) %gep1 to ptr97  %cmp = icmp ult ptr %cast1, %gep298  ret i1 %cmp99}100 101define i1 @test60_addrspacecast_larger(ptr addrspace(1) %foo, i32 %i, i16 %j) {102; CHECK-LABEL: @test60_addrspacecast_larger(103; CHECK-NEXT:    [[I_TR:%.*]] = trunc i32 [[I:%.*]] to i16104; CHECK-NEXT:    [[TMP1:%.*]] = shl i16 [[I_TR]], 2105; CHECK-NEXT:    [[CMP:%.*]] = icmp sgt i16 [[J:%.*]], [[TMP1]]106; CHECK-NEXT:    ret i1 [[CMP]]107;108  %bit = addrspacecast ptr addrspace(1) %foo to ptr addrspace(2)109  %gep1 = getelementptr inbounds i32, ptr addrspace(2) %bit, i32 %i110  %gep2 = getelementptr inbounds i8, ptr addrspace(1) %foo, i16 %j111  %cast1 = addrspacecast ptr addrspace(2) %gep1 to ptr addrspace(1)112  %cmp = icmp ult ptr addrspace(1) %cast1, %gep2113  ret i1 %cmp114}115 116define i1 @test61(ptr %foo, i64 %i, i64 %j) {117; CHECK-LABEL: @test61(118; CHECK-NEXT:    [[TMP1:%.*]] = trunc i64 [[I:%.*]] to i32119; CHECK-NEXT:    [[GEP1:%.*]] = getelementptr i32, ptr [[FOO:%.*]], i32 [[TMP1]]120; CHECK-NEXT:    [[TMP2:%.*]] = trunc i64 [[J:%.*]] to i32121; CHECK-NEXT:    [[GEP2:%.*]] = getelementptr i8, ptr [[FOO]], i32 [[TMP2]]122; CHECK-NEXT:    [[CMP:%.*]] = icmp ult ptr [[GEP1]], [[GEP2]]123; CHECK-NEXT:    ret i1 [[CMP]]124;125  %gep1 = getelementptr i32, ptr %foo, i64 %i126  %gep2 = getelementptr  i8,  ptr %foo, i64 %j127  %cmp = icmp ult ptr %gep1, %gep2128  ret i1 %cmp129; Don't transform non-inbounds GEPs.130}131 132define i1 @test61_as1(ptr addrspace(1) %foo, i16 %i, i16 %j) {133; CHECK-LABEL: @test61_as1(134; CHECK-NEXT:    [[GEP1:%.*]] = getelementptr i32, ptr addrspace(1) [[FOO:%.*]], i16 [[I:%.*]]135; CHECK-NEXT:    [[GEP2:%.*]] = getelementptr i8, ptr addrspace(1) [[FOO]], i16 [[J:%.*]]136; CHECK-NEXT:    [[CMP:%.*]] = icmp ult ptr addrspace(1) [[GEP1]], [[GEP2]]137; CHECK-NEXT:    ret i1 [[CMP]]138;139  %gep1 = getelementptr i32, ptr addrspace(1) %foo, i16 %i140  %gep2 = getelementptr i8, ptr addrspace(1) %foo, i16 %j141  %cmp = icmp ult ptr addrspace(1) %gep1, %gep2142  ret i1 %cmp143; Don't transform non-inbounds GEPs.144}145 146; Negative test: GEP inbounds may cross sign boundary.147define i1 @test62(ptr %a) {148; CHECK-LABEL: @test62(149; CHECK-NEXT:    [[ARRAYIDX1:%.*]] = getelementptr inbounds nuw i8, ptr [[A:%.*]], i32 1150; CHECK-NEXT:    [[ARRAYIDX2:%.*]] = getelementptr inbounds nuw i8, ptr [[A]], i32 10151; CHECK-NEXT:    [[CMP:%.*]] = icmp slt ptr [[ARRAYIDX1]], [[ARRAYIDX2]]152; CHECK-NEXT:    ret i1 [[CMP]]153;154  %arrayidx1 = getelementptr inbounds i8, ptr %a, i64 1155  %arrayidx2 = getelementptr inbounds i8, ptr %a, i64 10156  %cmp = icmp slt ptr %arrayidx1, %arrayidx2157  ret i1 %cmp158}159 160define i1 @test62_as1(ptr addrspace(1) %a) {161; CHECK-LABEL: @test62_as1(162; CHECK-NEXT:    [[ARRAYIDX1:%.*]] = getelementptr inbounds nuw i8, ptr addrspace(1) [[A:%.*]], i16 1163; CHECK-NEXT:    [[ARRAYIDX2:%.*]] = getelementptr inbounds nuw i8, ptr addrspace(1) [[A]], i16 10164; CHECK-NEXT:    [[CMP:%.*]] = icmp slt ptr addrspace(1) [[ARRAYIDX1]], [[ARRAYIDX2]]165; CHECK-NEXT:    ret i1 [[CMP]]166;167  %arrayidx1 = getelementptr inbounds i8, ptr addrspace(1) %a, i64 1168  %arrayidx2 = getelementptr inbounds i8, ptr addrspace(1) %a, i64 10169  %cmp = icmp slt ptr addrspace(1) %arrayidx1, %arrayidx2170  ret i1 %cmp171}172 173 174; Variation of the above with an ashr175define i1 @icmp_and_ashr_multiuse(i32 %X) {176; CHECK-LABEL: @icmp_and_ashr_multiuse(177; CHECK-NEXT:    [[TMP1:%.*]] = and i32 [[X:%.*]], 240178; CHECK-NEXT:    [[TOBOOL:%.*]] = icmp ne i32 [[TMP1]], 224179; CHECK-NEXT:    [[TMP2:%.*]] = and i32 [[X]], 496180; CHECK-NEXT:    [[TOBOOL2:%.*]] = icmp ne i32 [[TMP2]], 432181; CHECK-NEXT:    [[AND3:%.*]] = and i1 [[TOBOOL]], [[TOBOOL2]]182; CHECK-NEXT:    ret i1 [[AND3]]183;184  %shr = ashr i32 %X, 4185  %and = and i32 %shr, 15186  %and2 = and i32 %shr, 31 ; second use of the shift187  %tobool = icmp ne i32 %and, 14188  %tobool2 = icmp ne i32 %and2, 27189  %and3 = and i1 %tobool, %tobool2190  ret i1 %and3191}192 193define i1 @icmp_and_ashr_multiuse_logical(i32 %X) {194; CHECK-LABEL: @icmp_and_ashr_multiuse_logical(195; CHECK-NEXT:    [[TMP1:%.*]] = and i32 [[X:%.*]], 240196; CHECK-NEXT:    [[TOBOOL:%.*]] = icmp ne i32 [[TMP1]], 224197; CHECK-NEXT:    [[TMP2:%.*]] = and i32 [[X]], 496198; CHECK-NEXT:    [[TOBOOL2:%.*]] = icmp ne i32 [[TMP2]], 432199; CHECK-NEXT:    [[AND3:%.*]] = and i1 [[TOBOOL]], [[TOBOOL2]]200; CHECK-NEXT:    ret i1 [[AND3]]201;202  %shr = ashr i32 %X, 4203  %and = and i32 %shr, 15204  %and2 = and i32 %shr, 31 ; second use of the shift205  %tobool = icmp ne i32 %and, 14206  %tobool2 = icmp ne i32 %and2, 27207  %and3 = select i1 %tobool, i1 %tobool2, i1 false208  ret i1 %and3209}210 211define i1 @icmp_lshr_and_overshift(i8 %X) {212; CHECK-LABEL: @icmp_lshr_and_overshift(213; CHECK-NEXT:    [[TOBOOL:%.*]] = icmp ugt i8 [[X:%.*]], 31214; CHECK-NEXT:    ret i1 [[TOBOOL]]215;216  %shr = lshr i8 %X, 5217  %and = and i8 %shr, 15218  %tobool = icmp ne i8 %and, 0219  ret i1 %tobool220}221 222; We shouldn't simplify this because the and uses bits that are shifted in.223define i1 @icmp_ashr_and_overshift(i8 %X) {224; CHECK-LABEL: @icmp_ashr_and_overshift(225; CHECK-NEXT:    [[SHR:%.*]] = ashr i8 [[X:%.*]], 5226; CHECK-NEXT:    [[AND:%.*]] = and i8 [[SHR]], 15227; CHECK-NEXT:    [[TOBOOL:%.*]] = icmp ne i8 [[AND]], 0228; CHECK-NEXT:    ret i1 [[TOBOOL]]229;230  %shr = ashr i8 %X, 5231  %and = and i8 %shr, 15232  %tobool = icmp ne i8 %and, 0233  ret i1 %tobool234}235 236; PR16244237define i1 @test71(ptr %x) {238; CHECK-LABEL: @test71(239; CHECK-NEXT:    ret i1 false240;241  %a = getelementptr i8, ptr %x, i64 8242  %b = getelementptr inbounds i8, ptr %x, i64 8243  %c = icmp ugt ptr %a, %b244  ret i1 %c245}246 247define i1 @test71_as1(ptr addrspace(1) %x) {248; CHECK-LABEL: @test71_as1(249; CHECK-NEXT:    ret i1 false250;251  %a = getelementptr i8, ptr addrspace(1) %x, i64 8252  %b = getelementptr inbounds i8, ptr addrspace(1) %x, i64 8253  %c = icmp ugt ptr addrspace(1) %a, %b254  ret i1 %c255}256 257