<div dir="ltr"><div style="min-height:100%"><div class="gmail-nH" style="width:1869px"><div class="gmail-nH" style=""><div class="gmail-nH gmail-bkL"><div class="gmail-no" style="float:left;display:flex;width:1869px"><div class="gmail-nH gmail-bkK gmail-nn" style="min-height:1px;float:left;overflow:hidden;width:1682px"><div class="gmail-nH"><div class="gmail-nH"><div class="gmail-nH gmail-ar4 gmail-z"><div class="gmail-aeI"><div class="gmail-AO" style=""><div id="gmail-:3" class="gmail-Tm gmail-aeJ" style="padding-right:0px;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;overflow-y:scroll;height:838px"><div id="gmail-:1" class="gmail-aeF" style="padding:0px;vertical-align:bottom;min-height:648px"><div class="gmail-nH"><div class="gmail-nH"><div class="gmail-nH gmail-g"><table class="gmail-Bs gmail-nH gmail-iY gmail-bAt" cellpadding="0" style="border-spacing:0px;padding:0px;border-collapse:collapse;width:1597px;display:block"><tbody><tr><td class="gmail-Bu gmail-bAn" style="vertical-align:top;padding:0px;display:block;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial"><div class="gmail-nH gmail-if" style="margin:0px 16px 0px 0px;padding:0px"><div class="gmail-nH gmail-aHU" style=""><div class="gmail-nH gmail-hx" style="background-color:transparent;min-width:502px;padding:0px"><div class="gmail-nH"><div class="gmail-h7 gmail-ie gmail-nH gmail-oy8Mbf" tabindex="-1" style="clear:both;padding-bottom:0px;max-width:100000px;outline:none"><div class="gmail-Bk" style="margin-bottom:0px;border-width:0px;border-top-style:solid;border-right-style:initial;border-bottom-style:initial;border-left-style:initial;border-top-color:rgb(239,239,239);border-right-color:initial;border-left-color:initial;border-bottom-color:initial;border-radius:0px;width:1581px;float:none"><div class="gmail-G3 gmail-G2" style="padding-top:0px;background-color:transparent;border-right:0px;border-bottom:0px rgba(100,121,143,0.12);border-left:0px;border-top:none;border-radius:0px;margin-bottom:0px;margin-left:0px;margin-right:0px"><div id="gmail-:1qs"><div class="gmail-adn gmail-ads" style="border-left:none;padding:0px;display:flex"><div class="gmail-gs" style="margin:0px;padding:0px 0px 20px;width:1517px"><div class="gmail-"><div id="gmail-:1sc" class="gmail-ii gmail-gt" style="font-size:12.8px;direction:ltr;margin:8px 0px 0px;padding:0px"><div id="gmail-:1qq" class="gmail-a3s gmail-aXjCH" style="overflow:hidden;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:small;line-height:1.5;font-family:Arial,Helvetica,sans-serif"><div dir="ltr">Hello,<div><br></div><div>I was trying a basic example on LLVM GVN Hoist and output differs from what I expect. Am I missing something ?</div><div><br></div><div><b>Code</b> :</div><div><br></div><div><div>int main()</div><div>{</div><div><span style="white-space:pre-wrap">     </span>int x = 7;</div><div><span style="white-space:pre-wrap">       </span>int a = 0;</div><div><span style="white-space:pre-wrap">       </span>if(a == 7){</div><div><span style="white-space:pre-wrap">              </span>x = 1;</div><div><span style="white-space:pre-wrap">           </span>a = 8 * x;</div><div><span style="white-space:pre-wrap">       </span>} else {</div><div><span style="white-space:pre-wrap">         </span>x = 1;</div><div><span style="white-space:pre-wrap">           </span>a = 2 * x;</div><div><span style="white-space:pre-wrap">       </span>}</div><div><span style="white-space:pre-wrap">        </span>return 0;</div><div>}</div></div><div><br></div><div><b>Commands</b> :</div><div>clang-8 -O0 -S -emit-llvm test.c<br></div><div>opt-8 -gvn-hoist -S < test.ll<br></div><div><br></div><div><b>Output :</b></div><div><b><br></b></div><div><div>; ModuleID = '<stdin>'</div><div>source_filename = "test.c"</div><div>target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"</div><div>target triple = "x86_64-pc-linux-gnu"</div><div><br></div><div>; Function Attrs: noinline nounwind optnone uwtable</div><div>define dso_local i32 @main() #0 {</div><div>  %1 = alloca i32, align 4</div><div>  %2 = alloca i32, align 4</div><div>  %3 = alloca i32, align 4</div><div>  store i32 0, i32* %1, align 4</div><div>  store i32 7, i32* %2, align 4</div><div>  store i32 0, i32* %3, align 4</div><div>  %4 = load i32, i32* %3, align 4</div><div>  %5 = icmp eq i32 %4, 7</div><div>  br i1 %5, label %6, label %9</div><div><br></div><div>; <label>:6:                                      ; preds = %0</div><div>  store i32 1, i32* %2, align 4</div><div>  %7 = load i32, i32* %2, align 4</div><div>  %8 = mul nsw i32 8, %7</div><div>  store i32 %8, i32* %3, align 4</div><div>  br label %12</div><div><br></div><div>; <label>:9:                                      ; preds = %0</div><div>  store i32 1, i32* %2, align 4</div><div>  %10 = load i32, i32* %2, align 4</div><div>  %11 = mul nsw i32 2, %10</div><div>  store i32 %11, i32* %3, align 4</div><div>  br label %12</div><div><br></div><div>; <label>:12:                                     ; preds = %9, %6</div><div>  ret i32 0</div><div>}</div><div><br></div><div>attributes #0 = { noinline nounwind optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }</div><div><br></div><div>!llvm.module.flags = !{!0}</div><div>!llvm.ident = !{!1}</div><div><br></div><div>!0 = !{i32 1, !"wchar_size", i32 4}</div><div>!1 = !{!"clang version 8.0.0-svn356034-1~exp1~20190313093039.54 (branches/release_80)"}</div><div><br></div><div>Thank you,</div><div>Digvijay</div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></td><td class="gmail-Bu gmail-yM" style="vertical-align:top;padding:0px;width:0px;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial"><div class="gmail-nH" style="width:0px"><div class="gmail-dJ" style="height:0px;overflow:hidden;clear:both"></div></div></td><td class="gmail-Bu gmail-y3" style="vertical-align:top;padding:0px;width:0px;height:100px;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial"><div class="gmail-Bt" style="height:0px;overflow:hidden;width:841px"></div><div class="gmail-nH gmail-bno gmail-adC" style="width:0px;margin:0px"><div class="gmail-nH"></div></div><div class="gmail-y4" style="height:2095px;width:0px;opacity:0"></div></td></tr></tbody></table></div></div></div></div></div></div></div></div></div></div></div><div class="gmail-nH gmail-bAw gmail-nn gmail-it" style="min-height:1px;float:left;min-width:0px;width:0px;height:886px"><div class="gmail-brC-dA-I-Jw" style="display:flex;height:56px;overflow:hidden;width:56px"><div class="gmail-aT5-aOt-I gmail-brC-dA-I gmail-aT5-aOt-I-Jp" tabindex="0" style="height:56px;outline:none;width:56px"><div class="gmail-aT5-aOt-I-JX-Jw" style="background-repeat:no-repeat;background-position:50% 50%;background-size:20px 20px;border-top-right-radius:0px;border-bottom-right-radius:0px;display:flex;height:20px;margin:8px 0px 8px 8px;padding:10px 0px 10px 10px"></div></div></div></div></div><div class="gmail-dJ" style="height:0px;overflow:hidden;clear:both"></div></div></div></div></div><div class="gmail-vY gmail-nq" style="width:1869px;height:950px"></div><div><div></div></div><div class="gmail-dw" style="width:1869px;height:950px;overflow:hidden"><div><div class="gmail-nH" style="width:1869px"><div class="gmail-nH" style="height:950px"><div class="gmail-no" style="float:right"><div class="gmail-nH gmail-nn" style="min-height:1px;float:left;width:8px"></div><div class="gmail-nH gmail-nn" style="min-height:1px;float:left;width:605px;height:950px"><div class="gmail-no" style="float:left"><div class="gmail-nH gmail-nn" style="min-height:1px;float:left;width:600px;height:950px"><div class="gmail-AD" style="width:600px"><div class="gmail-nH"><div class="gmail-nH gmail-Hd" style="border-radius:4px 4px 0px 0px"><div class="gmail-nH"><div tabindex="1" style="background-color:transparent"></div></div><div class="gmail-nH gmail-Hy gmail-aXJ"><div class="gmail-nH"><div class="gmail-l gmail-m" style="float:none;width:600px;background:rgb(64,64,64);border-radius:4px 4px 0px 0px"><div class="gmail-l gmail-n" style="background:none;border-radius:4px 4px 0px 0px;margin:0px 0px 0px 3px"><div class="gmail-k" style="background:none;padding:0px 0px 4px;border-radius:4px 0px 0px;margin:0px 3px 0px 0px"><div class="gmail-aCk"><div class="gmail-nH gmail-wKggEb"><table cellpadding="0" class="gmail-cf gmail-Ht" style="border-collapse:collapse;width:600px;margin:0px;font-size:12.8px"><tbody><tr id="gmail-:1t8"><td><div id="gmail-:1ta" class="gmail-Hp" style="background-position:0% 50%;background-repeat:no-repeat;color:white;margin-left:16px;height:auto;padding:10px 0px;line-height:20px"><h2 class="gmail-a3E" style="font-size:0.875rem;font-weight:500;margin:0px;letter-spacing:0.2px"><div class="gmail-a3I" style="width:1px;height:1px;overflow:hidden;letter-spacing:0.2px">Compose:</div><br class="gmail-Apple-interchange-newline"></h2></div></td></tr></tbody></table></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>