-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Closed
Labels
floating-pointFloating-point mathFloating-point mathllvm:instcombineCovers the InstCombine, InstSimplify and AggressiveInstCombine passesCovers the InstCombine, InstSimplify and AggressiveInstCombine passesmiscompilation
Description
llvm-project/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
Lines 559 to 568 in ae618d3
| Value *NewSel = Builder.CreateSelect(SI.getCondition(), Swapped ? C : OOp, | |
| Swapped ? OOp : C, "", &SI); | |
| if (isa<FPMathOperator>(&SI)) | |
| cast<Instruction>(NewSel)->setFastMathFlags(FMF); | |
| NewSel->takeName(TVI); | |
| BinaryOperator *BO = | |
| BinaryOperator::Create(TVI->getOpcode(), FalseVal, NewSel); | |
| BO->copyIRFlags(TVI); | |
| return BO; | |
| }; |
The compiler explorer's alive2 times out for this case.
But I post a proof that the optimization actually happens: https://alive2.llvm.org/ce/z/7MRSu5
This is the Alive2 report on my machine:
----------------------------------------
define float @fmul_by_self_if_0_oeq_zero_f32_fmul_nnan_ninf_nsz.2(float %x) {
#0:
%#1 = fcmp ule float %x, 0.000000
%scaled.x = fmul nnan ninf nsz float %x, %x
%scaled.if.denormal = select nnan i1 %#1, float %x, float %scaled.x
ret float %scaled.if.denormal
}
=>
define float @fmul_by_self_if_0_oeq_zero_f32_fmul_nnan_ninf_nsz.2(float %x) {
#0:
%#1 = fcmp ule float %x, 0.000000
%scaled.x = select nnan i1 %#1, float 1.000000, float %x
%scaled.if.denormal = fmul nnan ninf nsz float %scaled.x, %x
ret float %scaled.if.denormal
}
Transformation doesn't verify!
ERROR: Target is more poisonous than source
Example:
float %x = #xff800000 (-oo)
Source:
i1 %#1 = #x1 (1)
float %scaled.x = poison
float %scaled.if.denormal = #xff800000 (-oo)
Target:
i1 %#1 = #x1 (1)
float %scaled.x = #x3f800000 (1)
float %scaled.if.denormal = poison
Source value: #xff800000 (-oo)
Target value: poison
Summary:
0 correct transformations
1 incorrect transformations
0 failed-to-prove transformations
0 Alive2 errorsMetadata
Metadata
Assignees
Labels
floating-pointFloating-point mathFloating-point mathllvm:instcombineCovers the InstCombine, InstSimplify and AggressiveInstCombine passesCovers the InstCombine, InstSimplify and AggressiveInstCombine passesmiscompilation