torch.flip is inplaced too aggressively in torch inductor
Labels: triaged, oncall: pt2, module: inductor

### 🐛 Describe the bug

The operation `a.copy_(torch.flip(a, (0,)))` for `a` a 1D vector generates the following incorrect code
```python
@pointwise(size_hints=[1048576], filename=__file__, meta={'signature': {0: '*fp32', 1: '*fp32', 2: '*fp32', 3: 'i32'}, 'device': 0, 'constants': {}, 'mutated_arg_names': ['in_ptr0', 'out_ptr1'], 'configs': [instan
ce_descriptor(divisible_by_16=(0, 1, 2, 3), equal_to_1=())]})                                                                                                                                                        
@triton.jit                                                                                                                                                                                                          
def triton_(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK : tl.constexpr):                                                                                                                                             
    xnumel = 1048576                                                                                                                                                                                                 
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel  
    x0 = xindex  
    tmp0 = tl.load(in_ptr0 + (1048575 + ((-1)*x0)), None)
    tl.store(out_ptr0 + (tl.broadcast_to(x0, [XBLOCK])), tmp0, None)
    tl.store(out_ptr1 + (tl.broadcast_to(x0, [XBLOCK])), tmp0, None)            
                                                     
import triton                                                                                             
import triton.language as tl                                                                              
from torch._inductor.triton_heuristics import grid, start_graph, end_graph
from torch._C import _cuda_getCurrentRawStream as get_cuda_stream                                                                                                                                                    
                                                     
                                                     
async_compile.wait(globals())
del async_compile
                                                     
def call(args):                                   
    arg0_1, = args                                                                                        
    args.clear()
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0) # no-op to ensure context
        buf0 = empty_strided((1048576, ), (1, ), device='cuda', dtype=torch.float32)
        stream0 = get_cuda_stream(0)
        triton_poi_fused_copy_flip_0.run(arg0_1, buf0, arg0_1, 1048576, grid=grid(1048576), stream=stream0)
        del arg0_1
        return (buf0, )
```

This code has two issues:
- It is clearly incorrect given aliasing of `in_ptr0` and `out_ptr1`
- If it were correct, it's still using an extra buffer that it doesn't return
Even more, one could argue that:
- If the stride iteration allowed for it, the input should be marked as an `in_out_ptr

This last issue is happening because we have two ways of dealing with mutated args. One, at an IR affecting the read-writes level which happens in `Scheduler.compute_dependencies`, and another one that happens at `BaseSchedulerNode.allocate`. The first one does not create an `in_out_ptr`, but simply annotates the mutations in the `mutated_arg_names`. It's not clear to me why wouldn't both of them create `in_out_ptr`s. Perhaps this is an oversight. 

The easiest fix for this would be to perform the operation out-of-place when the index has negative strides. A better fix (that we'd need to benchmark) would be to perform two loads and two stores per thread, iterating just over half of the dimension that needs to be flipped.

Found when looking at https://github.com/pytorch/pytorch/issues/101930

### Versions

master

cc @ezyang @msaroufim @wconstab @ngimel @bdhirsh @anijain2305 @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @Xia-Weiwen @wenzhe-nrv @jiayisunx @peterbell10