Skip to content

[Middle-end] Moving truncate before right-shift #45579

@LebedevRI

Description

@LebedevRI
Bugzilla Link 46234
Version trunk
OS Linux
CC @RKSimon,@nikic,@rotateright

Extended Description

int src(long int num) {
num &= 0xFFFFFFF;
return num >> 2;
}
int tgt(long int num) {
return (((unsigned int)num) << 4) >> 6;
}


define i32 @​src(i64 %0) {
%1:
%2 = lshr i64 %0, 2
%3 = trunc i64 %2 to i32
%4 = and i32 %3, 67108863
ret i32 %4
}
=>
define i32 @​tgt(i64 %0) {
%1:
%2 = trunc i64 %0 to i32
%3 = lshr i32 %2, 2
%4 = and i32 %3, 67108863
ret i32 %4
}
Transformation seems to be correct!

https://godbolt.org/z/V7xRAy
^ we do that in backend, but not middle-end.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions