aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/Local.cpp
diff options
context:
space:
mode:
authorJay Foad <jay.foad@amd.com>2022-01-28 14:45:06 +0000
committerJay Foad <jay.foad@amd.com>2022-01-31 10:44:17 +0000
commita6b54ddaba2d5dc0f72dcc4591c92b9544eb0016 (patch)
treee451666814ffacc679f3bc3e9297c750051cc50b /llvm/lib/Transforms/Utils/Local.cpp
parent00bf4755e90c89963a135739218ef49c2417109f (diff)
downloadllvm-a6b54ddaba2d5dc0f72dcc4591c92b9544eb0016.zip
llvm-a6b54ddaba2d5dc0f72dcc4591c92b9544eb0016.tar.gz
llvm-a6b54ddaba2d5dc0f72dcc4591c92b9544eb0016.tar.bz2
[Local] invertCondition: try modifying an existing ICmpInst
This avoids various cases where StructurizeCFG would otherwise insert an xor i1 instruction, and it since it generally runs late in the pipeline, instcombine does not clean up the xor-of-cmp pattern. Differential Revision: https://reviews.llvm.org/D118478
Diffstat (limited to 'llvm/lib/Transforms/Utils/Local.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/Local.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index 9f33d2f..c457931 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -3343,6 +3343,14 @@ Value *llvm::invertCondition(Value *Condition) {
if (I->getParent() == Parent && match(I, m_Not(m_Specific(Condition))))
return I;
+ // Fourth: Modify an existing instruction
+ if (Condition->hasOneUse()) {
+ if (auto *CI = dyn_cast<CmpInst>(Condition)) {
+ CI->setPredicate(CI->getInversePredicate());
+ return Condition;
+ }
+ }
+
// Last option: Create a new instruction
auto *Inverted =
BinaryOperator::CreateNot(Condition, Condition->getName() + ".inv");