[PATCH] D78880: [InstCombine] use select-of-constants with set/clear bit mask patterns
Sanjay Patel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 26 09:33:40 PDT 2020
spatel created this revision.
spatel added reviewers: lebedev.ri, xbolva00, dmgreen.
Herald added subscribers: hiraditya, mcrosier.
Herald added a project: LLVM.
Cond ? (X & ~C) : (X | C) --> (X & ~C) | (Cond ? 0 : C)
Cond ? (X | C) : (X & ~C) --> (X & ~C) | (Cond ? C : 0)
The select-of-constants form results in better codegen. There's an existing test diff that shows a transform that results in an extra IR instruction, but that's an existing problem.
This is motivated by code seen in LLVM itself - see PR37581:
https://bugs.llvm.org/show_bug.cgi?id=37581
define i8 @src(i8 %x, i8 %C, i1 %b) {
%notC = xor i8 %C, -1
%and = and i8 %x, %notC
%or = or i8 %x, %C
%cond = select i1 %b, i8 %or, i8 %and
ret i8 %cond
}
define i8 @tgt(i8 %x, i8 %C, i1 %b) {
%notC = xor i8 %C, -1
%and = and i8 %x, %notC
%mul = select i1 %b, i8 %C, i8 0
%or = or i8 %mul, %and
ret i8 %or
}
http://volta.cs.utah.edu:8080/z/Vt2WVm
https://reviews.llvm.org/D78880
Files:
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
llvm/test/Transforms/InstCombine/cast.ll
llvm/test/Transforms/InstCombine/select-with-bitwise-ops.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78880.260170.patch
Type: text/x-patch
Size: 6222 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200426/71c5656c/attachment.bin>
More information about the llvm-commits
mailing list