Skip to content

[InstCombine] Select gt/lt with constant predicates not canonicalized #43866

@nikic

Description

@nikic
Bugzilla Link 44521
Version trunk
OS All
CC @LebedevRI,@rotateright

Extended Description

The following stay invariant under -instcombine:

define i8 @​sign_select_scalar_sgt(i8 %cond, i8 %tval, i8 %fval) {
%cmp = icmp sgt i8 %cond, -1
%res = select i1 %cmp, i8 %fval, i8 %tval
ret i8 %res
}
define i8 @​sign_select_scalar_slt(i8 %cond, i8 %tval, i8 %fval) {
%cmp = icmp slt i8 %cond, 0
%res = select i1 %cmp, i8 %tval, i8 %fval
ret i8 %res
}
define <4 x i8> @​sign_select_vec_sgt(<4 x i8> %cond, <4 x i8> %tval, <4 x i8> %fval) {
%cmp = icmp sgt <4 x i8> %cond, <i8 -1, i8 -1, i8 -1, i8 -1>
%res = select <4 x i1> %cmp, <4 x i8> %fval, <4 x i8> %tval
ret <4 x i8> %res
}
define <4 x i8> @​sign_select_vec_slt(<4 x i8> %cond, <4 x i8> %tval, <4 x i8> %fval) {
%cmp = icmp slt <4 x i8> %cond, zeroinitializer
%res = select <4 x i1> %cmp, <4 x i8> %tval, <4 x i8> %fval
ret <4 x i8> %res
}

I would expect that this gets canonicalized one way or another (<0 probably).

Noticed this when some InstCombine worklist order changes resulted in the above patterns getting flipped in places.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillallvm:instcombineCovers the InstCombine, InstSimplify and AggressiveInstCombine passes

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions