[llvm] [ConstantFolding] Consolidate poison propagation for intrinsics (PR #146878)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 3 07:25:20 PDT 2025
================
@@ -7879,6 +7879,47 @@ bool llvm::isGuaranteedToExecuteForEveryIteration(const Instruction *I,
llvm_unreachable("Instruction not contained in its own parent basic block.");
}
+bool llvm::intrinsicPropagatesPoison(Intrinsic::ID IID) {
+ switch (IID) {
+ // TODO: Add more intrinsics.
+ case Intrinsic::sadd_with_overflow:
+ case Intrinsic::ssub_with_overflow:
+ case Intrinsic::smul_with_overflow:
+ case Intrinsic::uadd_with_overflow:
+ case Intrinsic::usub_with_overflow:
+ case Intrinsic::umul_with_overflow:
+ // If an input is a vector containing a poison element, the
+ // two output vectors (calculated results, overflow bits)'
+ // corresponding lanes are poison.
+ return true;
+ case Intrinsic::ctpop:
+ case Intrinsic::ctlz:
+ case Intrinsic::cttz:
+ case Intrinsic::abs:
+ case Intrinsic::smax:
+ case Intrinsic::smin:
+ case Intrinsic::umax:
+ case Intrinsic::umin:
+ case Intrinsic::scmp:
+ case Intrinsic::ucmp:
+ case Intrinsic::bitreverse:
+ case Intrinsic::bswap:
+ case Intrinsic::sadd_sat:
+ case Intrinsic::ssub_sat:
+ case Intrinsic::sshl_sat:
+ case Intrinsic::uadd_sat:
+ case Intrinsic::usub_sat:
+ case Intrinsic::ushl_sat:
+ case Intrinsic::smul_fix:
+ case Intrinsic::smul_fix_sat:
+ case Intrinsic::canonicalize:
+ case Intrinsic::sqrt:
----------------
nikic wrote:
Consolidating the frexp case is more complicated due to the struct return. I think it needs some refactorings to ConstantFoldStructCall first.
https://github.com/llvm/llvm-project/pull/146878
More information about the llvm-commits
mailing list