Skip to content

[InstCombine] Failure to convert vector fp comparisons that can be represented as integers #82241

Closed
@RKSimon

Description

@RKSimon

https://rust.godbolt.org/z/dfWjnToef

We will simplify a comparison of scalar floats that can be represented as integers to compare the integers directly, but we don't do this for vectors:

define i32 @cmpf(i32 %x) {
  %and = and i32 %x, 3
  %conv = sitofp i32 %and to float
  %cmp = fcmp oeq float %conv, 3.000000e+00
  %sext = sext i1 %cmp to i32
  ret i32 %sext
}

define <8 x i32> @vcmpf(<8 x i32> %x) {
  %and = and <8 x i32> %x, <i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3>
  %conv = sitofp <8 x i32> %and to <8 x float>
  %cmp = fcmp oeq <8 x float> %conv, <float 3.000000e+00, float 3.000000e+00, float 3.000000e+00, float 3.000000e+00, float 3.000000e+00, float 3.000000e+00, float 3.000000e+00, float 3.000000e+00>
  %sext = sext <8 x i1> %cmp to <8 x i32>
  ret <8 x i32> %sext
}

opt -O3

define i32 @cmpf(i32 %x) {
  %and = and i32 %x, 3
  %cmp = icmp eq i32 %and, 3
  %sext = sext i1 %cmp to i32
  ret i32 %sext
}

define <8 x i32> @vcmpf(<8 x i32> %x) {
  %and = and <8 x i32> %x, <i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3>
  %conv = sitofp <8 x i32> %and to <8 x float>
  %cmp = fcmp oeq <8 x float> %conv, <float 3.000000e+00, float 3.000000e+00, float 3.000000e+00, float 3.000000e+00, float 3.000000e+00, float 3.000000e+00, float 3.000000e+00, float 3.000000e+00>
  %sext = sext <8 x i1> %cmp to <8 x i32>
  ret <8 x i32> %sext
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions