diff options
author | Nikita Popov <npopov@redhat.com> | 2022-05-10 16:34:11 +0200 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2022-05-16 10:37:26 +0200 |
commit | 7ba484660b74d5b9d0b342a45cdb0ce8fd5b04bb (patch) | |
tree | 52f275ee6bbfc664088d04681d3f5952faf07e11 /llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp | |
parent | 3d2e05d542e646891745c5278a09950d3c4fb4a5 (diff) | |
download | llvm-7ba484660b74d5b9d0b342a45cdb0ce8fd5b04bb.zip llvm-7ba484660b74d5b9d0b342a45cdb0ce8fd5b04bb.tar.gz llvm-7ba484660b74d5b9d0b342a45cdb0ce8fd5b04bb.tar.bz2 |
[ControlHeightReduction] Freeze condition when converting select to branch
While select conditions can be poison, branch on poison is
immediate UB. As such, we need to freeze the condition when
converting a select into a branch.
Differential Revision: https://reviews.llvm.org/D125398
Diffstat (limited to 'llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp')
-rw-r--r-- | llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp b/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp index 6ee0468..2d1b762 100644 --- a/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp +++ b/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp @@ -1974,6 +1974,13 @@ void CHR::addToMergedCondition(bool IsTrueBiased, Value *Cond, Cond = IRB.CreateXor(ConstantInt::getTrue(F.getContext()), Cond); } + // Select conditions can be poison, while branching on poison is immediate + // undefined behavior. As such, we need to freeze potentially poisonous + // conditions derived from selects. + if (isa<SelectInst>(BranchOrSelect) && + !isGuaranteedNotToBeUndefOrPoison(Cond)) + Cond = IRB.CreateFreeze(Cond); + MergedCondition = IRB.CreateAnd(MergedCondition, Cond); } |