Skip to content

Commit

Permalink
[ConstraintElimination] Extend test coverage.
Browse files Browse the repository at this point in the history
This patch adds a lot of additional tests, focusing on loops and GEP
arithmetic. Some of the tests expose existing problems, which will be
fixed soon.
  • Loading branch information
fhahn committed Feb 6, 2021
1 parent e6810ca commit 14da287
Show file tree
Hide file tree
Showing 15 changed files with 2,813 additions and 7 deletions.
67 changes: 66 additions & 1 deletion llvm/test/Transforms/ConstraintElimination/add-nuw.ll
Expand Up @@ -335,5 +335,70 @@ if.end: ; preds = %entry
}


define i1 @test_n_must_ule_1_due_to_nuw(i8 %n, i8 %i) {
entry:
%sub.n.1 = add nuw i8 %n, -1
%add = add nuw i8 %i, %sub.n.1
%c.1 = icmp uge i8 %i, %add
br i1 %c.1, label %if.then, label %if.end

if.then: ; preds = %entry
%t = icmp ule i8 %n, 1
ret i1 %t

if.end: ; preds = %entry
%f = icmp ule i8 %n, 1
ret i1 %f
}


define i1 @test_n_unknown_missing_nuw(i8 %n, i8 %i) {
entry:
%sub.n.1 = add i8 %n, -1
%add = add i8 %i, %sub.n.1
%c.1 = icmp uge i8 %i, %add
br i1 %c.1, label %if.then, label %if.end

if.then: ; preds = %entry
%t = icmp ule i8 %n, 1
ret i1 %t

if.end: ; preds = %entry
%f = icmp ule i8 %n, 1
ret i1 %f
}

define i1 @test_n_must_ule_2_due_to_nuw(i8 %n, i8 %i) {
entry:
%sub.n.1 = add nuw i8 %n, -2
%add = add nuw i8 %i, %sub.n.1
%c.1 = icmp uge i8 %i, %add
br i1 %c.1, label %if.then, label %if.end

if.then: ; preds = %entry
%t = icmp ule i8 %n, 2
ret i1 %t

if.end: ; preds = %entry
%f = icmp ule i8 %n, 2
ret i1 %f
}


define i1 @test_n_unknown_missing_nuw2(i8 %n, i8 %i) {
entry:
%sub.n.1 = add i8 %n, -2
%add = add i8 %i, %sub.n.1
%c.1 = icmp uge i8 %i, %add
br i1 %c.1, label %if.then, label %if.end

if.then: ; preds = %entry
%t = icmp ule i8 %n, 1
ret i1 %t

if.end: ; preds = %entry
%f = icmp ule i8 %n, 1
ret i1 %f
}

declare void @use(i1)
declare void @llvm.trap()
1 change: 0 additions & 1 deletion llvm/test/Transforms/ConstraintElimination/add.ll
Expand Up @@ -239,4 +239,3 @@ if.end: ; preds = %entry


declare void @use(i1)
declare void @llvm.trap()
27 changes: 27 additions & 0 deletions llvm/test/Transforms/ConstraintElimination/and.ll
Expand Up @@ -135,3 +135,30 @@ exit:

ret i32 20
}

define i4 @and_compare_undef(i16 %N, i16 %step) {
; CHECK-LABEL: @and_compare_undef(
; CHECK-NEXT: step.check:
; CHECK-NEXT: [[STEP_POS:%.*]] = icmp uge i16 [[STEP:%.*]], 0
; CHECK-NEXT: [[B1:%.*]] = add i16 undef, -1
; CHECK-NEXT: [[STEP_ULT_N:%.*]] = icmp ult i16 [[B1]], [[N:%.*]]
; CHECK-NEXT: [[AND_STEP:%.*]] = and i1 [[STEP_POS]], [[STEP_ULT_N]]
; CHECK-NEXT: br i1 [[AND_STEP]], label [[PTR_CHECK:%.*]], label [[EXIT:%.*]]
; CHECK: ptr.check:
; CHECK-NEXT: br label [[EXIT]]
; CHECK: exit:
; CHECK-NEXT: ret i4 3
;
step.check:
%step.pos = icmp uge i16 %step, 0
%B1 = add i16 undef, -1
%step.ult.N = icmp ult i16 %B1, %N
%and.step = and i1 %step.pos, %step.ult.N
br i1 %and.step, label %ptr.check, label %exit

ptr.check:
br label %exit

exit:
ret i4 3
}

0 comments on commit 14da287

Please sign in to comment.