{"push_id":590828749,"size":1,"distinct_size":1,"ref":"refs/heads/master","head":"0a523a5e041d05a557cfbb0ce8e87f9f113e7b13","before":"4415da12fa11018fd79d9c5e5d17d475cf713b2e","commits":[{"sha":"0a523a5e041d05a557cfbb0ce8e87f9f113e7b13","author":{"email":"34e6c836575097c76965abe8873967ccff230386@gmail.com","name":"Eric Christopher"},"message":"Fix a problem where the TwoAddressInstructionPass which generate redundant register moves in a loop.\n\nFrom:\nint M, total;\nvoid foo() {\nint i;\nfor (i = 0; i < M; i++) {\n  total = total + i / 2;\n}\n}\n\nThis is the kernel loop:\n\n.LBB0_2: # %for.body\n\n=>This Inner Loop Header: Depth=1\nmovl %edx, %esi\nmovl %ecx, %edx\nshrl $31, %edx\naddl %ecx, %edx\nsarl %edx\naddl %esi, %edx\nincl %ecx\ncmpl %eax, %ecx\njl .LBB0_2\n--------------------------\nThe first mov insn \"movl %edx, %esi\" could be removed if we change \"addl %esi, %edx\" to \"addl %edx, %esi\".\n\nThe IR before TwoAddressInstructionPass is:\nBB#2: derived from LLVM BB %for.body\n\nPredecessors according to CFG: BB#1 BB#2\n    %vreg3<def> = COPY %vreg12<kill>; GR32:%vreg3,%vreg12\n    %vreg2<def> = COPY %vreg11<kill>; GR32:%vreg2,%vreg11\n    %vreg7<def,tied1> = SHR32ri %vreg3<tied0>, 31, %EFLAGS<imp-def,dead>; GR32:%vreg7,%vreg3\n    %vreg8<def,tied1> = ADD32rr %vreg3<tied0>, %vreg7<kill>, %EFLAGS<imp-def,dead>; GR32:%vreg8,%vreg3,%vreg7\n    %vreg9<def,tied1> = SAR32r1 %vreg8<kill,tied0>, %EFLAGS<imp-def,dead>; GR32:%vreg9,%vreg8\n    %vreg4<def,tied1> = ADD32rr %vreg9<kill,tied0>, %vreg2<kill>, %EFLAGS<imp-def,dead>; GR32:%vreg4,%vreg9,%vreg2\n    %vreg5<def,tied1> = INC64_32r %vreg3<kill,tied0>, %EFLAGS<imp-def,dead>; GR32:%vreg5,%vreg3\n    CMP32rr %vreg5, %vreg0, %EFLAGS<imp-def>; GR32:%vreg5,%vreg0\n    %vreg11<def> = COPY %vreg4; GR32:%vreg11,%vreg4\n    %vreg12<def> = COPY %vreg5<kill>; GR32:%vreg12,%vreg5\n    JL_4 <BB#2>, %EFLAGS<imp-use,kill>\nNow TwoAddressInstructionPass will choose vreg9 to be tied with vreg4. However, it doesn't see that there is copy from vreg4 to vreg11 and another copy from vreg11 to vreg2 inside the loop body. To remove those copies, it is necessary to choose vreg2 to be tied with vreg4 instead of vreg9. This code pattern commonly appears when there is reduction operation in a loop.\n\nSo check for a reversed copy chain and if we encounter one then we can commute the add instruction so we can avoid a copy.\n\nPatch by Wei Mi.\nhttp://reviews.llvm.org/D7806","distinct":true,"url":"https://api.github.com/repos/llvm-project/llvm-project-submodule/commits/0a523a5e041d05a557cfbb0ce8e87f9f113e7b13"}]}