(X || Y) ? false : X --> false
https://alive2.llvm.org/ce/z/y93yUm
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
These two patterns are really simple so I merge them into one patch. If any of you think split them is better I will send another patch for the new pattern.
Note:
!(X || Y) && Y --> false
can be trigged on SpecCPU2017\benchspec\CPU\502.gcc_r\src\insn-attrtab.c
There are quite a few variations within these patterns, so I prefer to split it up.
Please pre-commit baseline tests and see my comment in D138744. Also, should we prefer the code placement/structure that is proposed in that patch?
I prefer to keep current position. Because
- These two patterns I add is very similar. Put them together looks better.
- They can share m_LogicalOr match. D138744 miss logical or also. We can't put the code on there because BO is not BinaryOperator when it is a logical or.
There's still a lot of possibilities even with these 2 patterns, so I'd prefer to split it up again. We are missing some necessary tests.
llvm/lib/Analysis/InstructionSimplify.cpp | ||
---|---|---|
4565 | This comment is not the same as the pattern that is matched. | |
llvm/test/Transforms/InstSimplify/select-logical.ll | ||
204–205 | Shouldn't there be a test like this (or the first test) with a bitwise 'or'? | |
219–220 | We need a test similar to this, but with poison elements. | |
329 | This is a miscompile: |
llvm/test/Transforms/InstSimplify/select-logical.ll | ||
---|---|---|
219–220 | @logical_not_or_and_vector1_poison should be the test you mentioned. |
llvm/test/Transforms/InstSimplify/select-logical.ll | ||
---|---|---|
292 | Here and below - the usual notation for a select op if we are writing it like C code would be: | |
303 | update comment to match test: | |
327 | We can transform this, but it must not propagate the poison: So it should be ok to leave the match with m_ZeroInt(), but instead of returning the existing TrueVal, return a "full" false constant: ConstantInt::getFalse(Cond->getType()) |
LGTM - see inline for code suggestion.
llvm/lib/Analysis/InstructionSimplify.cpp | ||
---|---|---|
4564 | Use m_c_LogicalOr() and m_Specific() to make the code shorter. We do not need to capture X/Y: if (match(Cond, m_c_LogicalOr(m_Specific(FalseVal), m_Value())) && match(TrueVal, m_ZeroInt())) return ConstantInt::getFalse(Cond->getType()); |
Use m_c_LogicalOr() and m_Specific() to make the code shorter. We do not need to capture X/Y: