aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2022-04-18 15:03:10 -0400
committerSanjay Patel <spatel@rotateright.com>2022-04-18 15:14:02 -0400
commit3a27b51b2751dba1b3fbef68d647833ab65aa45b (patch)
tree1d07590996a775e57542f5f555a5def6be8c8451 /llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
parent60de144119abc5848d4fae2f502e05ffae90a970 (diff)
downloadllvm-3a27b51b2751dba1b3fbef68d647833ab65aa45b.zip
llvm-3a27b51b2751dba1b3fbef68d647833ab65aa45b.tar.gz
llvm-3a27b51b2751dba1b3fbef68d647833ab65aa45b.tar.bz2
[InstCombine] reduce code for freeze of undef
The description was ambiguous about the behavior when boths select arms are constant or both arms are not constant. I don't think there's any evidence to support either way, but this matches the code with a more specified description. We can extend this to deal with vector constants with undef/poison elements. Currently, those don't get folded anywhere.
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstructionCombining.cpp')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstructionCombining.cpp17
1 files changed, 7 insertions, 10 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index b9957a9..b1f2e8b 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -3779,23 +3779,20 @@ Instruction *InstCombinerImpl::visitFreeze(FreezeInst &I) {
return replaceInstUsesWith(I, NI);
if (match(Op0, m_Undef())) {
- // If I is freeze(undef), see its uses and fold it to the best constant.
+ // If I is freeze(undef), check its uses and fold it to a fixed constant.
// - or: pick -1
- // - select's condition: pick the value that leads to choosing a constant
- // - other ops: pick 0
+ // - select's condition: if the true value is constant, choose it by making
+ // the condition true.
+ // - default: pick 0
Constant *BestValue = nullptr;
Constant *NullValue = Constant::getNullValue(I.getType());
for (const auto *U : I.users()) {
Constant *C = NullValue;
if (match(U, m_Or(m_Value(), m_Value())))
- C = Constant::getAllOnesValue(I.getType());
- else if (const auto *SI = dyn_cast<SelectInst>(U)) {
- if (SI->getCondition() == &I) {
- APInt CondVal(1, isa<Constant>(SI->getFalseValue()) ? 0 : 1);
- C = Constant::getIntegerValue(I.getType(), CondVal);
- }
- }
+ C = ConstantInt::getAllOnesValue(I.getType());
+ else if (match(U, m_Select(m_Specific(&I), m_Constant(), m_Value())))
+ C = ConstantInt::getTrue(I.getType());
if (!BestValue)
BestValue = C;