Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CVP] Flip signedness icmp predicate in use level #69948

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,9 @@ static bool processICmp(ICmpInst *Cmp, LazyValueInfo *LVI) {

ICmpInst::Predicate UnsignedPred =
ConstantRange::getEquivalentPredWithFlippedSignedness(
Cmp->getPredicate(), LVI->getConstantRange(Cmp->getOperand(0), Cmp),
LVI->getConstantRange(Cmp->getOperand(1), Cmp));
Cmp->getPredicate(),
LVI->getConstantRangeAtUse(Cmp->getOperandUse(0)),
LVI->getConstantRangeAtUse(Cmp->getOperandUse(1)));

if (UnsignedPred == ICmpInst::Predicate::BAD_ICMP_PREDICATE)
return false;
Expand Down
105 changes: 105 additions & 0 deletions llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll
Original file line number Diff line number Diff line change
Expand Up @@ -1246,3 +1246,108 @@ declare <2 x i8> @llvm.umin.v2i8(<2 x i8>, <2 x i8>)
declare <2 x i8> @llvm.umax.v2i8(<2 x i8>, <2 x i8>)

attributes #4 = { noreturn }

define i1 @pr69928(i64 noundef %arg, i64 noundef %arg1) {
; CHECK-LABEL: @pr69928(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP1:%.*]] = icmp ult i64 [[ARG:%.*]], 64424509440
; CHECK-NEXT: [[AND:%.*]] = and i64 [[ARG1:%.*]], 4294967295
; CHECK-NEXT: [[CMP2:%.*]] = icmp ult i64 [[ARG]], [[AND]]
; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP1]], i1 [[CMP2]], i1 false
; CHECK-NEXT: ret i1 [[SELECT]]
;
entry:
%cmp1 = icmp ult i64 %arg, 64424509440
%and = and i64 %arg1, 4294967295
%cmp2 = icmp slt i64 %arg, %and
%select = select i1 %cmp1, i1 %cmp2, i1 false
ret i1 %select
}

define i1 @test_select_flip(i64 noundef %arg) {
nikic marked this conversation as resolved.
Show resolved Hide resolved
; CHECK-LABEL: @test_select_flip(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP1:%.*]] = icmp ult i64 [[ARG:%.*]], 1000
; CHECK-NEXT: [[CMP2:%.*]] = icmp ult i64 [[ARG]], 100
; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP1]], i1 [[CMP2]], i1 false
; CHECK-NEXT: ret i1 [[SELECT]]
;
entry:
%cmp1 = icmp ult i64 %arg, 1000
%cmp2 = icmp slt i64 %arg, 100
%select = select i1 %cmp1, i1 %cmp2, i1 false
ret i1 %select
}

define i1 @test_select_flip_fail1(i64 noundef %arg) {
; CHECK-LABEL: @test_select_flip_fail1(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i64 [[ARG:%.*]], 1000
; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i64 [[ARG]], 100
; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP1]], i1 [[CMP2]], i1 false
; CHECK-NEXT: ret i1 [[SELECT]]
;
entry:
%cmp1 = icmp slt i64 %arg, 1000
%cmp2 = icmp slt i64 %arg, 100
%select = select i1 %cmp1, i1 %cmp2, i1 false
ret i1 %select
}

define i1 @test_select_flip_fail2(i64 noundef %arg) {
; CHECK-LABEL: @test_select_flip_fail2(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP1:%.*]] = icmp ult i64 [[ARG:%.*]], 1000
; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i64 [[ARG]], 100
; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP1]], i1 false, i1 [[CMP2]]
; CHECK-NEXT: ret i1 [[SELECT]]
;
entry:
%cmp1 = icmp ult i64 %arg, 1000
%cmp2 = icmp slt i64 %arg, 100
%select = select i1 %cmp1, i1 false, i1 %cmp2
ret i1 %select
}

define i1 @test_select_flip_fail3(i64 noundef %arg, i64 noundef %arg1) {
; CHECK-LABEL: @test_select_flip_fail3(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP1:%.*]] = icmp ult i64 [[ARG1:%.*]], 1000
; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i64 [[ARG:%.*]], 100
; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP1]], i1 [[CMP2]], i1 false
; CHECK-NEXT: ret i1 [[SELECT]]
;
entry:
%cmp1 = icmp ult i64 %arg1, 1000
%cmp2 = icmp slt i64 %arg, 100
%select = select i1 %cmp1, i1 %cmp2, i1 false
ret i1 %select
}

define i1 @test_select_flip_fail4(i64 noundef %arg) {
; CHECK-LABEL: @test_select_flip_fail4(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i64 [[ARG:%.*]], 100
; CHECK-NEXT: [[SELECT:%.*]] = select i1 true, i1 [[CMP2]], i1 false
; CHECK-NEXT: ret i1 [[SELECT]]
;
entry:
%cmp2 = icmp slt i64 %arg, 100
%select = select i1 true, i1 %cmp2, i1 false
ret i1 %select
}

define i1 @test_select_flip_fail5(i64 noundef %arg, i64 noundef %arg1) {
; CHECK-LABEL: @test_select_flip_fail5(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP1:%.*]] = icmp ult i64 [[ARG:%.*]], 1000
; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i64 [[ARG]], [[ARG1:%.*]]
; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP1]], i1 [[CMP2]], i1 false
; CHECK-NEXT: ret i1 [[SELECT]]
;
entry:
%cmp1 = icmp ult i64 %arg, 1000
%cmp2 = icmp slt i64 %arg, %arg1
%select = select i1 %cmp1, i1 %cmp2, i1 false
ret i1 %select
}