Skip to content

InstCombine should fold ldexp(x, zext(i1 y)) to fmul x, (select y, 2.0, 1.0) #92538

Closed
@arsenm

Description

@arsenm
define float @src(float %x, i1 %bool) {
  %zext = zext i1 %bool to i32
  %ldexp = call float @llvm.ldexp.f32.i32(float %x, i32 %zext)
  ret float %ldexp
}

define float @tgt(float %x, i1 %bool) {
  %select = select i1 %bool, float 2.000000e+00, float 1.000000e+00
  %mul = fmul float %x, %select
  ret float %mul
}

I noticed the pattern while looking at builtin math library code

Metadata

Metadata

Assignees

Labels

floating-pointFloating-point mathgood first issuehttps://github.com/llvm/llvm-project/contributellvm:instcombineCovers the InstCombine, InstSimplify and AggressiveInstCombine passesmissed-optimization

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions