[PATCH] D48278: [SelectionDAG] Fold redundant masking operations of shifted value

Diogo N. Sampaio via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 9 07:24:58 PDT 2018


dnsampaio added a comment.

>> Ah, I see that now. But I'm not convinced this is the right approach. Why are we waiting to optimize this in the backend? This is a universally good optimization, so it should be in IR:

Agree, I also intend to implement this transformation in the IR. But there are cases that this is only seen after some instructions have been combined in the dag, so why not here also? And indeed, it required for a future patch that detects sub-elements moves in memory, as to reduce load and store widths.

>> I'm not sure exactly where that optimization belongs. Ie, is it EarlyCSE, GVN, somewhere else, or is it its own pass? But I don't see any benefit in waiting to do this in the DAG.
> 
> This also raises a question that has come up in another review recently - https://reviews.llvm.org/D41233. If we reverse the canonicalization of shl+and, we would solve the most basic case that I showed above:
> 
>   define i32 @shl_first(i32 %a) {
>     %t2 = shl i32 %a, 8
>     %t3 = and i32 %t2, 44032
>     ret i32 %t3
>   }
>   
>   define i32 @mask_first(i32 %a) {
>     %a2 = and i32 %a, 172
>     %a3 = shl i32 %a2, 8
>     ret i32 %a3
>   }
>   




https://reviews.llvm.org/D48278





More information about the llvm-commits mailing list