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

AArch64: there seems to be a bug in DAGCombiner. #89061

Closed
ParkHanbum opened this issue Apr 17, 2024 · 3 comments
Closed

AArch64: there seems to be a bug in DAGCombiner. #89061

ParkHanbum opened this issue Apr 17, 2024 · 3 comments

Comments

@ParkHanbum
Copy link
Contributor

ParkHanbum commented Apr 17, 2024

I'm working on this issue #34101
while proceeding, I found bug when we doing shifting array index by right 1.

here is example:

int test(long a, long b, int *table) {    
  return table[(a) >> 1];  
}
test(long, long, int*):                            // @test(unsigned long long, unsigned long long, int*)
        mul     x8, x1, x0
        lsl     x8, x8, #1
        and     x8, x8, #0xfffffffffffffffc
        ldr     w0, [x2, x8]
        ret

as you can see, we doing shifting array index by left 1.
I think this bug causes by we do not considering how shift amount to array index.
and this is debugging log that how this code occurred bad shifting.

# loss highest bit
1    int bug(long long a, int *table)
   2    {
-> 3      return table[(a)>>1];
   4    }
warning: a.out was compiled with optimization - stepping may behave oddly; variables may not be available.
(lldb) disas -a bug
a.out`bug:
->  0x100003f84 <+0>:  lsl    x8, x0, #1
    0x100003f88 <+4>:  and    x8, x8, #0xfffffffffffffffc
    0x100003f8c <+8>:  ldr    w0, [x1, x8]
    0x100003f90 <+12>: ret    
(lldb) p $x0
(unsigned long) 9223372036854775808
(lldb) ni
Process 79078 stopped
* thread #1, queue = 'cohttp://m.apple.main-thread',/ stop reason = instruction step over
    frame #0: 0x0000000100003f88 a.out`bug(a=-9223372036854775808, table=0x00006000016f0020) at bug.c:3:10 [opt]
   1    int bug(long long a, int *table)
   2    {
-> 3      return table[(a)>>1];
   4    }
(lldb) p $x0
(unsigned long) 9223372036854775808
(lldb) p $x8
(unsigned long) 0
(lldb) ni
Process 79078 stopped
* thread #1, queue = 'cohttp://m.apple.main-thread',/ stop reason = instruction step over
    frame #0: 0x0000000100003f8c a.out`bug(a=-9223372036854775808, table=0x00006000016f0020) at bug.c:3:10 [opt]
   1    int bug(long long a, int *table)
   2    {
-> 3      return table[(a)>>1];
   4    }
(lldb) p $x8
(unsigned long) 0

godbolt link : https://simd.godbolt.org/z/a819j4xGP

how do you think?

ps. I wish take this issue to solve also :)

@llvmbot
Copy link
Member

llvmbot commented Apr 17, 2024

@llvm/issue-subscribers-backend-aarch64

Author: hanbeom (ParkHanbum)

I'm working on this issue https://github.com//issues/34101 while proceeding, I found bug when we doing shifting array index by right 1.

here is example:

int test(unsigned long long a, unsigned long long b, int *table) {    
  return table[(a * b) &gt;&gt; 1];  
}
test(unsigned long long, unsigned long long, int*):                            // @<!-- -->test(unsigned long long, unsigned long long, int*)
        mul     x8, x1, x0
        lsl     x8, x8, #<!-- -->1
        and     x8, x8, #<!-- -->0xfffffffffffffffc
        ldr     w0, [x2, x8]
        ret

as you can see, we doing shifting array index by left 3.
I think this bug causes by we do not considering how shift amount to array index.

how do you think?

ps. I wish take this issue to solve also :)

@EugeneZelenko
Copy link
Contributor

@ParkHanbum: Could you please elaborate?

@ParkHanbum
Copy link
Contributor Author

@EugeneZelenko I'm adding more detail and reopen it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants