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

LowerCallResult regression bugfix #10

Closed
wants to merge 2 commits into from
Closed

LowerCallResult regression bugfix #10

wants to merge 2 commits into from

Conversation

carlos4242
Copy link

@carlos4242 carlos4242 commented Mar 9, 2019

bugfix:

  • The reversal function call had somehow got removed from LowerCallResult, meaning calls returning i32 (or greater) were effectively being word swapped

improvements:

  • The function name ReverseArgumentsToBigEndian is (I think) a bit misleading, I suggest something like ReverseReturnValuePartsToEnsureLittleEndian
  • Also added some explanatory comments to the function.
  • Moved the check for whether this is a split return value or not outside the function as I think that's more clear.

tests:

bugfix:
- The reversal function call had somehow got removed from LowerCallResult, meaning calls returning i32 (or greater) were effectively being word swapped

improvements:
- The function name ReverseArgumentsToBigEndian is (I think) a bit misleading, I suggest something like ReverseReturnValuePartsToEnsureLittleEndian
- Also added some explanatory comments to the function.
- Moved the check for whether this is a split return value or not outside the function as I think that's more clear.

tests:
- Added a test for the regression in rust-lang#92, which is also causing rust-lang#130
- corrected directmem.ll at the same time as that had become broken by e2baccf
Copy link
Member

@dylanmckay dylanmckay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, looking good, only one suggestion from me.

In terms of testing, have you been able to verify that >16-bit calls (like multiplication) spit out the right numbers when executed?

lib/Target/AVR/AVRISelLowering.cpp Outdated Show resolved Hide resolved
@shepmaster
Copy link
Member

@dylanmckay no pressure intended, but the "easiest" way to get these PRs from this repo into the new llvm-project repo would be to merge them into upstream LLVM and then we can cherry-pick them 😉

@dylanmckay
Copy link
Member

dylanmckay commented May 16, 2019

I've created two branches in my LLVM fork for upstreaming

The first one, the fix for avr-rust/rust-legacy-fork#92 looks good and it doesn't introduce test failures. The second one, the fix for avr-rust/rust-legacy-fork#129, currently fails on the newly introduced test, test/CodeGen/AVR/call-avr-rust-issue-130-regression.ll.

FAIL: LLVM :: CodeGen/AVR/call-avr-rust-issue-130-regression.ll (1 of 1)
******************** TEST 'LLVM :: CodeGen/AVR/call-avr-rust-issue-130-regression.ll' FAILED ********************
Script:
--
: 'RUN: at line 1';   /home/dylan/projects/builds/llvm-project/llvm/bin/llc -O1 < /home/dylan/projects/llvm-project/llvm/test/CodeGen/AVR/call-avr-rust-issue-130-regression.ll -march=avr | /home/dylan/projects/builds/llvm-project/llvm/bin/FileCheck /home/dylan/projects/llvm-project/llvm/test/CodeGen/AVR/call-avr-rust-issue-130-regression.ll
--
Exit Code: 1

Command Output (stderr):
--
/home/dylan/projects/llvm-project/llvm/test/CodeGen/AVR/call-avr-rust-issue-130-regression.ll:22:10: error: CHECK: expected string not found in input
; CHECK: ldi r20, 0
         ^
<stdin>:26:2: note: scanning from here
 mov r24, r22
 ^

--

********************
Testing Time: 0.18s
********************
Failing Tests (1):
    LLVM :: CodeGen/AVR/call-avr-rust-issue-130-regression.ll

  Unexpected Failures: 1

1 warning(s) in tests.

The assembly that is now generated for the setServoAngle2 method is

        .p2align        1
        .type   setServoAngle2,@function
setServoAngle2:                         ; @setServoAngle2
; %bb.0:                                ; %entry
        ldi     r18, 19
        ldi     r19, 0
        mov     r24, r22
        mov     r25, r23
        mov     r22, r18
        mov     r23, r19
        call    __mulhi3
        ret

Beforehand, 4 bytes were explicitly loaded to repreesnt the integer literal multiplicand, but now only the lower two are loaded, seemingly leaving the top two bytes undefined.

Do you know what might be going on @carlos4242 ?

@carlos4242
Copy link
Author

carlos4242 commented May 20, 2019 via email

@dylanmckay
Copy link
Member

Yes, my mistake, I have edited my comment.

@carlos4242
Copy link
Author

Ok. It will take me a few days to check it over. I’m pretty sure the test that’s regressed is one I wrote to catch the regression on 130? So I’ll need to have a nice cup of tea, sit down and look over it carefully. :)

[Glad we are getting these fixed now... side note: 128 is going to be a tricky one!]

@carlos4242
Copy link
Author

OK, had a chance to look more closely at this (sorry about the delay).

This has me a little puzzled as it compiles fine on my local branch, which is basically avr-rust-2019-01-18, plus my bufixes for rust-lang#92/rust-lang#130 and then rust-lang#129.

My compiler outputs this for setServoAngle2...

setServoAngle2:                         ; @setServoAngle2
; %bb.0:                                ; %entry
	ldi	r18, 19
	ldi	r19, 0
	ldi	r20, 0
	ldi	r21, 0
	call	__mulsi3
	mov	r24, r22
	mov	r25, r23
	ret
.Lfunc_end1:
	.size	setServoAngle2, .Lfunc_end1-setServoAngle2
                                        ; -- End function

Which looks correct to me.

The version you are getting is doing 16 bit multiplication, it's calling a different gcc runtime library function, __mulhi3. I can't understand how. Can there be something different in instruction selection?

Have you got some extra code on your branch before the patches, downstream from avr-rust-2019-01-18, which was the baseline I used? Maybe your baseline is more recent?

The assembly in your case should produce the same result and is more efficient, because the end result is truncated to 16 bit before return, any parts of the multiplicands beyond bit 16 would have been truncated away, so converting both multiplicands to 16 bit first then calling __mulhi3 is definitely more optimised code without loss of function.

Which suggests this is probably a benign unit test fail, the test might just need updating.

@carlos4242 carlos4242 closed this by deleting the head repository Nov 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants