@@ -2363,3 +2363,107 @@ _Z3fooPKc.exit20:
2363
2363
%and9 = and i1 %tobool , %retval.0.i19
2364
2364
ret i1 %and9
2365
2365
}
2366
+
2367
+ define i1 @fold_or_phi_into_or_icmp (ptr noundef readnone %dv1 , ptr noundef %val1 , ptr noundef readnone %dv2 , ptr noundef %val2 ) {
2368
+ ; CHECK-LABEL: @fold_or_phi_into_or_icmp(
2369
+ ; CHECK-NEXT: entry:
2370
+ ; CHECK-NEXT: [[CMP_I:%.*]] = icmp eq ptr [[VAL1:%.*]], null
2371
+ ; CHECK-NEXT: br i1 [[CMP_I]], label [[_Z3FOOPKC_EXIT:%.*]], label [[WHILE_COND_I:%.*]]
2372
+ ; CHECK: while.cond.i:
2373
+ ; CHECK-NEXT: [[TEST_0_I:%.*]] = phi ptr [ [[INCDEC_PTR_I:%.*]], [[WHILE_COND_I]] ], [ [[VAL1]], [[ENTRY:%.*]] ]
2374
+ ; CHECK-NEXT: [[TMP0:%.*]] = load i8, ptr [[TEST_0_I]], align 1
2375
+ ; CHECK-NEXT: [[CMP1_NOT_I:%.*]] = icmp eq i8 [[TMP0]], 0
2376
+ ; CHECK-NEXT: [[INCDEC_PTR_I]] = getelementptr inbounds i8, ptr [[TEST_0_I]], i64 1
2377
+ ; CHECK-NEXT: br i1 [[CMP1_NOT_I]], label [[WHILE_END_I:%.*]], label [[WHILE_COND_I]]
2378
+ ; CHECK: while.end.i:
2379
+ ; CHECK-NEXT: [[SUB_PTR_LHS_CAST_I:%.*]] = ptrtoint ptr [[TEST_0_I]] to i64
2380
+ ; CHECK-NEXT: [[SUB_PTR_RHS_CAST_I:%.*]] = ptrtoint ptr [[VAL1]] to i64
2381
+ ; CHECK-NEXT: [[SUB_PTR_SUB_I:%.*]] = sub i64 [[SUB_PTR_LHS_CAST_I]], [[SUB_PTR_RHS_CAST_I]]
2382
+ ; CHECK-NEXT: br label [[_Z3FOOPKC_EXIT]]
2383
+ ; CHECK: _Z3fooPKc.exit:
2384
+ ; CHECK-NEXT: [[RETVAL_0_I:%.*]] = phi i64 [ [[SUB_PTR_SUB_I]], [[WHILE_END_I]] ], [ 0, [[ENTRY]] ]
2385
+ ; CHECK-NEXT: [[CMP_I10:%.*]] = icmp eq ptr [[VAL2:%.*]], null
2386
+ ; CHECK-NEXT: br i1 [[CMP_I10]], label [[_Z3FOOPKC_EXIT19:%.*]], label [[WHILE_COND_I11:%.*]]
2387
+ ; CHECK: while.cond.i11:
2388
+ ; CHECK-NEXT: [[TEST_0_I12:%.*]] = phi ptr [ [[INCDEC_PTR_I14:%.*]], [[WHILE_COND_I11]] ], [ [[VAL2]], [[_Z3FOOPKC_EXIT]] ]
2389
+ ; CHECK-NEXT: [[TMP1:%.*]] = load i8, ptr [[TEST_0_I12]], align 1
2390
+ ; CHECK-NEXT: [[CMP1_NOT_I13:%.*]] = icmp eq i8 [[TMP1]], 0
2391
+ ; CHECK-NEXT: [[INCDEC_PTR_I14]] = getelementptr inbounds i8, ptr [[TEST_0_I12]], i64 1
2392
+ ; CHECK-NEXT: br i1 [[CMP1_NOT_I13]], label [[WHILE_END_I15:%.*]], label [[WHILE_COND_I11]]
2393
+ ; CHECK: while.end.i15:
2394
+ ; CHECK-NEXT: [[SUB_PTR_LHS_CAST_I16:%.*]] = ptrtoint ptr [[TEST_0_I12]] to i64
2395
+ ; CHECK-NEXT: [[SUB_PTR_RHS_CAST_I17:%.*]] = ptrtoint ptr [[VAL2]] to i64
2396
+ ; CHECK-NEXT: [[SUB_PTR_SUB_I18:%.*]] = sub i64 [[SUB_PTR_LHS_CAST_I16]], [[SUB_PTR_RHS_CAST_I17]]
2397
+ ; CHECK-NEXT: br label [[_Z3FOOPKC_EXIT19]]
2398
+ ; CHECK: _Z3fooPKc.exit19:
2399
+ ; CHECK-NEXT: [[RETVAL_0_I20:%.*]] = phi i64 [ [[SUB_PTR_SUB_I18]], [[WHILE_END_I15]] ], [ 0, [[_Z3FOOPKC_EXIT]] ]
2400
+ ; CHECK-NEXT: [[TMP2:%.*]] = or i64 [[RETVAL_0_I]], [[RETVAL_0_I20]]
2401
+ ; CHECK-NEXT: [[OR_COND_NOT:%.*]] = icmp eq i64 [[TMP2]], 0
2402
+ ; CHECK-NEXT: br i1 [[OR_COND_NOT]], label [[IF_THEN:%.*]], label [[IF_END4:%.*]]
2403
+ ; CHECK: if.then:
2404
+ ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[DV1:%.*]], [[DV2:%.*]]
2405
+ ; CHECK-NEXT: br label [[CLEANUP:%.*]]
2406
+ ; CHECK: if.end4:
2407
+ ; CHECK-NEXT: [[TOBOOL2:%.*]] = icmp ne i64 [[RETVAL_0_I20]], 0
2408
+ ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp ne i64 [[RETVAL_0_I]], 0
2409
+ ; CHECK-NEXT: [[OR_COND10:%.*]] = and i1 [[TOBOOL]], [[TOBOOL2]]
2410
+ ; CHECK-NEXT: br label [[CLEANUP]]
2411
+ ; CHECK: cleanup:
2412
+ ; CHECK-NEXT: [[RETVAL_0:%.*]] = phi i1 [ [[CMP]], [[IF_THEN]] ], [ [[OR_COND10]], [[IF_END4]] ]
2413
+ ; CHECK-NEXT: ret i1 [[RETVAL_0]]
2414
+ ;
2415
+ entry:
2416
+ %cmp.i = icmp eq ptr %val1 , null
2417
+ br i1 %cmp.i , label %_Z3fooPKc.exit , label %while.cond.i
2418
+
2419
+ while.cond.i:
2420
+ %test.0.i = phi ptr [ %incdec.ptr.i , %while.cond.i ], [ %val1 , %entry ]
2421
+ %0 = load i8 , ptr %test.0.i , align 1
2422
+ %cmp1.not.i = icmp eq i8 %0 , 0
2423
+ %incdec.ptr.i = getelementptr inbounds i8 , ptr %test.0.i , i64 1
2424
+ br i1 %cmp1.not.i , label %while.end.i , label %while.cond.i
2425
+
2426
+ while.end.i:
2427
+ %sub.ptr.lhs.cast.i = ptrtoint ptr %test.0.i to i64
2428
+ %sub.ptr.rhs.cast.i = ptrtoint ptr %val1 to i64
2429
+ %sub.ptr.sub.i = sub i64 %sub.ptr.lhs.cast.i , %sub.ptr.rhs.cast.i
2430
+ br label %_Z3fooPKc.exit
2431
+
2432
+ _Z3fooPKc.exit:
2433
+ %retval.0.i = phi i64 [ %sub.ptr.sub.i , %while.end.i ], [ 0 , %entry ]
2434
+ %cmp.i10 = icmp eq ptr %val2 , null
2435
+ br i1 %cmp.i10 , label %_Z3fooPKc.exit19 , label %while.cond.i11
2436
+
2437
+ while.cond.i11 :
2438
+ %test.0.i12 = phi ptr [ %incdec.ptr.i14 , %while.cond.i11 ], [ %val2 , %_Z3fooPKc.exit ]
2439
+ %1 = load i8 , ptr %test.0.i12 , align 1
2440
+ %cmp1.not.i13 = icmp eq i8 %1 , 0
2441
+ %incdec.ptr.i14 = getelementptr inbounds i8 , ptr %test.0.i12 , i64 1
2442
+ br i1 %cmp1.not.i13 , label %while.end.i15 , label %while.cond.i11
2443
+
2444
+ while.end.i15 :
2445
+ %sub.ptr.lhs.cast.i16 = ptrtoint ptr %test.0.i12 to i64
2446
+ %sub.ptr.rhs.cast.i17 = ptrtoint ptr %val2 to i64
2447
+ %sub.ptr.sub.i18 = sub i64 %sub.ptr.lhs.cast.i16 , %sub.ptr.rhs.cast.i17
2448
+ br label %_Z3fooPKc.exit19
2449
+
2450
+ _Z3fooPKc.exit19:
2451
+ %retval.0.i20 = phi i64 [ %sub.ptr.sub.i18 , %while.end.i15 ], [ 0 , %_Z3fooPKc.exit ]
2452
+ %2 = or i64 %retval.0.i , %retval.0.i20
2453
+ %or.cond.not = icmp eq i64 %2 , 0
2454
+ br i1 %or.cond.not , label %if.then , label %if.end4
2455
+
2456
+ if.then:
2457
+ %cmp = icmp eq ptr %dv1 , %dv2
2458
+ br label %cleanup
2459
+
2460
+ if.end4:
2461
+ %tobool2 = icmp ne i64 %retval.0.i20 , 0
2462
+ %tobool = icmp ne i64 %retval.0.i , 0
2463
+ %or.cond10 = and i1 %tobool , %tobool2
2464
+ br label %cleanup
2465
+
2466
+ cleanup:
2467
+ %retval.0 = phi i1 [ %cmp , %if.then ], [ %or.cond10 , %if.end4 ]
2468
+ ret i1 %retval.0
2469
+ }
0 commit comments