The AllConstant check needs to be moved out of the if/else if chain to
avoid a test regression. The "there is no SimplifyZExt" comment puzzles me,
since there is SimplifyCastInst. Additionally, the Simplify* calls
seem to not see the operand as constant, so this needs to be tried if
the simplify failed.
Details
Diff Detail
Event Timeline
This generally makes sense to me. I left a comment as it would be preferable to split the two conceptual changes if we can test them separately.
I think we also need addrspacecast tests with different address spaces to show they are not accidentally merged.
lib/Transforms/Scalar/NewGVN.cpp | ||
---|---|---|
1181 | The way I understand this: If you have a BitCast, or maybe even another instruction, for which the simplify failed but AllConstant is true, you won't get constant folding before, correct? Would it be possible to show the problem even w/o AddrSpaceCast? |
lib/Transforms/Scalar/NewGVN.cpp | ||
---|---|---|
1171 | The code here should pass in E->getOperand(0), instead of CI->getOperand(0): we want to pass in the leader for the operand, not the operand from the original IR. This way, there should be no need to move the AllConstant condition. If the leader of the CastInst is constant, we should already simplify it here. Please note that there is a subtle underlying issue with the way simplifications on the original IR and the simplified leaders interact, but that needs to be addressed separately and I do not think CastInst should have any special treatment here. If anything, it may make it a bit harder to trigger the issue. |
LGTM. Could you also add a test where we need to pass in the leader of the operand? Something like having 2 loads from the same address would probably be enough.
The code here should pass in E->getOperand(0), instead of CI->getOperand(0): we want to pass in the leader for the operand, not the operand from the original IR. This way, there should be no need to move the AllConstant condition. If the leader of the CastInst is constant, we should already simplify it here.
Please note that there is a subtle underlying issue with the way simplifications on the original IR and the simplified leaders interact, but that needs to be addressed separately and I do not think CastInst should have any special treatment here. If anything, it may make it a bit harder to trigger the issue.