-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[ConstantFolding] Consolidate poison propagation for intrinsics #146878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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: | ||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
See llvm-project/llvm/lib/Analysis/ConstantFolding.cpp Lines 3915 to 3916 in 438863a
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consolidating the frexp case is more complicated due to the struct return. I think it needs some refactorings to ConstantFoldStructCall first. |
||||||||||||
| return true; | ||||||||||||
| default: | ||||||||||||
| return false; | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| bool llvm::propagatesPoison(const Use &PoisonOp) { | ||||||||||||
| const Operator *I = cast<Operator>(PoisonOp.getUser()); | ||||||||||||
| switch (I->getOpcode()) { | ||||||||||||
|
|
@@ -7889,38 +7930,8 @@ bool llvm::propagatesPoison(const Use &PoisonOp) { | |||||||||||
| case Instruction::Select: | ||||||||||||
| return PoisonOp.getOperandNo() == 0; | ||||||||||||
| case Instruction::Call: | ||||||||||||
| if (auto *II = dyn_cast<IntrinsicInst>(I)) { | ||||||||||||
| switch (II->getIntrinsicID()) { | ||||||||||||
| // 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::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: | ||||||||||||
| return true; | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| if (auto *II = dyn_cast<IntrinsicInst>(I)) | ||||||||||||
| return intrinsicPropagatesPoison(II->getIntrinsicID()); | ||||||||||||
| return false; | ||||||||||||
| case Instruction::ICmp: | ||||||||||||
| case Instruction::FCmp: | ||||||||||||
|
|
||||||||||||
Uh oh!
There was an error while loading. Please reload this page.