diff options
author | Craig Topper <craig.topper@sifive.com> | 2023-11-24 08:49:19 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-24 08:49:19 -0800 |
commit | d9962c400f970d17396e84c1a55cdbea29a7c893 (patch) | |
tree | 148b09a26214ed5534441c041ec7136372bfff34 /llvm/lib/Bitcode | |
parent | 5d501b1091ce3632b885c60a8fc9f74ed9c95ae3 (diff) | |
download | llvm-d9962c400f970d17396e84c1a55cdbea29a7c893.zip llvm-d9962c400f970d17396e84c1a55cdbea29a7c893.tar.gz llvm-d9962c400f970d17396e84c1a55cdbea29a7c893.tar.bz2 |
[IR] Add disjoint flag for Or instructions. (#72583)
This flag indicates that every bit is known to be zero in at least one
of the inputs. This allows the Or to be treated as an Add since there is
no possibility of a carry from any bit.
If the flag is present and this property does not hold, the result is
poison.
This makes it easier to reverse the InstCombine transform that turns Add
into Or.
This is inspired by a comment here
https://github.com/llvm/llvm-project/pull/71955#discussion_r1391614578
Discourse thread
https://discourse.llvm.org/t/rfc-add-or-disjoint-flag/75036
Diffstat (limited to 'llvm/lib/Bitcode')
-rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 3 |
2 files changed, 6 insertions, 1 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 788906a..e4c3770 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -4866,12 +4866,14 @@ Error BitcodeReader::parseFunctionBody(Function *F) { Opc == Instruction::AShr) { if (Record[OpNum] & (1 << bitc::PEO_EXACT)) cast<BinaryOperator>(I)->setIsExact(true); + } else if (Opc == Instruction::Or) { + if (Record[OpNum] & (1 << bitc::PDI_DISJOINT)) + cast<PossiblyDisjointInst>(I)->setIsDisjoint(true); } else if (isa<FPMathOperator>(I)) { FastMathFlags FMF = getDecodedFastMathFlags(Record[OpNum]); if (FMF.any()) I->setFastMathFlags(FMF); } - } break; } diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 9c21cc6..8239775 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -1540,6 +1540,9 @@ static uint64_t getOptimizationFlags(const Value *V) { } else if (const auto *PEO = dyn_cast<PossiblyExactOperator>(V)) { if (PEO->isExact()) Flags |= 1 << bitc::PEO_EXACT; + } else if (const auto *PDI = dyn_cast<PossiblyDisjointInst>(V)) { + if (PDI->isDisjoint()) + Flags |= 1 << bitc::PDI_DISJOINT; } else if (const auto *FPMO = dyn_cast<FPMathOperator>(V)) { if (FPMO->hasAllowReassoc()) Flags |= bitc::AllowReassoc; |