Skip to content

Commit a4318a2

Browse files
author
Biplob Mishra
committed
Precommit tests for gep has phi ptr
1 parent a5a6008 commit a4318a2

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

llvm/test/Transforms/InstCombine/sub-gep.ll

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,3 +369,108 @@ define i64 @gep_diff_with_bitcast(ptr %p, i64 %idx) {
369369
%i6 = lshr i64 %i5, 5
370370
ret i64 %i6
371371
}
372+
373+
define i1 @_gep_phi1(ptr noundef %str1) {
374+
; CHECK-LABEL: @_gep_phi1(
375+
; CHECK-NEXT: entry:
376+
; CHECK-NEXT: [[CMP_I:%.*]] = icmp eq ptr [[STR1:%.*]], null
377+
; CHECK-NEXT: br i1 [[CMP_I]], label [[_Z3FOOPKC_EXIT:%.*]], label [[LOR_LHS_FALSE_I:%.*]]
378+
; CHECK: lor.lhs.false.i:
379+
; CHECK-NEXT: [[TMP0:%.*]] = load i8, ptr [[STR1]], align 1
380+
; CHECK-NEXT: [[CMP1_I:%.*]] = icmp eq i8 [[TMP0]], 0
381+
; CHECK-NEXT: br i1 [[CMP1_I]], label [[_Z3FOOPKC_EXIT]], label [[WHILE_COND_I:%.*]]
382+
; CHECK: while.cond.i:
383+
; CHECK-NEXT: [[A_PN_I:%.*]] = phi ptr [ [[TEST_0_I:%.*]], [[WHILE_COND_I]] ], [ [[STR1]], [[LOR_LHS_FALSE_I]] ]
384+
; CHECK-NEXT: [[TEST_0_I]] = getelementptr inbounds i8, ptr [[A_PN_I]], i64 1
385+
; CHECK-NEXT: [[TMP1:%.*]] = load i8, ptr [[TEST_0_I]], align 1
386+
; CHECK-NEXT: [[CMP3_NOT_I:%.*]] = icmp eq i8 [[TMP1]], 0
387+
; CHECK-NEXT: br i1 [[CMP3_NOT_I]], label [[WHILE_END_I:%.*]], label [[WHILE_COND_I]]
388+
; CHECK: while.end.i:
389+
; CHECK-NEXT: [[TMP2:%.*]] = icmp ne ptr [[TEST_0_I]], [[STR1]]
390+
; CHECK-NEXT: br label [[_Z3FOOPKC_EXIT]]
391+
; CHECK: _Z3fooPKc.exit:
392+
; CHECK-NEXT: [[RETVAL_0_I:%.*]] = phi i1 [ [[TMP2]], [[WHILE_END_I]] ], [ false, [[LOR_LHS_FALSE_I]] ], [ false, [[ENTRY:%.*]] ]
393+
; CHECK-NEXT: ret i1 [[RETVAL_0_I]]
394+
;
395+
entry:
396+
%cmp.i = icmp eq ptr %str1, null
397+
br i1 %cmp.i, label %_Z3fooPKc.exit, label %lor.lhs.false.i
398+
399+
lor.lhs.false.i:
400+
%0 = load i8, ptr %str1, align 1
401+
%cmp1.i = icmp eq i8 %0, 0
402+
br i1 %cmp1.i, label %_Z3fooPKc.exit, label %while.cond.i
403+
404+
while.cond.i:
405+
%a.pn.i = phi ptr [ %test.0.i, %while.cond.i ], [ %str1, %lor.lhs.false.i ]
406+
%test.0.i = getelementptr inbounds i8, ptr %a.pn.i, i64 1
407+
%1 = load i8, ptr %test.0.i, align 1
408+
%cmp3.not.i = icmp eq i8 %1, 0
409+
br i1 %cmp3.not.i, label %while.end.i, label %while.cond.i
410+
411+
while.end.i:
412+
%sub.ptr.lhs.cast.i = ptrtoint ptr %test.0.i to i64
413+
%sub.ptr.rhs.cast.i = ptrtoint ptr %str1 to i64
414+
%sub.ptr.sub.i = sub i64 %sub.ptr.lhs.cast.i, %sub.ptr.rhs.cast.i
415+
br label %_Z3fooPKc.exit
416+
417+
_Z3fooPKc.exit:
418+
%retval.0.i = phi i64 [ %sub.ptr.sub.i, %while.end.i ], [ 0, %lor.lhs.false.i ], [ 0, %entry ]
419+
%tobool = icmp ne i64 %retval.0.i, 0
420+
ret i1 %tobool
421+
}
422+
423+
define i1 @_gep_phi2(ptr noundef %str1, i64 %val2) {
424+
; CHECK-LABEL: @_gep_phi2(
425+
; CHECK-NEXT: entry:
426+
; CHECK-NEXT: [[CMP_I:%.*]] = icmp eq ptr [[STR1:%.*]], null
427+
; CHECK-NEXT: br i1 [[CMP_I]], label [[_Z3FOOPKC_EXIT:%.*]], label [[LOR_LHS_FALSE_I:%.*]]
428+
; CHECK: lor.lhs.false.i:
429+
; CHECK-NEXT: [[TMP0:%.*]] = load i8, ptr [[STR1]], align 1
430+
; CHECK-NEXT: [[CMP1_I:%.*]] = icmp eq i8 [[TMP0]], 0
431+
; CHECK-NEXT: br i1 [[CMP1_I]], label [[_Z3FOOPKC_EXIT]], label [[WHILE_COND_I:%.*]]
432+
; CHECK: while.cond.i:
433+
; CHECK-NEXT: [[A_PN_I:%.*]] = phi ptr [ [[TEST_0_I:%.*]], [[WHILE_COND_I]] ], [ [[STR1]], [[LOR_LHS_FALSE_I]] ]
434+
; CHECK-NEXT: [[TEST_0_I]] = getelementptr inbounds i8, ptr [[A_PN_I]], i64 1
435+
; CHECK-NEXT: [[TMP1:%.*]] = load i8, ptr [[TEST_0_I]], align 1
436+
; CHECK-NEXT: [[CMP3_NOT_I:%.*]] = icmp eq i8 [[TMP1]], 0
437+
; CHECK-NEXT: br i1 [[CMP3_NOT_I]], label [[WHILE_END_I:%.*]], label [[WHILE_COND_I]]
438+
; CHECK: while.end.i:
439+
; CHECK-NEXT: [[SUB_PTR_LHS_CAST_I:%.*]] = ptrtoint ptr [[TEST_0_I]] to i64
440+
; CHECK-NEXT: [[SUB_PTR_RHS_CAST_I:%.*]] = ptrtoint ptr [[STR1]] to i64
441+
; CHECK-NEXT: [[SUB_PTR_SUB_I:%.*]] = sub i64 [[SUB_PTR_LHS_CAST_I]], [[SUB_PTR_RHS_CAST_I]]
442+
; CHECK-NEXT: br label [[_Z3FOOPKC_EXIT]]
443+
; CHECK: _Z3fooPKc.exit:
444+
; CHECK-NEXT: [[RETVAL_0_I:%.*]] = phi i64 [ [[SUB_PTR_SUB_I]], [[WHILE_END_I]] ], [ 0, [[LOR_LHS_FALSE_I]] ], [ 0, [[ENTRY:%.*]] ]
445+
; CHECK-NEXT: [[TMP2:%.*]] = or i64 [[RETVAL_0_I]], [[VAL2:%.*]]
446+
; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i64 [[TMP2]], 0
447+
; CHECK-NEXT: ret i1 [[TOBOOL]]
448+
;
449+
entry:
450+
%cmp.i = icmp eq ptr %str1, null
451+
br i1 %cmp.i, label %_Z3fooPKc.exit, label %lor.lhs.false.i
452+
453+
lor.lhs.false.i:
454+
%0 = load i8, ptr %str1, align 1
455+
%cmp1.i = icmp eq i8 %0, 0
456+
br i1 %cmp1.i, label %_Z3fooPKc.exit, label %while.cond.i
457+
458+
while.cond.i:
459+
%a.pn.i = phi ptr [ %test.0.i, %while.cond.i ], [ %str1, %lor.lhs.false.i ]
460+
%test.0.i = getelementptr inbounds i8, ptr %a.pn.i, i64 1
461+
%1 = load i8, ptr %test.0.i, align 1
462+
%cmp3.not.i = icmp eq i8 %1, 0
463+
br i1 %cmp3.not.i, label %while.end.i, label %while.cond.i
464+
465+
while.end.i:
466+
%sub.ptr.lhs.cast.i = ptrtoint ptr %test.0.i to i64
467+
%sub.ptr.rhs.cast.i = ptrtoint ptr %str1 to i64
468+
%sub.ptr.sub.i = sub i64 %sub.ptr.lhs.cast.i, %sub.ptr.rhs.cast.i
469+
br label %_Z3fooPKc.exit
470+
471+
_Z3fooPKc.exit:
472+
%retval.0.i = phi i64 [ %sub.ptr.sub.i, %while.end.i ], [ 0, %lor.lhs.false.i ], [ 0, %entry ]
473+
%2 = or i64 %retval.0.i, %val2
474+
%tobool = icmp eq i64 %2, 0
475+
ret i1 %tobool
476+
}

0 commit comments

Comments
 (0)