[CVP] Stop CVP constant propagation from destroying llvm.assume#183688
[CVP] Stop CVP constant propagation from destroying llvm.assume#183688
llvm.assume#183688Conversation
|
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
|
@llvm/pr-subscribers-llvm-transforms Author: None (lijinpei-amd) ChangesFor following code sequence: CVP may replace all use of Full diff: https://github.com/llvm/llvm-project/pull/183688.diff 3 Files Affected:
diff --git a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
index f4897034569c6..37e46e1b52593 100644
--- a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
+++ b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
@@ -334,8 +334,14 @@ static bool constantFoldCmp(CmpInst *Cmp, LazyValueInfo *LVI) {
return false;
++NumCmps;
- Cmp->replaceAllUsesWith(Res);
- Cmp->eraseFromParent();
+ Cmp->replaceUsesWithIf(Res, [](Use &use) {
+ if (auto *intrin = dyn_cast<IntrinsicInst>(use.getUser())) {
+ return !intrin->isAssumeLikeIntrinsic();
+ }
+ return true;
+ });
+ if (Cmp->use_empty())
+ Cmp->eraseFromParent();
return true;
}
diff --git a/llvm/test/Transforms/CorrelatedValuePropagation/conflict.ll b/llvm/test/Transforms/CorrelatedValuePropagation/conflict.ll
index 7bba0565d9988..88f4aa12e90f2 100644
--- a/llvm/test/Transforms/CorrelatedValuePropagation/conflict.ll
+++ b/llvm/test/Transforms/CorrelatedValuePropagation/conflict.ll
@@ -58,7 +58,8 @@ define i8 @test3(i8 %a) {
; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i8 [[A:%.*]], 5
; CHECK-NEXT: br i1 [[CMP1]], label [[DEAD:%.*]], label [[EXIT:%.*]]
; CHECK: dead:
-; CHECK-NEXT: call void @llvm.assume(i1 false)
+; CHECK-NEXT: [[CMP2:%.*]] = icmp eq i8 [[A]], 3
+; CHECK-NEXT: call void @llvm.assume(i1 [[CMP2]])
; CHECK-NEXT: ret i8 5
; CHECK: exit:
; CHECK-NEXT: ret i8 0
diff --git a/llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll b/llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll
index 7fb1e0718795d..3c7c17a84bf6b 100644
--- a/llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll
+++ b/llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll
@@ -6,6 +6,7 @@ target triple = "x86_64-apple-macosx10.10.0"
declare void @check1(i1) #1
declare void @check2(i1) #1
+declare void @check3(i64)
declare void @llvm.assume(i1)
; Make sure we propagate the value of %tmp35 to the true/false cases
@@ -1657,3 +1658,19 @@ if.true:
if.false:
ret void
}
+
+
+define void @test_assume_not_removed(i64 %idx) {
+; CHECK-LABEL: @test_assume_not_removed(
+; CHECK-NEXT: [[IDX1:%.*]] = add nuw i64 [[IDX:%.*]], 1
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i64 [[IDX1]], 1
+; CHECK-NEXT: tail call void @llvm.assume(i1 [[CMP]])
+; CHECK-NEXT: tail call void @check3(i64 [[IDX1]])
+; CHECK-NEXT: ret void
+;
+ %idx1 = add i64 %idx, 1
+ %cmp = icmp ugt i64 %idx1, 1
+ tail call void @llvm.assume(i1 %cmp)
+ tail call void @check3(i64 %idx1)
+ ret void
+}
|
17f2b1e to
c4c3206
Compare
c4c3206 to
277a834
Compare
277a834 to
4896385
Compare
|
Does it fix #90206? |
nikic
left a comment
There was a problem hiding this comment.
A consequence of this change is that we'll also stop removing redundant assumes in CVP, that is cases where dominating conditions already imply the assume. But probably that makes sense, as the assume is not trivially redundant. In particular, it may still be of value for ValueTracking based optimizations, which do not have a global view.
4896385 to
99239cb
Compare
🐧 Linux x64 Test Results
Failed Tests(click on a test name to see its output) lldb-apilldb-api.functionalities/data-formatter/data-formatter-stl/generic/list/TestDataFormatterGenericList.pyIf these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the |
For following code sequence: ``` %cmp = icmp ugt i64 %idx, 1 tail call void @llvm.assume(i1 %cmp) ``` CVP may replace all use of `%cmp` with `true`, and the information about `%idx` is lost. This commit stop CVP from doing that, so that later pass can exploit the `llvm.assume`.
99239cb to
c0cac23
Compare
|
@lijinpei-amd Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
…vm#183688) For following code sequence: ``` %cmp = icmp ugt i64 %idx, 1 tail call void @llvm.assume(i1 %cmp) ``` CVP may replace all use of `%cmp` with `true`, and the information about `%idx` is lost. This commit stop CVP from doing that, so that later pass can exploit the `llvm.assume`. Fixes llvm#90206.
…vm#183688) For following code sequence: ``` %cmp = icmp ugt i64 %idx, 1 tail call void @llvm.assume(i1 %cmp) ``` CVP may replace all use of `%cmp` with `true`, and the information about `%idx` is lost. This commit stop CVP from doing that, so that later pass can exploit the `llvm.assume`. Fixes llvm#90206.
For following code sequence:
CVP may replace all use of
%cmpwithtrue, and the information about%idxis lost. This commit stop CVP from doing that, so that later pass can exploit thellvm.assume.