Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
7 changes: 6 additions & 1 deletion llvm/lib/Analysis/ConstantFolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2206,8 +2206,13 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,

if (isa<PoisonValue>(Operands[0])) {
// TODO: All of these operations should probably propagate poison.
if (IntrinsicID == Intrinsic::canonicalize)
switch (IntrinsicID) {
case Intrinsic::canonicalize:
case Intrinsic::sqrt:
return PoisonValue::get(Ty);
default:
break;
}
}

if (isa<UndefValue>(Operands[0])) {
Expand Down
42 changes: 42 additions & 0 deletions llvm/test/Transforms/InstSimplify/fp-undef-poison.ll
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,45 @@ define double @fmul_nnan_inf_op1(double %x) {
%r = fmul nnan double %x, 0xfff0000000000000
ret double %r
}

define float @sqrt_poison() {
; CHECK-LABEL: @sqrt_poison(
; CHECK-NEXT: ret float poison
;
%sqrt = call float @llvm.sqrt(float poison)
ret float %sqrt
}

define <2 x float> @sqrt_poison_fixed_vec() {
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a case with <float 1.0, float poison>?

; CHECK-LABEL: @sqrt_poison_fixed_vec(
; CHECK-NEXT: ret <2 x float> poison
;
%sqrt = call <2 x float> @llvm.sqrt(<2 x float> poison)
ret <2 x float> %sqrt
}

define <vscale x 2 x float> @sqrt_poison_scalable_vec() {
; CHECK-LABEL: @sqrt_poison_scalable_vec(
; CHECK-NEXT: ret <vscale x 2 x float> poison
;
%sqrt = call <vscale x 2 x float> @llvm.sqrt(<vscale x 2 x float> poison)
ret <vscale x 2 x float> %sqrt
}

define float @sqrt_nnan_nan() {
; CHECK-LABEL: @sqrt_nnan_nan(
; CHECK-NEXT: [[SQRT:%.*]] = call nnan float @llvm.sqrt.f32(float 0x7FF8000000000000)
; CHECK-NEXT: ret float [[SQRT]]
;
%sqrt = call nnan float @llvm.sqrt(float 0x7ff8000000000000)
ret float %sqrt
}

define float @sqrt_ninf_inf() {
; CHECK-LABEL: @sqrt_ninf_inf(
; CHECK-NEXT: [[SQRT:%.*]] = call ninf float @llvm.sqrt.f32(float 0xFFF0000000000000)
; CHECK-NEXT: ret float [[SQRT]]
;
%sqrt = call ninf float @llvm.sqrt(float 0xfff0000000000000)
ret float %sqrt
}