Recompute the range: match for fptosi of sitofp, and then query the range of the input to the sitofp
according the comment on D129140.
Details
Diff Detail
Event Timeline
llvm/lib/Transforms/Utils/SimplifyIndVar.cpp | ||
---|---|---|
681 | This is probably not needed, as SIToFP operand must be an integer, which is always SCEVable. | |
683 | Why do we care about hasOneUse here? This seems at odds with your users() loop below. | |
687 | getSignedRange? | |
698 | How can IVOperand not dominate U? IVOperands dominates UseInst, which dominates all its uses. | |
699 | There may be a type mismatch here: Either we need to limit to the same type, or insert sext/trunc as necessary. |
This looks reasonable to me, but I think we could use at least two more tests: 1. Type mismatch between the integer IV and the fptosi result. 2. Case where the transform is *not* valid because there are too many significant bits.
llvm/lib/Transforms/Utils/SimplifyIndVar.cpp | ||
---|---|---|
679 | We don't really need the IVOperand argument, given how casts only have a single operand. | |
694 | We should also add CI to DeadInsts, so it gets DCEd. | |
699 | Can just be Changed = true, no need for |=. | |
llvm/test/Transforms/IndVarSimplify/floating-point-small-iv.ll | ||
3 | Drop the -adce here. | |
37 | For this test, it would be better to use an integer IV from the start, rather than going through the float -> int transform. This makes it clear that your code works even if IndVars is not the producer of the integer IV (which is the key difference to D129140). |
llvm/lib/Transforms/Utils/SimplifyIndVar.cpp | ||
---|---|---|
932 | You might want to call pushIVUsers(IVOperand, L, Simplified, SimpleIVUsers); here, to queue the potentially new direct uses of IVOperand (which no longer go through the cast pair and might be simplified now). |
Address the remain comment, and new call pushIVUsers(IVOperand, L, Simplified, SimpleIVUsers)
We don't really need the IVOperand argument, given how casts only have a single operand.