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

[InstCombine] Fix test with experimental.guard + nounwind (NFC) #67641

Closed
wants to merge 1 commit into from

Conversation

nikic
Copy link
Contributor

@nikic nikic commented Sep 28, 2023

The function is marked nounwind, so experimental.guard becomes nounwind as well, and in conjunction with willreturn becomes guaranteed-to-transfer. Thus the optimization that this test was supposed to be guarding against is performed. This regressed in fbfb1c7 when experimental.guard was marked willreturn.

I believe this is an error in the test case, and it should not be using nounwind. However, I wanted to double check whether experimental.guard should be willreturn or not. (And possibly nounwind instead -- it depends on how one wants to model them.)

The function is marked nounwind, so experimental.guard becomes
nounwind as well, and in conjunction with willreturn becomes
guaranteed-to-transfer. Thus the optimization that this test
was supposed to be guarding against is performed. This regressed
in fbfb1c7 when experimental.guard
was marked willreturn.

I believe this is an error in the test case, and it should not be
using nounwind. However, I wanted to double check whether
experimental.guard should be willreturn or not. (And possibly
nounwind instead -- it depends on how one wants to model them.)
@llvmbot
Copy link
Collaborator

llvmbot commented Sep 28, 2023

@llvm/pr-subscribers-llvm-transforms

Changes

The function is marked nounwind, so experimental.guard becomes nounwind as well, and in conjunction with willreturn becomes guaranteed-to-transfer. Thus the optimization that this test was supposed to be guarding against is performed. This regressed in fbfb1c7 when experimental.guard was marked willreturn.

I believe this is an error in the test case, and it should not be using nounwind. However, I wanted to double check whether experimental.guard should be willreturn or not. (And possibly nounwind instead -- it depends on how one wants to model them.)


Full diff: https://github.com/llvm/llvm-project/pull/67641.diff

1 Files Affected:

  • (modified) llvm/test/Transforms/InstCombine/sdiv-guard.ll (+4-3)
diff --git a/llvm/test/Transforms/InstCombine/sdiv-guard.ll b/llvm/test/Transforms/InstCombine/sdiv-guard.ll
index ba9670924108b19..b0f96dafa18c0bd 100644
--- a/llvm/test/Transforms/InstCombine/sdiv-guard.ll
+++ b/llvm/test/Transforms/InstCombine/sdiv-guard.ll
@@ -4,10 +4,11 @@
 declare void @llvm.experimental.guard(i1, ...)
 
 ; Regression test. If %flag is false then %s == 0 and guard should be triggered.
-define i32 @a(i1 %flag, i32 %X) nounwind readnone {
+define i32 @a(i1 %flag, i32 %X) {
 ; CHECK-LABEL: @a(
-; CHECK-NEXT:    [[CMP:%.*]] = icmp ne i32 [[X:%.*]], 0
-; CHECK-NEXT:    call void (i1, ...) @llvm.experimental.guard(i1 [[CMP]]) #[[ATTR2:[0-9]+]] [ "deopt"() ]
+; CHECK-NEXT:    [[CMP1:%.*]] = icmp ne i32 [[X:%.*]], 0
+; CHECK-NEXT:    [[CMP:%.*]] = select i1 [[FLAG:%.*]], i1 [[CMP1]], i1 false
+; CHECK-NEXT:    call void (i1, ...) @llvm.experimental.guard(i1 [[CMP]]) [ "deopt"() ]
 ; CHECK-NEXT:    [[R:%.*]] = sdiv i32 100, [[X]]
 ; CHECK-NEXT:    ret i32 [[R]]
 ;

@nikic nikic requested a review from skachkov-sc October 9, 2023 08:10
@nikic
Copy link
Contributor Author

nikic commented Oct 16, 2023

ping

@annamthomas
Copy link
Contributor

This regressed in fbfb1c7 when experimental.guard was marked willreturn.

The problem is thatexperimental.guard should not be marked as willreturn. It has the same properties as experimental.deoptimize in that guards are nounwind, but are not willreturn. We missed this regression since we moved to the llvm.experimental.widenable.condition form instead of generating guards. We're waiting for couple of releases for this mode to stabilize and we should remove the guard form from upstream (as long as no one else is using this representation for some other purposes).

So, the testcase should still have nounwind and the guaranteed-to-transfer will not happen since the guard is not willreturn.

@nikic
Copy link
Contributor Author

nikic commented Oct 18, 2023

Okay, in that case I've put up a new patch that returns the willreturn attribute instead: #69433

@nikic nikic closed this Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants