[PATCH] D136244: [AArch64] Optimize memcmp when the result is tested for [in]equality with 0

Dave Green via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 25 00:49:14 PDT 2022


dmgreen added inline comments.


================
Comment at: llvm/test/CodeGen/AArch64/i128-cmp.ll:11
+; CHECK-NEXT:    ccmp x1, x3, #0, eq
+; CHECK-NEXT:    cset w0, ne
 ; CHECK-NEXT:    ret
----------------
Allen wrote:
> dmgreen wrote:
> > Allen wrote:
> > > dmgreen wrote:
> > > > Allen wrote:
> > > > > dmgreen wrote:
> > > > > > Are you sure this is correct? It doesn't look right.
> > > > > > 
> > > > > > I think I would expect `ccmp #0, eq;  cset eq`.
> > > > > Yes, I test the executive for the initial case in https://github.com/llvm/llvm-project/issues/58061
> > > > How did you test that? Is it the code from https://gcc.godbolt.org/z/Tv1YP6bPc? Could it have been constant-folded away?
> > > Yes, I test the executive very simple, just run the following cmd with and without the changes.
> > > **~/llvm-project-upstream/build/bin/clang -march=armv8.2-a -O3 run.c -ffast-math;./a.out **
> > Have you tried with -fno-inline? The example godbolt link has everything inlined into main, and constant folded into the arguments of the printf's. It doesn't look like it is really testing the codegen.
> > I would expect the code to be the same as this for eq, due to the way i128 is split into i64 registers: https://godbolt.org/z/aed4bYn6n
> oh, thanks very much, you are right.
> 
> But how can I get the **#8** for case cmp_i128_ne ? it seem the input Code should be **MI or LT** when it return expect  **"#8"** with function getNZCVToSatisfyCondCode ?
> 
> 
> 
> 
Yeah, #8 is not the only choice. I think it can be any constant where the the Z bit is clear, so #0 is fine (as is #8). #4 is not because that is the Z bit.

Because the eq is a && and the ne is a ||, it might be simpler to just use a constant of 0 in both cases, providing that works.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136244/new/

https://reviews.llvm.org/D136244



More information about the llvm-commits mailing list