Marcello Maggioni
2014-May-30 01:21 UTC
[LLVMdev] [PATCH] Passing down BinaryOperator flags to BinarySDNode + X86 optimization
Hello, here is a proposed patch to pass down BinaryOperator the NoUnsignedWrap/NoSignedWrap and IsExact flags down to the SDNodes so that backends can use them for additional optimizations. The core of the patch is using the SubclassData field of SDNode for BinarySDNode to store the flags information. SelectionDAGBuilder will then set the correct flag information the moment the Binary instruction is visited during construction. In doing this I also refactored a little bit the getNode() method accepting two operands, extracting the main constant folding logic into a separate static function. The patch implementing this is the file "flag_nodes.patch" attached. In addition I implemented an optimization where an unneeded "test instruction" in X86 where emitted that uses this new feature. This optimization is contained in the "x86_opt_wrap.patch" attached. I also added a test case that exercises the optimization in the "factorial_test.patch" The patch makes this snippet of code: LBB0_1: ## %while.body ## =>This Inner Loop Header: Depth=1 imulq %rdi, %rax decq %rdi testq %rdi, %rdi jg LBB0_1 become this: LBB0_1: ## %while.body ## =>This Inner Loop Header: Depth=1 imulq %rdi, %rax decq %rdi jg LBB0_1 if the NSW flag is set on the SDNode of that represents the DEC instruction (presumably an ADD or a SUB). If somebody could review this it would be awesome :) Cheers, Marcello -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140529/fe77989c/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: factorial_test.patch Type: application/octet-stream Size: 1802 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140529/fe77989c/attachment.obj> -------------- next part -------------- A non-text attachment was scrubbed... Name: flag_nodes.patch Type: application/octet-stream Size: 24119 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140529/fe77989c/attachment-0001.obj> -------------- next part -------------- A non-text attachment was scrubbed... Name: x86_opt_wrap.patch Type: application/octet-stream Size: 1201 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140529/fe77989c/attachment-0002.obj>