Fix #56795
Details
Diff Detail
Unit Tests
Time | Test | |
---|---|---|
60,040 ms | x64 debian > libFuzzer.libFuzzer::minimize_crash.test |
Event Timeline
There's a question of where this kind of transform belongs - CVP, SCCP?
This seems fine to me, but it should probably be split off into a helper function. We could do the same for srem/urem? sdiv/udiv with a slight adjustment? any other opcodes?
llvm/test/Transforms/InstSimplify/domcondition.ll | ||
---|---|---|
37 | Something went wrong - this should not simplify? | |
69 | xor -> sub? |
I guess if one of the compare value is constant, it should be IPSCCP. If both of them are not constant, it should be CVP.
This seems fine to me, but it should probably be split off into a helper function. We could do the same for srem/urem? sdiv/udiv with a slight adjustment? any other opcodes?
Yeah, you are right. div/rem should work also.
llvm/test/Transforms/InstSimplify/domcondition.ll | ||
---|---|---|
37 | Yeah, this is a negative test. The condition is icmp ne. |
llvm/lib/Analysis/InstructionSimplify.cpp | ||
---|---|---|
762 | I'm a little worry about the and/or part. Recursive call to isImpliedByDomCondition looks a little heavy. |
llvm/lib/Analysis/InstructionSimplify.cpp | ||
---|---|---|
744–745 | Put a descriptive comment on this function like: /// Test if there is a dominating equivalence condition for the /// two operands. If there is, try to reduce the binary operation /// between the two operands. /// Example: Op0 - Op1 --> 0 when Op0 == Op1 | |
762 | Did you run any compile-time-tracker experiments? | |
902–903 | If there's a good block comment for the new function, comments like this at the callers are probably not needed. | |
llvm/test/Transforms/InstSimplify/domcondition.ll | ||
20 | The mul in these tests could be removed? It would be better to still have at least one negative test. We want to make sure the implication is not inverted somehow. Go ahead and pre-commit the baseline tests, so we just show diffs in this patch. |
llvm/lib/Analysis/InstructionSimplify.cpp | ||
---|---|---|
762 | Sure - I created a branch from current main and applied this patch to it: There seems to be a slight increase in time, but it could also be in the noise. If you want to compare vs. a CVP solution, I think it would be interesting to know the result. |
llvm/lib/Analysis/InstructionSimplify.cpp | ||
---|---|---|
762 | Sorry - after re-reading the comment, I realize I didn't run the experiment that was requested. I'll add and/or in another commit. |
llvm/lib/Analysis/InstructionSimplify.cpp | ||
---|---|---|
762 | https://llvm-compile-time-tracker.com/?config=NewPM-O3&stat=instructions%3Au&remote=rotateright So there does seem to be a noticeable cost to handling more instructions. This again suggests we might do better by creating a CVP patch. |
llvm/lib/Analysis/InstructionSimplify.cpp | ||
---|---|---|
762 | It looks the if we don't propagate and/or the compile time is acceptable. |
llvm/lib/Analysis/InstructionSimplify.cpp | ||
---|---|---|
762 | Another headache thing I find here is the pass sequence. SimplifyCFGPass will convert the test case to select at very early time. Even if we add the similar code into CVP it still can't detect the select. |
I made a small adjustment to pass the MaxRecurse through to div/rem as well.
There doesn't appear to be any real cost even if we include and/or in the opcodes now:
https://llvm-compile-time-tracker.com/compare.php?from=27b861a1fd271459e8109418f79293732770bc04&to=7b84f6922df17d6609cffa5c6d6d7ea2083341b8&stat=instructions:u
See the pair of commits ending with:
https://github.com/llvm/llvm-project/commit/7b84f6922df17d6609cffa5c6d6d7ea2083341b8
So how do you think the patch now? Do we need to add and/or in this patch? Or do we need to find a way to work on CVP/SCCP?
This looks almost good to me now - I would just make the change to MaxRecurse that I tried. That makes the behavior consistent for all opcodes. I think we should handle ‘and’ and ‘or’ for completeness since it doesn’t seem to have any extra cost. If you want to leave it as a TODO in this patch, that is ok.
Note:
This pattern will be triggered in
SpecCPU2017\benchspec\CPU\502.gcc_r\src\tree-ssa-alias.c
SpecCPU2017\benchspec\CPU\510.parest_r\src\source\lac\block_sparse_matrix.cc
SpecCPU2017\benchspec\CPU\538.imagick_r\src\magick\property.c
Put a descriptive comment on this function like: