[llvm] fd1094f - [ConstantFolding] Clean up Intrinsics::abs undef handling
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 10 09:08:01 PST 2022
Author: Simon Pilgrim
Date: 2022-01-10T17:04:03Z
New Revision: fd1094f318971e4aaa1c6b836ba93e757c8b913a
URL: https://github.com/llvm/llvm-project/commit/fd1094f318971e4aaa1c6b836ba93e757c8b913a
DIFF: https://github.com/llvm/llvm-project/commit/fd1094f318971e4aaa1c6b836ba93e757c8b913a.diff
LOG: [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.
Added:
Modified:
llvm/lib/Analysis/ConstantFolding.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index d25694b0c0eda..103992de3dc08 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());
More information about the llvm-commits
mailing list