The or operation can be represented as an add instruction.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/lib/Transforms/Scalar/ConstraintElimination.cpp | ||
---|---|---|
357 | You're looking for haveNoCommonBitsSet(). |
llvm/lib/Transforms/Scalar/ConstraintElimination.cpp | ||
---|---|---|
357 | I tried the following snippet if (match(V, m_Or(m_Value(Op0), m_ConstantInt(CI)))) { if (haveNoCommonBitsSet(Op0, CI, DL)) return MergeResults(Op0, CI, IsSigned); } it works for most of the cases but for the following test define void @test.not.uge.ule %start.4 = or i8 %start, 4 %t.4 = icmp ule i8 %start.4, %high call void @use(i1 %t.4) %t.4 is not replaced with true |
llvm/lib/Transforms/Scalar/ConstraintElimination.cpp | ||
---|---|---|
357 | Isn't that the expected behavior? It's the same with your current patch. |
llvm/lib/Transforms/Scalar/ConstraintElimination.cpp | ||
---|---|---|
359 | Is it more useful to have an add than an or? |
llvm/lib/Transforms/Scalar/ConstraintElimination.cpp | ||
---|---|---|
359 | For this pass, yes, as it only handles adds. If this was a more generic question: We currently canonicalize add -> or if no common bits, and then undo that in various places. It's hard to say whether switching to the reverse direction or -> add would be more beneficial. We have both many or folds and many add folds. I've never tried it, though I did wonder about it in the past. |
llvm/test/Transforms/ConstraintElimination/or.ll | ||
---|---|---|
534–535 | This transformation should be true hasNoCommonBits doesn't optimise it while the original implementation did | |
610–611 | this check should be false |
llvm/lib/Transforms/Scalar/ConstraintElimination.cpp | ||
---|---|---|
373 | Could you add a comment indicating what this code does, i.e. treat or as an Add if no common bits are set? | |
374 | nit: merge with previous if | |
llvm/test/Transforms/ConstraintElimination/or.ll | ||
534–535 | It's fine if the current version doesn't catch all possible cases we could optimize. Further improvements can be landed as follow-ups |
- Add comment to explain that the operation is being treated as an add
- Address nit comments
You're looking for haveNoCommonBitsSet().