322 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature2; RUN: opt < %s -passes=ipsccp -S | FileCheck %s3 4; Constant range for %a is [1, 48) and for %b is [301, 1000)5define internal i32 @f1(i32 %a, i32 %b) {6; CHECK-LABEL: define {{[^@]+}}@f17; CHECK-SAME: (i32 range(i32 1, 48) [[A:%.*]], i32 range(i32 301, 1000) [[B:%.*]]) {8; CHECK-NEXT: entry:9; CHECK-NEXT: ret i32 poison10;11entry:12 %cmp.a = icmp sgt i32 %a, 30013 %cmp.b = icmp sgt i32 %b, 30014 %cmp.a2 = icmp ugt i32 %a, 30015 %cmp.b2 = icmp ugt i32 %b, 30016 17 %a.1 = select i1 %cmp.a, i32 1, i32 218 %b.1 = select i1 %cmp.b, i32 1, i32 219 %a.2 = select i1 %cmp.a2, i32 1, i32 220 %b.2 = select i1 %cmp.b2, i32 1, i32 221 %res1 = add i32 %a.1, %b.122 %res2 = add i32 %a.2, %b.223 %res3 = add i32 %res1, %res224 ret i32 %res325}26 27; Constant range for %x is [47, 302)28define internal i32 @f2(i32 %x) {29; CHECK-LABEL: define {{[^@]+}}@f230; CHECK-SAME: (i32 range(i32 47, 302) [[X:%.*]]) {31; CHECK-NEXT: entry:32; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X]], 30033; CHECK-NEXT: [[CMP4:%.*]] = icmp ugt i32 [[X]], 30034; CHECK-NEXT: [[RES1:%.*]] = select i1 [[CMP]], i32 1, i32 235; CHECK-NEXT: [[RES4:%.*]] = select i1 [[CMP4]], i32 3, i32 436; CHECK-NEXT: [[RES6:%.*]] = add nuw nsw i32 [[RES1]], 337; CHECK-NEXT: [[RES7:%.*]] = add nuw nsw i32 5, [[RES4]]38; CHECK-NEXT: [[RES:%.*]] = add nuw nsw i32 [[RES6]], 539; CHECK-NEXT: ret i32 [[RES]]40;41entry:42 %cmp = icmp sgt i32 %x, 30043 %cmp2 = icmp ne i32 %x, 1044 %cmp3 = icmp sge i32 %x, 4745 %cmp4 = icmp ugt i32 %x, 30046 %cmp5 = icmp uge i32 %x, 4747 %res1 = select i1 %cmp, i32 1, i32 248 %res2 = select i1 %cmp2, i32 3, i32 449 %res3 = select i1 %cmp3, i32 5, i32 650 %res4 = select i1 %cmp4, i32 3, i32 451 %res5 = select i1 %cmp5, i32 5, i32 652 53 %res6 = add i32 %res1, %res254 %res7 = add i32 %res3, %res455 %res = add i32 %res6, %res556 ret i32 %res57}58 59define i32 @caller1() {60; CHECK-LABEL: define {{[^@]+}}@caller1() {61; CHECK-NEXT: entry:62; CHECK-NEXT: [[CALL1:%.*]] = tail call i32 @f1(i32 1, i32 301)63; CHECK-NEXT: [[CALL2:%.*]] = tail call i32 @f1(i32 47, i32 999)64; CHECK-NEXT: [[CALL3:%.*]] = tail call i32 @f2(i32 47)65; CHECK-NEXT: [[CALL4:%.*]] = tail call i32 @f2(i32 301)66; CHECK-NEXT: [[RES_1:%.*]] = add nuw nsw i32 12, [[CALL3]]67; CHECK-NEXT: [[RES_2:%.*]] = add nuw nsw i32 [[RES_1]], [[CALL4]]68; CHECK-NEXT: ret i32 [[RES_2]]69;70entry:71 %call1 = tail call i32 @f1(i32 1, i32 301)72 %call2 = tail call i32 @f1(i32 47, i32 999)73 %call3 = tail call i32 @f2(i32 47)74 %call4 = tail call i32 @f2(i32 301)75 %res.1 = add nsw i32 12, %call376 %res.2 = add nsw i32 %res.1, %call477 ret i32 %res.278}79 80define internal i32 @f3(i32 %x) {81; CHECK-LABEL: define {{[^@]+}}@f382; CHECK-SAME: (i32 range(i32 0, 2) [[X:%.*]]) {83; CHECK-NEXT: entry:84; CHECK-NEXT: ret i32 poison85;86entry:87 %cmp = icmp sgt i32 %x, 30088 %res = select i1 %cmp, i32 1, i32 289 ret i32 %res90}91 92; The phi node could be converted in a ConstantRange.93define i32 @caller2(i1 %cmp) {94; CHECK-LABEL: define {{[^@]+}}@caller295; CHECK-SAME: (i1 [[CMP:%.*]]) {96; CHECK-NEXT: entry:97; CHECK-NEXT: br i1 [[CMP]], label [[IF_TRUE:%.*]], label [[END:%.*]]98; CHECK: if.true:99; CHECK-NEXT: br label [[END]]100; CHECK: end:101; CHECK-NEXT: [[RES:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ 1, [[IF_TRUE]] ]102; CHECK-NEXT: [[CALL1:%.*]] = tail call i32 @f3(i32 [[RES]])103; CHECK-NEXT: ret i32 2104;105entry:106 br i1 %cmp, label %if.true, label %end107 108if.true:109 br label %end110 111end:112 %res = phi i32 [ 0, %entry], [ 1, %if.true ]113 %call1 = tail call i32 @f3(i32 %res)114 ret i32 2115}116 117define internal i32 @f4(i32 %x) {118; CHECK-LABEL: define {{[^@]+}}@f4119; CHECK-SAME: (i32 range(i32 301, -2147483648) [[X:%.*]]) {120; CHECK-NEXT: entry:121; CHECK-NEXT: ret i32 poison122;123entry:124 %cmp = icmp sgt i32 %x, 300125 %res = select i1 %cmp, i32 1, i32 2126 ret i32 %res127}128 129; ICmp introduces bounds on ConstantRanges.130define i32 @caller3(i32 %x) {131; CHECK-LABEL: define {{[^@]+}}@caller3132; CHECK-SAME: (i32 [[X:%.*]]) {133; CHECK-NEXT: entry:134; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X]], 300135; CHECK-NEXT: br i1 [[CMP]], label [[IF_TRUE:%.*]], label [[END:%.*]]136; CHECK: if.true:137; CHECK-NEXT: [[X_1:%.*]] = tail call i32 @f4(i32 [[X]])138; CHECK-NEXT: br label [[END]]139; CHECK: end:140; CHECK-NEXT: [[RES:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ 1, [[IF_TRUE]] ]141; CHECK-NEXT: ret i32 [[RES]]142;143entry:144 %cmp = icmp sgt i32 %x, 300145 br i1 %cmp, label %if.true, label %end146 147if.true:148 %x.1 = tail call i32 @f4(i32 %x)149 br label %end150 151end:152 %res = phi i32 [ 0, %entry], [ %x.1, %if.true ]153 ret i32 %res154}155 156; Check to make sure we do not attempt to access lattice values in unreachable157; blocks.158define i32 @test_unreachable() {159; CHECK-LABEL: define {{[^@]+}}@test_unreachable() {160; CHECK-NEXT: entry:161; CHECK-NEXT: [[TMP0:%.*]] = call i1 @test_unreachable_callee(i32 1)162; CHECK-NEXT: [[TMP1:%.*]] = call i1 @test_unreachable_callee(i32 2)163; CHECK-NEXT: ret i32 1164;165entry:166 call i1 @test_unreachable_callee(i32 1)167 call i1 @test_unreachable_callee(i32 2)168 ret i32 1169}170 171define internal i1 @test_unreachable_callee(i32 %a) {172; CHECK-LABEL: define {{[^@]+}}@test_unreachable_callee173; CHECK-SAME: (i32 range(i32 1, 3) [[A:%.*]]) {174; CHECK-NEXT: entry:175; CHECK-NEXT: ret i1 poison176;177entry:178 ret i1 true179 180unreachablebb:181 %cmp = icmp eq i32 undef, %a182 unreachable183}184 185; Check that we do not attempt to get range info for non-integer types and186; crash.187define double @test_struct({ double, double } %test) {188; CHECK-LABEL: define {{[^@]+}}@test_struct189; CHECK-SAME: ({ double, double } [[TEST:%.*]]) {190; CHECK-NEXT: [[V:%.*]] = extractvalue { double, double } [[TEST]], 0191; CHECK-NEXT: [[R:%.*]] = fmul double [[V]], [[V]]192; CHECK-NEXT: ret double [[R]]193;194 %v = extractvalue { double, double } %test, 0195 %r = fmul double %v, %v196 ret double %r197}198 199; Constant range for %x is [47, 302)200define internal i32 @f5(i32 %x) {201; CHECK-LABEL: define {{[^@]+}}@f5202; CHECK-SAME: (i32 range(i32 47, 302) [[X:%.*]]) {203; CHECK-NEXT: entry:204; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X]], undef205; CHECK-NEXT: [[CMP2:%.*]] = icmp ne i32 undef, [[X]]206; CHECK-NEXT: [[RES1:%.*]] = select i1 [[CMP]], i32 1, i32 2207; CHECK-NEXT: [[RES2:%.*]] = select i1 [[CMP2]], i32 3, i32 4208; CHECK-NEXT: [[RES:%.*]] = add i32 [[RES1]], [[RES2]]209; CHECK-NEXT: ret i32 [[RES]]210;211entry:212 %cmp = icmp sgt i32 %x, undef213 %cmp2 = icmp ne i32 undef, %x214 %res1 = select i1 %cmp, i32 1, i32 2215 %res2 = select i1 %cmp2, i32 3, i32 4216 217 %res = add i32 %res1, %res2218 ret i32 %res219}220 221define i32 @caller4() {222; CHECK-LABEL: define {{[^@]+}}@caller4() {223; CHECK-NEXT: entry:224; CHECK-NEXT: [[CALL1:%.*]] = tail call i32 @f5(i32 47)225; CHECK-NEXT: [[CALL2:%.*]] = tail call i32 @f5(i32 301)226; CHECK-NEXT: [[RES:%.*]] = add nsw i32 [[CALL1]], [[CALL2]]227; CHECK-NEXT: ret i32 [[RES]]228;229entry:230 %call1 = tail call i32 @f5(i32 47)231 %call2 = tail call i32 @f5(i32 301)232 %res = add nsw i32 %call1, %call2233 ret i32 %res234}235 236; Make sure we do re-evaluate the function after ParamState changes.237define internal i32 @recursive_f(i32 %i) {238; CHECK-LABEL: define {{[^@]+}}@recursive_f239; CHECK-SAME: (i32 [[I:%.*]]) {240; CHECK-NEXT: entry:241; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[I]], 0242; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]243; CHECK: if.then:244; CHECK-NEXT: br label [[RETURN:%.*]]245; CHECK: if.else:246; CHECK-NEXT: [[SUB:%.*]] = sub nuw nsw i32 [[I]], 1247; CHECK-NEXT: [[CALL:%.*]] = call i32 @recursive_f(i32 [[SUB]])248; CHECK-NEXT: [[ADD:%.*]] = add i32 [[I]], [[CALL]]249; CHECK-NEXT: br label [[RETURN]]250; CHECK: return:251; CHECK-NEXT: [[RETVAL_0:%.*]] = phi i32 [ 0, [[IF_THEN]] ], [ [[ADD]], [[IF_ELSE]] ]252; CHECK-NEXT: ret i32 [[RETVAL_0]]253;254entry:255 %cmp = icmp eq i32 %i, 0256 br i1 %cmp, label %if.then, label %if.else257 258if.then: ; preds = %entry259 br label %return260 261if.else: ; preds = %entry262 %sub = sub nsw i32 %i, 1263 %call = call i32 @recursive_f(i32 %sub)264 %add = add i32 %i, %call265 br label %return266 267return: ; preds = %if.else, %if.then268 %retval.0 = phi i32 [ 0, %if.then ], [ %add, %if.else ]269 ret i32 %retval.0270}271 272define i32 @caller5() {273; CHECK-LABEL: define {{[^@]+}}@caller5() {274; CHECK-NEXT: entry:275; CHECK-NEXT: [[CALL:%.*]] = call i32 @recursive_f(i32 42)276; CHECK-NEXT: ret i32 [[CALL]]277;278entry:279 %call = call i32 @recursive_f(i32 42)280 ret i32 %call281}282 283define internal i32 @callee6.1(i32 %i) {284; CHECK-LABEL: define {{[^@]+}}@callee6.1285; CHECK-SAME: (i32 range(i32 30, 44) [[I:%.*]]) {286; CHECK-NEXT: [[RES:%.*]] = call i32 @callee6.2(i32 [[I]])287; CHECK-NEXT: ret i32 poison288;289 %res = call i32 @callee6.2(i32 %i)290 ret i32 %res291}292 293define internal i32 @callee6.2(i32 %i) {294; CHECK-LABEL: define {{[^@]+}}@callee6.2295; CHECK-SAME: (i32 range(i32 30, 44) [[I:%.*]]) {296; CHECK-NEXT: br label [[IF_THEN:%.*]]297; CHECK: if.then:298; CHECK-NEXT: ret i32 poison299;300 301 %cmp = icmp ne i32 %i, 0302 br i1 %cmp, label %if.then, label %if.else303 304if.then: ; preds = %entry305 ret i32 1306 307if.else: ; preds = %entry308 ret i32 2309}310 311define i32 @caller6() {312; CHECK-LABEL: define {{[^@]+}}@caller6() {313; CHECK-NEXT: [[CALL_1:%.*]] = call i32 @callee6.1(i32 30)314; CHECK-NEXT: [[CALL_2:%.*]] = call i32 @callee6.1(i32 43)315; CHECK-NEXT: ret i32 2316;317 %call.1 = call i32 @callee6.1(i32 30)318 %call.2 = call i32 @callee6.1(i32 43)319 %res = add i32 %call.1, %call.2320 ret i32 %res321}322