diff options
| author | Simon Pilgrim <llvm-dev@redking.me.uk> | 2022-01-10 17:03:43 +0000 |
|---|---|---|
| committer | Simon Pilgrim <llvm-dev@redking.me.uk> | 2022-01-10 17:04:03 +0000 |
| commit | fd1094f318971e4aaa1c6b836ba93e757c8b913a (patch) | |
| tree | 8760ce9855ad23dd268732e0638bfedf2858a445 | |
| parent | cf90b3cf7e467db9052a2fd392faa68ef2f175d8 (diff) | |
| download | llvm-fd1094f318971e4aaa1c6b836ba93e757c8b913a.zip llvm-fd1094f318971e4aaa1c6b836ba93e757c8b913a.tar.gz llvm-fd1094f318971e4aaa1c6b836ba93e757c8b913a.tar.bz2 | |
[ConstantFolding] Clean up Intrinsics::abs undef handling
Match cttz/ctlz handling by assuming C1 == 0 if C1 != 1 - I've added an assertion as well.
Fixes static analyzer nullptr dereference warnings.
| -rw-r--r-- | llvm/lib/Analysis/ConstantFolding.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index d25694b..103992d 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -2572,13 +2572,15 @@ static Constant *ConstantFoldScalarCall2(StringRef Name, return ConstantInt::get(Ty, C0->countLeadingZeros()); case Intrinsic::abs: - // Undef or minimum val operand with poison min --> undef assert(C1 && "Must be constant int"); + assert((C1->isOne() || C1->isZero()) && "Must be 0 or 1"); + + // Undef or minimum val operand with poison min --> undef if (C1->isOne() && (!C0 || C0->isMinSignedValue())) return UndefValue::get(Ty); // Undef operand with no poison min --> 0 (sign bit must be clear) - if (C1->isZero() && !C0) + if (!C0) return Constant::getNullValue(Ty); return ConstantInt::get(Ty, C0->abs()); |
