Skip to content

redundant mask op could be eliminated #38926

@rotateright

Description

@rotateright
Bugzilla Link 39578
Version trunk
OS All
CC @hfinkel,@RKSimon

Extended Description

Forking this off from bug 29009:

define void @​redundant_mask(i32 %x, i32* %st1, i8* %st2) {
%and1 = and i32 %x, 7
store i32 %and1, i32* %st1
%conv = trunc i32 %x to i8
%and2 = and i8 %conv, 7
store i8 %and2, i8* %st2
ret void
}

We (GVN?) should be able to recognize that the 2nd 'and' can be removed to reduce the IR:

define void @​no_redundant_mask(i32 %x, i32* %st1, i8* %st2) {
%and1 = and i32 %x, 7
store i32 %and1, i32* %st1
%conv2 = trunc i32 %and1 to i8
store i8 %conv2, i8* %st2
ret void
}

%and1 = and i32 %x, 7
store i32 %and1, i32* %p
%conv = trunc i32 %x to i8
%r = and i8 %conv, 7
=>
%and1 = and i32 %x, 7
store i32 %and1, i32* %p
%r = trunc i32 %and1 to i8

https://rise4fun.com/Alive/JGb

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