<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
<div class="">Hi,</div>
<div class=""><br class="">
</div>
<div class="">I'm trying to optimize a pattern like this into a single i16 load:</div>
<div class=""> %1 = bitcast i16* %pData to i8*</div>
<div class=""> %2 = load i8, i8* %1, align 1</div>
<div class=""> %3 = zext i8 %2 to i16</div>
<div class=""> %4 = shl nuw i16 %3, 8</div>
<div class=""> %5 = getelementptr inbounds i8, i8* %1, i16 1</div>
<div class=""> %6 = load i8, i8* %5, align 1</div>
<div class=""> %7 = zext i8 %6 to i16</div>
<div class=""> %8 = shl nuw nsw i16 %7, 0</div>
<div class=""> %9 = or i16 %8, %4 </div>
<div class=""><br class="">
</div>
<div class="">I came across load combine pass which is motivated by virtualliy the same pattern. Load combine optimizes the pattern by combining adjacent loads into one load and lets the rest of the optimizer cleanup the rest. From what I see on the initial
review for load combine (<a href="https://reviews.llvm.org/D3580" class="">https://reviews.llvm.org/D3580</a>) it was not enabled by default because it caused some performance regressions. It's not very surprising, I see how this type of widening can obscure
some facts for the rest of the optimizer.</div>
<div class=""><br class="">
</div>
<div class="">I can't find any backstory for this pass, why was it chosen to optimize the pattern in question in this way? What is the current status of this pass?</div>
<div class=""><br class="">
</div>
<div class="">I have an alternative implementation for it locally. I implemented an instcombine rule similar to recognise bswap/bitreverse idiom. It relies on collectBitParts (Local.cpp) to determine the origin of the bits in a given or value. If all the bits
are happen to be loaded from adjacent locations it replaces the or with a single load or a load plus bswap.</div>
<div class=""><br class="">
</div>
<div class="">If the alternative approach sounds reasonable I'll post my patches for review.</div>
<div class=""><br class="">
</div>
<div class="">Artur</div>
</body>
</html>