aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Pilgrim <llvm-dev@redking.me.uk>2022-01-10 17:03:43 +0000
committerSimon Pilgrim <llvm-dev@redking.me.uk>2022-01-10 17:04:03 +0000
commitfd1094f318971e4aaa1c6b836ba93e757c8b913a (patch)
tree8760ce9855ad23dd268732e0638bfedf2858a445
parentcf90b3cf7e467db9052a2fd392faa68ef2f175d8 (diff)
downloadllvm-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.cpp6
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());