When fcmp true / fcmp false is used in and / or branching condition, llc crashes with error Unknown FP condition! for AArch64 when using GlobalISel.
Cause
The direct cause of the problem is that AArch64GISelUtils::changeFCMPPredToAArch64CC does not map predicates CmpInst::FCMP_TRUE and CmpInst::FCMP_FALSE to some AArch64CC::CondCode.
The root cause is that the developers might have assumed that fcmp true and fcmp false will be translated to an G_CONSTANT i1 in Generic MIR by IRTranslator before Instruction Selection. Such an assumption is true in most situations due to the special handling of CmpInst::FCMP_TRUE and CmpInst::FCMP_FALSE in IRTranslator::translateCompare. However, when such instruction is used in an and / or branching condition, IRTranslator::emitSwitchCase called by IRTranslator::translateBr will emit G_FCMP floatpred(false) instruction to Generic MIR here, thus failing the assumption.
Description
When
fcmp true
/fcmp false
is used inand
/or
branching condition,llc
crashes with errorUnknown FP condition!
for AArch64 when using GlobalISel.Cause
The direct cause of the problem is that
AArch64GISelUtils::changeFCMPPredToAArch64CC
does not map predicatesCmpInst::FCMP_TRUE
andCmpInst::FCMP_FALSE
to someAArch64CC::CondCode
.The root cause is that the developers might have assumed that
fcmp true
andfcmp false
will be translated to anG_CONSTANT i1
in Generic MIR byIRTranslator
before Instruction Selection. Such an assumption is true in most situations due to the special handling ofCmpInst::FCMP_TRUE
andCmpInst::FCMP_FALSE
inIRTranslator::translateCompare
. However, when such instruction is used in anand
/or
branching condition,IRTranslator::emitSwitchCase
called byIRTranslator::translateBr
will emitG_FCMP floatpred(false)
instruction to Generic MIR here, thus failing the assumption.Minimal Reproduction
https://godbolt.org/z/MMcG6fxer
Code
Stack Trace