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

Chained comparison of two integers against a constant is not coalesced #102103

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

pedrobsaila
Copy link
Contributor

Fixes #101347

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label May 10, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label May 10, 2024
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

@neon-sunset
Copy link
Contributor

Seems to have regressions on arm64 too 😢 I suppose Clang/LLVM reasons about these in a more generalized way...

612735.dasm - Program:InstanceMethodTest():ubyte (FullOpts)
@@ -174,11 +174,14 @@ G_M34320_IG08:        ; bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, byref
             ldr     x3, [x3]
             blr     x3
             ; gcrRegs -[x1-x2 x22]
-            cmn     w20, #1
+            movn    w0, #41
+            eor     w0, w21, w0
+            movn    w1, #0
+            eor     w1, w20, w1
+            orr     w0, w0, w1
+            cmp     w0, #0
             cset    x0, eq
-            cmn     w21, #42
-            csel    w0, wzr, w0, ne
-						;; size=88 bbWeight=1 PerfScore 16.00
+						;; size=100 bbWeight=1 PerfScore 17.50

@pedrobsaila
Copy link
Contributor Author

pedrobsaila commented May 12, 2024

It seems the regressions happen on ARM because it already supports conditional select in assembly which prevents from creating branches. Our optimization seems to confuse the JIT from recognizing the pattern and using the csel in certain methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Chained comparison of two integers against a constant is not coalesced
2 participants