[PATCH] D69686: [LVI][CVP] Use block value in getPredicateAt()
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 31 14:43:41 PDT 2019
nikic created this revision.
nikic added reviewers: lebedev.ri, reames, spatel.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
This resolves a long-standing deficiency in LVI: The getPredicateAt() method currently does not take into account the block value, i.e. it does not use any information from the current basic block, only information that is threaded over edges. This makes evaluation of icmps in CVP much weaker than it could be. I've included two real-life examples of icmps we fail to simplify under O3 <https://reviews.llvm.org/owners/package/3/>, but can handle after this change.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D69686
Files:
llvm/lib/Analysis/LazyValueInfo.cpp
llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll
llvm/test/Transforms/JumpThreading/bb-unreachable-from-entry.ll
llvm/test/Transforms/JumpThreading/header-succ.ll
Index: llvm/test/Transforms/JumpThreading/header-succ.ll
===================================================================
--- llvm/test/Transforms/JumpThreading/header-succ.ll
+++ llvm/test/Transforms/JumpThreading/header-succ.ll
@@ -103,12 +103,13 @@
; CHECK-NEXT: [[IND:%.*]] = phi i32 [ 0, [[TOP:%.*]] ], [ [[NEXTIND:%.*]], [[LATCH:%.*]] ]
; CHECK-NEXT: [[NEXTIND]] = add i32 [[IND]], 1
; CHECK-NEXT: [[CMP:%.*]] = icmp ule i32 [[IND]], 10
-; CHECK-NEXT: br i1 [[CMP]], label [[LATCH]], label [[EXIT:%.*]]
-; CHECK: latch:
+; CHECK-NEXT: br i1 [[CMP]], label [[BODY:%.*]], label [[LATCH]]
+; CHECK: body:
; CHECK-NEXT: call void @opaque_body()
+; CHECK-NEXT: br label [[LATCH]]
+; CHECK: latch:
+; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ undef, [[ENTRY]] ], [ 0, [[BODY]] ]
; CHECK-NEXT: br label [[ENTRY]]
-; CHECK: exit:
-; CHECK-NEXT: ret void
;
top:
br label %entry
Index: llvm/test/Transforms/JumpThreading/bb-unreachable-from-entry.ll
===================================================================
--- llvm/test/Transforms/JumpThreading/bb-unreachable-from-entry.ll
+++ llvm/test/Transforms/JumpThreading/bb-unreachable-from-entry.ll
@@ -3,7 +3,12 @@
define void @foo() {
; CHECK-LABEL: define {{[^@]+}}@foo(
-; CHECK-NEXT: exit2:
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label [[EXIT2:%.*]]
+; CHECK: entry2:
+; CHECK-NEXT: br label [[EXIT2]]
+; CHECK: exit2:
+; CHECK-NEXT: [[A0:%.*]] = phi i32 [ undef, [[ENTRY2:%.*]] ], [ 0, [[ENTRY:%.*]] ]
; CHECK-NEXT: ret void
;
entry:
Index: llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll
===================================================================
--- llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll
+++ llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll
@@ -381,7 +381,7 @@
; CHECK-NEXT: [[SHR:%.*]] = lshr i64 [[MUL]], 32
; CHECK-NEXT: [[TRUNC:%.*]] = trunc i64 [[SHR]] to i32
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[TRUNC]], 7
-; CHECK-NEXT: ret i1 [[CMP]]
+; CHECK-NEXT: ret i1 true
;
%zext = zext i32 %x to i64
%mul = mul nuw i64 %zext, 7
@@ -397,7 +397,7 @@
; CHECK-NEXT: [[ADD:%.*]] = add nuw nsw i64 [[ZEXT]], 128
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[ADD]], 384
; CHECK-NEXT: store i64 [[ADD]], i64* [[P:%.*]]
-; CHECK-NEXT: ret i1 [[CMP]]
+; CHECK-NEXT: ret i1 true
;
%zext = zext i8 %x to i64
%add = add nuw nsw i64 %zext, 128
Index: llvm/lib/Analysis/LazyValueInfo.cpp
===================================================================
--- llvm/lib/Analysis/LazyValueInfo.cpp
+++ llvm/lib/Analysis/LazyValueInfo.cpp
@@ -1861,7 +1861,14 @@
else if (Pred == ICmpInst::ICMP_NE)
return LazyValueInfo::True;
}
- ValueLatticeElement Result = getImpl(PImpl, AC, &DL, DT).getValueAt(V, CxtI);
+
+ // The getValueInBlock() result is valid anywhere in the block for non-pointer
+ // types. For pointer types, it will additionally take into account pointer
+ // dereferences anywhere in the block, so we need to use the more conservative
+ // getValueAt() function in this case.
+ ValueLatticeElement Result = V->getType()->isPointerTy()
+ ? getImpl(PImpl, AC, &DL, DT).getValueAt(V, CxtI)
+ : getImpl(PImpl, AC, &DL, DT).getValueInBlock(V, CxtI->getParent(), CxtI);
Tristate Ret = getPredicateResult(Pred, C, Result, DL, TLI);
if (Ret != Unknown)
return Ret;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69686.227351.patch
Type: text/x-patch
Size: 3440 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191031/fe4d08ef/attachment.bin>
More information about the llvm-commits
mailing list