<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Hi all, <br>
I have been looking at the way LLVM optimizes code before
forwarding it to the backend I develop for my company and while
building <br>
define i32 @test_extract_subreg_func(i32 %x, i32 %y) #0 {<br>
entry:<br>
%conv = zext i32 %x to i64<br>
%conv1 = zext i32 %y to i64<br>
%mul = mul nuw i64 %conv1, %conv<br>
%shr = lshr i64 %mul, 32<br>
%xor = xor i64 %shr, %mul<br>
%conv2 = trunc i64 %xor to i32<br>
ret i32 %conv2<br>
}<br>
<br>
I came upon the following optimization (during instcombine):<br>
<b>IC: Visiting: %mul = mul nuw i64 %conv, %conv1<br>
IC: Visiting: %shr = lshr i64 %mul, 32<br>
IC: Visiting: %conv2 = trunc i64 %shr to i32<br>
IC: Visiting: %conv3 = trunc i64 %mul to i32<br>
IC: Visiting: %xor = xor i32 %conv3, %conv2<br>
IC: ADD: %xor6 = xor i64 %mul, %shr<br>
IC: Old = %xor = xor i32 %conv3, %conv2<br>
New = <badref> = trunc i64 %xor6 to i32<br>
</b><br>
which seems to be performed by SDValue
DAGCombiner::SimplifyBinOpWithSameOpcodeHands(SDNode *N) <br>
<br>
In my backend's architecture truncate is free, but zext is not (and
i64 is not a desirable type for xor or any binary operation in
general), so I would expect this optimization to be bypassed but
because of the following statement :<br>
(N0.getOpcode() == ISD::TRUNCATE && (!TLI.isZExtFree(VT,
Op0VT) || !TLI.isTruncateFree(Op0VT, VT)) <br>
it is not (as isZExtFree return false for my architecture while
isTruncateFree returns true). The comment on binop simplification
says that binop over truncs should be optimize only if trunc is not
free, so I do not understand the point of adding !isZExtFree at this
point.<br>
Can someone enlighten my ignorance on this optimization ?<br>
<br>
best regards,<br>
Nicolas Brunie<br>
</body>
</html>