<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Exchange Server">
<!-- converted from rtf -->
<style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
</head>
<body>
<font face="Calibri" size="2"><span style="font-size:11pt;">
<div>Hi, </div>
<div> </div>
<div>I observed below behavior with Instruction combiner (visitMul  Canonicalization)</div>
<div>It tries to convert “(X+C1)*C2” to “X*C2+C1*C2”</div>
<div>While transforming if operation is guaranteed to not overflow it does not </div>
<div>reflect same property to transformed instructions.</div>
<div> </div>
<div>Consider following scenarios:</div>
<div>1) If input is ((X+C1)*C2)<nsw></div>
<div>Then post canonicalization output should be (X*C2+C1*C2) <nsw></div>
<div> </div>
<div>2) If input is (((X+C1)<nsw>)*C2)<nsw></div>
<div>Then post canonicalization output should be ((X*C2) <nsw>+(C1*C2) <nsw>) <nsw></div>
<div> </div>
<div>** C1 & C2 are constants.</div>
<div> </div>
<div>Current canonicalization transforms to (X*C2+C1*C2) in both scenarios (1 & 2).</div>
<div> </div>
<div>To me this looks like a limitation with canonicalization where its missing guarantee to not overflow property.</div>
<div>Please confirm my understanding.</div>
<div> </div>
<div><File: InstCombineMulDivRem.cpp ></div>
<div> 168 Instruction *InstCombiner::visitMul(BinaryOperator &I) { </div>
<div> 268     // Canonicalize (X+C1)*CI -> X*CI+C1*CI.</div>
<div> 269     {</div>
<div> 270       Value *X;</div>
<div> 271       Constant *C1;</div>
<div> 272       if (match(Op0, m_OneUse(m_Add(m_Value(X), m_Constant(C1))))) {</div>
<div> 273         Value *Mul = Builder->CreateMul(C1, Op1);</div>
<div> 274         // Only go forward with the transform if C1*CI simplifies to a tidier</div>
<div> 275         // constant.</div>
<div> 276         if (!match(Mul, m_Mul(m_Value(), m_Value())))</div>
<div> 277           return BinaryOperator::CreateAdd(Builder->CreateMul(X, Op1), Mul);</div>
<div> 278       }</div>
<div> 279     }</div>
<div> </div>
<div>If my understanding is correct then I like propose below change here:</div>
<div>If input operation to canonicalization is guaranteed to not overflow then transformed operation should have the same property.</div>
<div>Specifically I like to handle above explained 2 scenarios for ‘nsw’ & ‘nuw’.</div>
<div> </div>
<div>Regards,</div>
<div>Ashutosh</div>
<div> </div>
</span></font>
</body>
</html>