This is safe as long as the udiv is not exact. The pattern is not common in
C++ code, but comes up all the time in code generated by XLA's GPU backend.
Details
Details
Diff Detail
Diff Detail
- Repository
- rL LLVM
Event Timeline
lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp | ||
---|---|---|
556 ↗ | (On Diff #145954) | Can we also propagate the demanded bits of the division result (in some form) into DemandedMaskIn? |
lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp | ||
---|---|---|
556 ↗ | (On Diff #145954) | Maybe. This is hard for non-power of 2 divisors though and probably not worth the effort :| |
lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp | ||
---|---|---|
556 ↗ | (On Diff #145954) | I think demanded-bits should compose which means you can treat a /u 12 as (a >> 2) /u 3. Since in udiv input bit at index i can only affect output bits at index i and below (i.e. less significant) we should be able to left-smear the demanded bits demanded bits for (a >> 2) /u 3 into the demanded bits for (a >> 2) and then apply the rule for >>. For instance, if we demand bit only 5 for an i8 a /u 12 == (a >> 2) /u 3 then we can say:
I'd also be fine with a TODO here since it does seem complex. |