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

miscompilation of smul.with.overflow.i2 by arm64 backend #55644

Closed
regehr opened this issue May 23, 2022 · 4 comments
Closed

miscompilation of smul.with.overflow.i2 by arm64 backend #55644

regehr opened this issue May 23, 2022 · 4 comments

Comments

@regehr
Copy link
Contributor

regehr commented May 23, 2022

here's a function:

define i1 @f(i2 %0) {
  %2 = call { i2, i1 } @llvm.smul.with.overflow.i2(i2 %0, i2 -2)
  %3 = extractvalue { i2, i1 } %2, 1
  ret i1 %3
}

declare { i2, i1 } @llvm.smul.with.overflow.i2(i2, i2)

clearly f(1) -> 0 because you can't get an overflow when multiplying by 1 but using this driver:

#include <stdio.h>

unsigned f(unsigned);

int main(void) {
  printf("%u\n", f(1));
}

we get:

Johns-MacBook-Pro:~ regehr$ llc foo.ll
Johns-MacBook-Pro:~ regehr$ clang foo.c foo.s && ./a.out
1
Johns-MacBook-Pro:~ regehr$ 

cc @ornata @nunoplopes @ryan-berger @nbushehri @zhengyang92 @aqjune

@llvmbot
Copy link
Collaborator

llvmbot commented May 23, 2022

@llvm/issue-subscribers-backend-aarch64

@topperc
Copy link
Collaborator

topperc commented May 23, 2022

Probably this in visitMULO

  // (mulo x, 2) -> (addo x, x)
  if (N1C && N1C->getAPIntValue() == 2)
    return DAG.getNode(IsSigned ? ISD::SADDO : ISD::UADDO, DL,
                       N->getVTList(), N0, N0);

We need to check the bitwidth is more than 2.

And we also need a freeze, but that's not the bug here.

@topperc topperc self-assigned this May 23, 2022
@topperc
Copy link
Collaborator

topperc commented May 23, 2022

Will submit patch to phabricator when the ssl certificate is fixed.

@topperc
Copy link
Collaborator

topperc commented May 23, 2022

Fixed by 569d894

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

4 participants