Skip to content
This repository was archived by the owner on Sep 2, 2018. It is now read-only.

Division operations are being incorrectly lowered #70

Closed
dylanmckay opened this issue Mar 25, 2015 · 5 comments
Closed

Division operations are being incorrectly lowered #70

dylanmckay opened this issue Mar 25, 2015 · 5 comments

Comments

@dylanmckay
Copy link
Member

We are not handling the lowering of various instructions correctly.

This problem came about in this mailing list exchange.

Division is being lowered into a call to the libgcc function __udivqi3. This function does not exist. GCC instead lowers this to __divmodhi4, which is what we should be doing.

@dylanmckay dylanmckay added the bug label Mar 25, 2015
simonpcook added a commit to simonpcook/avr-llvm that referenced this issue Apr 22, 2015
This should be __divmodhi4 for AVR. Fixes bug avr-llvm#70.
@dylanmckay
Copy link
Member Author

We should be able to handle this by adding a case to the switch in AVRISelLowering::LowerOperation(). As @simonpcook said, custom lowering the divide may be the best solution.

See the ARMISelLowering::LowerOperation() for an example.

@dylanmckay
Copy link
Member Author

Note that a number of the compiler runtime library functions do not follow the normal AVR ABI.

See the avr-gcc wiki, heading "Exceptions to the calling convention" for details.

@dylanmckay
Copy link
Member Author

I believe the best way would be to create a custom calling convention which special cases all of the routines from the AVR-GCC wiki which do not follow the standard convention. This way libcalls would work as expected.

@dylanmckay dylanmckay changed the title Arithmetic operations are being incorrectly lowered Division operations are being incorrectly lowered Jul 17, 2015
@dylanmckay
Copy link
Member Author

I have implemented 8 and 16-bit division using custom lowering.

We cannot custom lower a 32-bit (or greater) values because the type is illegal. I am not sure how to go about this.

@agnat
Copy link

agnat commented Jul 22, 2015

The follow-up is #149.

We cannot custom lower a 32-bit (or greater) values because the type is illegal. I am not sure how to go about this.

Hehe... The whole concept of "legal types" is ... I wouldn't say flawed... but it just doesn't cut it for small targets. It is exactly what I'm trying to hack up to get rid of the pseudo instructions. If I succeed handling the division library calls shouldn't be a problem.

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

No branches or pull requests

2 participants