Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2618,6 +2618,16 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
}
}

// ldexp(x, zext(i1 y)) -> fmul x, (select y, 2.0, 1.0)
Value *ExtSrc;
if (match(Exp, m_ZExt(m_Value(ExtSrc))) &&
ExtSrc->getType()->getScalarSizeInBits() == 1) {
Value *Select =
Builder.CreateSelect(ExtSrc, ConstantFP::get(II->getType(), 2.0),
ConstantFP::get(II->getType(), 1.0));
return BinaryOperator::CreateFMulFMF(Src, Select, II);
}

break;
}
case Intrinsic::ptrauth_auth:
Expand Down
57 changes: 57 additions & 0 deletions llvm/test/Transforms/InstCombine/ldexp-zext.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -passes=instcombine -S | FileCheck %s

define float @ldexp_zext_float(float %x, i1 %bool) {
; CHECK-LABEL: @ldexp_zext_float(
; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[BOOL:%.*]], float 2.000000e+00, float 1.000000e+00
; CHECK-NEXT: [[LDEXP:%.*]] = fmul float [[TMP1]], [[X:%.*]]
; CHECK-NEXT: ret float [[LDEXP]]
;
%zext = zext i1 %bool to i32
%ldexp = call float @llvm.ldexp.f32.i32(float %x, i32 %zext)
ret float %ldexp
}

define float @ldexp_zext_float_negative(float %x, i8 %y) {
; CHECK-LABEL: @ldexp_zext_float_negative(
; CHECK-NEXT: [[ZEXT:%.*]] = zext i8 [[Y:%.*]] to i32
; CHECK-NEXT: [[LDEXP:%.*]] = call float @llvm.ldexp.f32.i32(float [[X:%.*]], i32 [[ZEXT]])
; CHECK-NEXT: ret float [[LDEXP]]
;
%zext = zext i8 %y to i32
%ldexp = call float @llvm.ldexp.f32.i32(float %x, i32 %zext)
ret float %ldexp
}

define double @ldexp_zext_double(double %x, i1 %bool) {
; CHECK-LABEL: @ldexp_zext_double(
; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[BOOL:%.*]], double 2.000000e+00, double 1.000000e+00
; CHECK-NEXT: [[LDEXP:%.*]] = fmul double [[TMP1]], [[X:%.*]]
; CHECK-NEXT: ret double [[LDEXP]]
;
%zext = zext i1 %bool to i32
%ldexp = call double @llvm.ldexp.f32.i32(double %x, i32 %zext)
ret double %ldexp
}

define double @ldexp_zext_double_fast_math(double %x, i1 %bool) {
; CHECK-LABEL: @ldexp_zext_double_fast_math(
; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[BOOL:%.*]], double 2.000000e+00, double 1.000000e+00
; CHECK-NEXT: [[LDEXP:%.*]] = fmul fast double [[TMP1]], [[X:%.*]]
; CHECK-NEXT: ret double [[LDEXP]]
;
%zext = zext i1 %bool to i32
%ldexp = call fast double @llvm.ldexp.f32.i32(double %x, i32 %zext)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

ret double %ldexp
}

define <2 x float> @ldexp_zext_float_vector(<2 x float> %x, <2 x i1> %bool) {
; CHECK-LABEL: @ldexp_zext_float_vector(
; CHECK-NEXT: [[TMP1:%.*]] = select <2 x i1> [[BOOL:%.*]], <2 x float> <float 2.000000e+00, float 2.000000e+00>, <2 x float> <float 1.000000e+00, float 1.000000e+00>
; CHECK-NEXT: [[LDEXP:%.*]] = fmul <2 x float> [[TMP1]], [[X:%.*]]
; CHECK-NEXT: ret <2 x float> [[LDEXP]]
;
%zext = zext <2 x i1> %bool to <2 x i32>
%ldexp = call <2 x float> @llvm.ldexp.v2f32.v2i32(<2 x float> %x, <2 x i32> %zext)
ret <2 x float> %ldexp
}