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

Descend to nested lvalue for assign, binAssign and address-of expressions. #873

Merged
merged 1 commit into from Mar 28, 2015

Conversation

kinke
Copy link
Member

@kinke kinke commented Mar 27, 2015

Thereby enabling nested assign/binAssign expressions in left-hand-sides of assign/binAssign expressions as well as taking the address of assign/binAssign expressions (e.g., required to return assign/binAssign expressions by reference).

import core.stdc.stdio;

ref int foo()
{
    static int a;
    return ++a *= 5;
}

void main()
{
    int a = foo();
    printf("%d\n", a);

    int b = 0;
    ((++b *= 5) *= 2) += 3;
    printf("%d\n", b);

    b = 0;
    ((++b *= 5) *= 2) += ++b * b;
    printf("%d\n", b);

    b = 0;
    ((++b *= 5) *= 2) += ++b * (b -= 6);
    printf("%d\n", b);

    b = 0;
    (((b = 1) *= 5) *= 2) = b - 1;
    printf("%d\n", b);
}

yields

5
13
131
65
9

@kinke kinke mentioned this pull request Mar 27, 2015
@kinke kinke changed the title Attempt to partially fix binary assignment operators Descend to nested lvalue for assign, binAssign and address-of expressions. Mar 28, 2015
…ions.

Thereby enabling nested assign/binAssign expressions in left-hand-sides
of assign/binAssign expressions as well as taking the address of assign/
binAssign expressions.
redstar added a commit that referenced this pull request Mar 28, 2015
Descend to nested lvalue for assign, binAssign and address-of expressions.
@redstar redstar merged commit 9967b86 into ldc-developers:merge-2.067 Mar 28, 2015
@kinke
Copy link
Member Author

kinke commented Mar 28, 2015

This 2.067 front-end change has a nice effect:

  • Above foo() function - LDC2 0.15.2:
define i32* @_D4incr3fooFNcZi() #0 {
  %__assignop1 = alloca i32*, align 8
  %1 = load i32* @_D4incr3fooFNcZ1ai
  %2 = add i32 %1, 1
  store i32 %2, i32* @_D4incr3fooFNcZ1ai
  store i32* @_D4incr3fooFNcZ1ai, i32** %__assignop1
  %3 = load i32** %__assignop1
  %4 = load i32* %3
  %5 = mul i32 %4, 5
  store i32 %5, i32* %3
  %6 = load i32** %__assignop1
  ret i32* %6
}

master:

define i32* @_D4incr3fooFNcZi() #0 {
  %1 = load i32* @_D4incr3fooFNcZ1ai
  %2 = add i32 %1, 1
  store i32 %2, i32* @_D4incr3fooFNcZ1ai
  %3 = mul i32 %2, 5
  store i32 %3, i32* @_D4incr3fooFNcZ1ai
  ret i32* @_D4incr3fooFNcZ1ai
}
  • First b test - 0.15.2:
  %__assignop3 = alloca i32*, align 8
  %__assignop2 = alloca i32*, align 8
  ...
  store i32 0, i32* %b
  %4 = load i32* %b
  %5 = load i32* %b
  %6 = add i32 %5, 1
  store i32 %6, i32* %b
  store i32* %b, i32** %__assignop2
  %7 = load i32** %__assignop2
  %8 = load i32* %7
  %9 = mul i32 %8, 5
  store i32 %9, i32* %7
  %10 = load i32** %__assignop2
  store i32* %10, i32** %__assignop3
  %11 = load i32** %__assignop3
  %12 = load i32* %11
  %13 = mul i32 %12, 2
  store i32 %13, i32* %11
  %14 = load i32** %__assignop3
  %15 = load i32* %14
  %16 = add i32 %15, 3
  store i32 %16, i32* %14

master:

  store i32 0, i32* %b
  %4 = load i32* %b
  %5 = load i32* %b
  %6 = add i32 %5, 1
  store i32 %6, i32* %b
  %7 = mul i32 %6, 5
  store i32 %7, i32* %b
  %8 = mul i32 %7, 2
  store i32 %8, i32* %b
  %9 = add i32 %8, 3
  store i32 %9, i32* %b
  %10 = load i32* %b

@kinke kinke deleted the 2.067 branch August 24, 2017 19:42
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.

None yet

2 participants