diff options
| author | Juneyoung Lee <aqjune@gmail.com> | 2020-09-10 02:55:06 +0900 |
|---|---|---|
| committer | Juneyoung Lee <aqjune@gmail.com> | 2020-09-10 08:07:38 +0900 |
| commit | a6183d0f028cb73eccc82a7cce9534708a149762 (patch) | |
| tree | 14ba1231bb124c5cf3010ca7e7e139eb95a8b599 /llvm/lib | |
| parent | 09d492902f178f60b3ab986360eadde9b5c8d359 (diff) | |
| download | llvm-a6183d0f028cb73eccc82a7cce9534708a149762.zip llvm-a6183d0f028cb73eccc82a7cce9534708a149762.tar.gz llvm-a6183d0f028cb73eccc82a7cce9534708a149762.tar.bz2 | |
[ValueTracking] isKnownNonZero, computeKnownBits for freeze
This implements support for isKnownNonZero, computeKnownBits when freeze is involved.
```
br (x != 0), BB1, BB2
BB1:
y = freeze x
```
In the above program, we can say that y is non-zero. The reason is as follows:
(1) If x was poison, `br (x != 0)` raised UB
(2) If x was fully undef, the branch again raised UB
(3) If x was non-zero partially undef, say `undef | 1`, `freeze x` will return a nondeterministic value which is also non-zero.
(4) If x was just a concrete value, it is trivial
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D75808
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 469257d..1a89495 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -1872,6 +1872,10 @@ static void computeKnownBitsFromOperator(const Operator *I, } } break; + case Instruction::Freeze: + if (isGuaranteedNotToBePoison(I->getOperand(0), Q.CxtI, Q.DT, Depth + 1)) + computeKnownBits(I->getOperand(0), Known, Depth + 1, Q); + break; } } @@ -2577,6 +2581,13 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts, unsigned Depth, return isKnownNonZero(Vec, DemandedVecElts, Depth, Q); } } + // Freeze + else if (const FreezeInst *FI = dyn_cast<FreezeInst>(V)) { + auto *Op = FI->getOperand(0); + if (isKnownNonZero(Op, Depth, Q) && + isGuaranteedNotToBePoison(Op, Q.CxtI, Q.DT, Depth)) + return true; + } KnownBits Known(BitWidth); computeKnownBits(V, DemandedElts, Known, Depth, Q); |
