[llvm-branch-commits] [llvm] InstCombine: Implement SimplifyDemandedFPClass for frexp (PR #176122)
Yingwei Zheng via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Jan 15 08:10:45 PST 2026
================
@@ -2941,6 +2941,55 @@ Value *InstCombinerImpl::SimplifyDemandedUseFPClass(Instruction *I,
Known = KnownLHS | KnownRHS;
break;
}
+ case Instruction::ExtractValue: {
+ ExtractValueInst *Extract = cast<ExtractValueInst>(I);
+ ArrayRef<unsigned> Indices = Extract->getIndices();
+ Value *Src = Extract->getAggregateOperand();
+ if (isa<StructType>(Src->getType()) && Indices.size() == 1 &&
+ Indices[0] == 0) {
+ if (auto *II = dyn_cast<IntrinsicInst>(Src)) {
+ switch (II->getIntrinsicID()) {
+ case Intrinsic::frexp: {
+ FPClassTest SrcDemandedMask = fcNone;
+ if (DemandedMask & fcNan)
+ SrcDemandedMask |= fcNan;
+ if (DemandedMask & fcNegFinite)
+ SrcDemandedMask |= fcNegFinite;
+ if (DemandedMask & fcPosFinite)
+ SrcDemandedMask |= fcPosFinite;
+ if (DemandedMask & fcPosInf)
+ SrcDemandedMask |= fcPosInf;
+ if (DemandedMask & fcNegInf)
+ SrcDemandedMask |= fcNegInf;
+
+ KnownFPClass KnownSrc;
+ if (SimplifyDemandedFPClass(II, 0, SrcDemandedMask, KnownSrc,
----------------
dtcxzyw wrote:
The latter one. Alive2: https://alive2.llvm.org/ce/z/y2ibWd
```
Transformation doesn't verify!
ERROR: Mismatch in memory
Example:
i1 %cond = #x0 (0)
half %unknown = #x7c21 (SNaN)
ptr %ptr = pointer(non-local, block_id=1, offset=0) / Address=#x08
Source:
half %select = #x7c00 (+oo)
{half, i16, i32} %frexp = { #x7c00 (+oo), poison, #x00000003 (3) }
half %frexp.mant = #x7c00 (+oo)
half %frexp.mant2 = #x7c00 (+oo)
SOURCE MEMORY STATE
===================
NON-LOCAL BLOCKS:
Block 0 > size: 0 align: 2 alloc type: 0 alive: false address: #x00
Block 1 > size: 5 align: 1 alloc type: 0 alive: true address: #x08
Contents:
*: #x0000
Target:
{half, i16, i32} %frexp = { #x7c21 (SNaN), poison, #x00000003 (3) }
half %frexp.mant = #x7c21 (SNaN)
half %frexp.mant2 = #x7c21 (SNaN)
TARGET MEMORY STATE
===================
NON-LOCAL BLOCKS:
Block 0 > size: 0 align: 2 alloc type: 0 alive: false address: #x00
Block 1 > size: 5 align: 1 alloc type: 0 alive: true address: #x08
Contents:
*: #x0000
Mismatch in pointer(non-local, block_id=1, offset=0)
Source value: #x7c00
Target value: #x7c21
```
The counterexample provided by Alive2 is not good enough (the return value of src is poison).
https://github.com/llvm/llvm-project/pull/176122
More information about the llvm-branch-commits
mailing list