[InstCombine] add tests for implied simplifications; NFC

Ideally, we would fold all of these in InstSimplify in a
similar way to rL347896, but this is a bit awkward when
we're trying to simplify a compare directly because the
ValueTracking API expects the compare as an input, but
in InstSimplify, we just have the operands of the compare.

Given that we can do transforms besides just simplifications,
we might as well just extend the code in InstCombine (which 
already does simplifications with constant operands).

llvm-svn: 348312
This commit is contained in:
Sanjay Patel 2018-12-04 22:25:33 +00:00
parent f28e4aa042
commit 28d71715a3

View File

@ -160,3 +160,171 @@ return:
ret void
}
define i1 @trueblock_cmp_is_false(i32 %x, i32 %y) {
; CHECK-LABEL: @trueblock_cmp_is_false(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
; CHECK: t:
; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i32 [[X]], [[Y]]
; CHECK-NEXT: ret i1 [[CMP2]]
; CHECK: f:
; CHECK-NEXT: ret i1 [[CMP]]
;
entry:
%cmp = icmp sgt i32 %x, %y
br i1 %cmp, label %t, label %f
t:
%cmp2 = icmp slt i32 %x, %y
ret i1 %cmp2
f:
ret i1 %cmp
}
define i1 @trueblock_cmp_is_false_commute(i32 %x, i32 %y) {
; CHECK-LABEL: @trueblock_cmp_is_false_commute(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
; CHECK: t:
; CHECK-NEXT: [[CMP2:%.*]] = icmp sgt i32 [[Y]], [[X]]
; CHECK-NEXT: ret i1 [[CMP2]]
; CHECK: f:
; CHECK-NEXT: ret i1 [[CMP]]
;
entry:
%cmp = icmp eq i32 %x, %y
br i1 %cmp, label %t, label %f
t:
%cmp2 = icmp sgt i32 %y, %x
ret i1 %cmp2
f:
ret i1 %cmp
}
define i1 @trueblock_cmp_is_true(i32 %x, i32 %y) {
; CHECK-LABEL: @trueblock_cmp_is_true(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
; CHECK: t:
; CHECK-NEXT: [[CMP2:%.*]] = icmp ne i32 [[X]], [[Y]]
; CHECK-NEXT: ret i1 [[CMP2]]
; CHECK: f:
; CHECK-NEXT: ret i1 [[CMP]]
;
entry:
%cmp = icmp ult i32 %x, %y
br i1 %cmp, label %t, label %f
t:
%cmp2 = icmp ne i32 %x, %y
ret i1 %cmp2
f:
ret i1 %cmp
}
define i1 @trueblock_cmp_is_true_commute(i32 %x, i32 %y) {
; CHECK-LABEL: @trueblock_cmp_is_true_commute(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
; CHECK: t:
; CHECK-NEXT: [[CMP2:%.*]] = icmp ne i32 [[Y]], [[X]]
; CHECK-NEXT: ret i1 [[CMP2]]
; CHECK: f:
; CHECK-NEXT: ret i1 [[CMP]]
;
entry:
%cmp = icmp ugt i32 %x, %y
br i1 %cmp, label %t, label %f
t:
%cmp2 = icmp ne i32 %y, %x
ret i1 %cmp2
f:
ret i1 %cmp
}
define i1 @falseblock_cmp_is_false(i32 %x, i32 %y) {
; CHECK-LABEL: @falseblock_cmp_is_false(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP:%.*]] = icmp sle i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
; CHECK: t:
; CHECK-NEXT: ret i1 [[CMP]]
; CHECK: f:
; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i32 [[X]], [[Y]]
; CHECK-NEXT: ret i1 [[CMP2]]
;
entry:
%cmp = icmp sle i32 %x, %y
br i1 %cmp, label %t, label %f
t:
ret i1 %cmp
f:
%cmp2 = icmp slt i32 %x, %y
ret i1 %cmp2
}
define i1 @falseblock_cmp_is_false_commute(i32 %x, i32 %y) {
; CHECK-LABEL: @falseblock_cmp_is_false_commute(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
; CHECK: t:
; CHECK-NEXT: ret i1 [[CMP]]
; CHECK: f:
; CHECK-NEXT: [[CMP2:%.*]] = icmp eq i32 [[Y]], [[X]]
; CHECK-NEXT: ret i1 [[CMP2]]
;
entry:
%cmp = icmp eq i32 %x, %y
br i1 %cmp, label %t, label %f
t:
ret i1 %cmp
f:
%cmp2 = icmp eq i32 %y, %x
ret i1 %cmp2
}
define i1 @falseblock_cmp_is_true(i32 %x, i32 %y) {
; CHECK-LABEL: @falseblock_cmp_is_true(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
; CHECK: t:
; CHECK-NEXT: ret i1 [[CMP]]
; CHECK: f:
; CHECK-NEXT: [[CMP2:%.*]] = icmp uge i32 [[X]], [[Y]]
; CHECK-NEXT: ret i1 [[CMP2]]
;
entry:
%cmp = icmp ult i32 %x, %y
br i1 %cmp, label %t, label %f
t:
ret i1 %cmp
f:
%cmp2 = icmp uge i32 %x, %y
ret i1 %cmp2
}
define i1 @falseblock_cmp_is_true_commute(i32 %x, i32 %y) {
; CHECK-LABEL: @falseblock_cmp_is_true_commute(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
; CHECK: t:
; CHECK-NEXT: ret i1 [[CMP]]
; CHECK: f:
; CHECK-NEXT: [[CMP2:%.*]] = icmp sge i32 [[Y]], [[X]]
; CHECK-NEXT: ret i1 [[CMP2]]
;
entry:
%cmp = icmp sgt i32 %x, %y
br i1 %cmp, label %t, label %f
t:
ret i1 %cmp
f:
%cmp2 = icmp sge i32 %y, %x
ret i1 %cmp2
}