<div dir="ltr">On 26 September 2013 12:34, Ben Karel <span dir="ltr"><<a href="mailto:ben@eschew.org" target="_blank">ben@eschew.org</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<div dir="ltr">I noticed a change in LLVM's behavior between 3.2 and 3.3/ToT, but I'm not sure if it qualifies as a bug/regression or not.<div><br></div><div>The change is that in 3.3 and tip of trunk, calling ConstantFoldConstantExpression on</div>



<div><br></div><div>    i64 and (i64 add (i64 add (i64 ptrtoint (i64* getelementptr (i64* null, i32 1) to i64), i64 ptrtoint (i64* getelementptr (i64* null, i32 1) to i64)), i64 15), i64 -16)<br></div><div><br></div><div>



produces</div><div><br></div><div>    i64 and (i64 add (i64 ptrtoint (i64* getelementptr (i64* null, i32 1) to i64), i64 23), i64 -16)<br></div><div><br></div><div>which, when passed back to ConstantFoldConstantExpression, gets boiled down to</div>



<div><br></div><div>    i64 16</div><div><br></div><div><br></div><div>LLVM 3.2 returns a ConstantInt from the first call. I've attached a small testcase which shows this behavior.</div><div><br></div><div>Is the fact that ConstantFoldConstantExpression does not produce a "minimal" constant expression a bug, or are clients expected to potentially need to iterate folding to get a final result? I didn't see anything in 3.3's release notes about changes to constant folding behavior.</div>

</div></blockquote><div><br></div><div>The original design had every constant being folded upon construction, thus preventing us from ever needing to revisit an CE's operands when trying to fold a CE. Unfortunately, we actually have two constant folders now, one which has access to TargetData and the other which doesn't. The TD-aware folder was designed with the same principle that it shouldn't need to fold its operands, but in reality this doesn't work since there's no guarantee that the operands have been folded with the TD-aware folder before. People have been adding hacks to make the TD-aware folder look deeper into its operands in an unprincipled fashion.</div>

<div><br></div><div>To answer your direct question, clients shouldn't need to iterate on the result. That's a bug.</div><div><br></div><div>But looking at the larger picture, I think we should fix the underlying problem by making TargetData a mandatory part of the Module and only having one constant folder in LLVM.</div>

<div><br></div><div>Nick</div><div><br></div></div></div></div>