Skip to content

Commit 48c4e4f

Browse files
committed
[LVI][CVP] Add support for abs/nabs select pattern flavor
Based on ConstantRange support added in D61084, we can now handle abs and nabs select pattern flavors in LVI. Differential Revision: https://reviews.llvm.org/D61794 llvm-svn: 360700
1 parent 0333dd9 commit 48c4e4f

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

llvm/lib/Analysis/LazyValueInfo.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,28 @@ bool LazyValueInfoImpl::solveBlockValueSelect(ValueLatticeElement &BBLV,
893893
return true;
894894
}
895895

896-
// TODO: ABS, NABS from the SelectPatternResult
896+
if (SPR.Flavor == SPF_ABS) {
897+
if (LHS == SI->getTrueValue()) {
898+
BBLV = ValueLatticeElement::getRange(TrueCR.abs());
899+
return true;
900+
}
901+
if (LHS == SI->getFalseValue()) {
902+
BBLV = ValueLatticeElement::getRange(FalseCR.abs());
903+
return true;
904+
}
905+
}
906+
907+
if (SPR.Flavor == SPF_NABS) {
908+
ConstantRange Zero(APInt::getNullValue(TrueCR.getBitWidth()));
909+
if (LHS == SI->getTrueValue()) {
910+
BBLV = ValueLatticeElement::getRange(Zero.sub(TrueCR.abs()));
911+
return true;
912+
}
913+
if (LHS == SI->getFalseValue()) {
914+
BBLV = ValueLatticeElement::getRange(Zero.sub(FalseCR.abs()));
915+
return true;
916+
}
917+
}
897918
}
898919

899920
// Can we constrain the facts about the true and false values by using the

llvm/test/Transforms/CorrelatedValuePropagation/basic.ll

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -633,8 +633,7 @@ define void @abs1(i32 %a, i1* %p) {
633633
; CHECK-NEXT: store i1 true, i1* [[P:%.*]]
634634
; CHECK-NEXT: [[C2:%.*]] = icmp slt i32 [[ABS]], 19
635635
; CHECK-NEXT: store i1 [[C2]], i1* [[P]]
636-
; CHECK-NEXT: [[C3:%.*]] = icmp sge i32 [[ABS]], 0
637-
; CHECK-NEXT: store i1 [[C3]], i1* [[P]]
636+
; CHECK-NEXT: store i1 true, i1* [[P]]
638637
; CHECK-NEXT: [[C4:%.*]] = icmp sge i32 [[ABS]], 1
639638
; CHECK-NEXT: store i1 [[C4]], i1* [[P]]
640639
; CHECK-NEXT: br label [[EXIT]]
@@ -684,8 +683,7 @@ define void @abs2(i32 %a, i1* %p) {
684683
; CHECK-NEXT: store i1 true, i1* [[P:%.*]]
685684
; CHECK-NEXT: [[C2:%.*]] = icmp slt i32 [[ABS]], 19
686685
; CHECK-NEXT: store i1 [[C2]], i1* [[P]]
687-
; CHECK-NEXT: [[C3:%.*]] = icmp sge i32 [[ABS]], 0
688-
; CHECK-NEXT: store i1 [[C3]], i1* [[P]]
686+
; CHECK-NEXT: store i1 true, i1* [[P]]
689687
; CHECK-NEXT: [[C4:%.*]] = icmp sge i32 [[ABS]], 1
690688
; CHECK-NEXT: store i1 [[C4]], i1* [[P]]
691689
; CHECK-NEXT: br label [[EXIT]]
@@ -735,8 +733,7 @@ define void @nabs1(i32 %a, i1* %p) {
735733
; CHECK-NEXT: store i1 true, i1* [[P:%.*]]
736734
; CHECK-NEXT: [[C2:%.*]] = icmp sgt i32 [[NABS]], -19
737735
; CHECK-NEXT: store i1 [[C2]], i1* [[P]]
738-
; CHECK-NEXT: [[C3:%.*]] = icmp sle i32 [[NABS]], 0
739-
; CHECK-NEXT: store i1 [[C3]], i1* [[P]]
736+
; CHECK-NEXT: store i1 true, i1* [[P]]
740737
; CHECK-NEXT: [[C4:%.*]] = icmp sle i32 [[NABS]], -1
741738
; CHECK-NEXT: store i1 [[C4]], i1* [[P]]
742739
; CHECK-NEXT: br label [[EXIT]]
@@ -786,8 +783,7 @@ define void @nabs2(i32 %a, i1* %p) {
786783
; CHECK-NEXT: store i1 true, i1* [[P:%.*]]
787784
; CHECK-NEXT: [[C2:%.*]] = icmp sgt i32 [[NABS]], -19
788785
; CHECK-NEXT: store i1 [[C2]], i1* [[P]]
789-
; CHECK-NEXT: [[C3:%.*]] = icmp sle i32 [[NABS]], 0
790-
; CHECK-NEXT: store i1 [[C3]], i1* [[P]]
786+
; CHECK-NEXT: store i1 true, i1* [[P]]
791787
; CHECK-NEXT: [[C4:%.*]] = icmp sle i32 [[NABS]], -1
792788
; CHECK-NEXT: store i1 [[C4]], i1* [[P]]
793789
; CHECK-NEXT: br label [[EXIT]]

0 commit comments

Comments
 (0)