On Jul 7, 2010, at 5:47 AM, Jianzhou Zhao wrote:>> >> Does this also apply to two different variables? say >> int z x y; >> z = x ^ y; >> If ConstantFoldBinaryInstruction also folds x ^ y into z, should this >> pass (which uses ConstantFold) also initialize x and y with a same >> initial value? Otherwise at runtime z may not be 0. > > I guess my question is what variables can have undef values. In my > understanding, only uninitialized locals and globals can be undefined, > so compilers are free to assign them at runtime, if > ConstantFoldBinaryInstruction ensures that x and y can only be locals > and globals. But function parameters cannot be undefined, which should > be arbitrary symbols, depending on concrete arguments. Is this > correct?I don't really understand your question here. Are you asking about C or LLVM IR, or something else? -Chris
On Wed, Jul 7, 2010 at 11:38 AM, Chris Lattner <clattner at apple.com> wrote:> > On Jul 7, 2010, at 5:47 AM, Jianzhou Zhao wrote: > >>> >>> Does this also apply to two different variables? say >>> int z x y; >>> z = x ^ y; >>> If ConstantFoldBinaryInstruction also folds x ^ y into z, should this >>> pass (which uses ConstantFold) also initialize x and y with a same >>> initial value? Otherwise at runtime z may not be 0. >> >> I guess my question is what variables can have undef values. In my >> understanding, only uninitialized locals and globals can be undefined, >> so compilers are free to assign them at runtime, if >> ConstantFoldBinaryInstruction ensures that x and y can only be locals >> and globals. But function parameters cannot be undefined, which should >> be arbitrary symbols, depending on concrete arguments. Is this >> correct? > > I don't really understand your question here. Are you asking about C or LLVM IR, or something else?Sorry for the confusion. Does ConstantFoldBinaryInstruction also fold x ^ y into 0 if both x and y are undef? I can understand why x ^ x can be 0 if x is undef, but if x and y are different variables, that x ^ y = 0 must reply on the assumption that x and y need to be initialized with the same value.> > -Chris-- Jianzhou
On Jul 7, 2010, at 8:45 AM, Jianzhou Zhao wrote:>> >> I don't really understand your question here. Are you asking about C or LLVM IR, or something else? > > Sorry for the confusion. Does ConstantFoldBinaryInstruction also fold > x ^ y into 0 if both x and y are undef?That's a poorly formed question. ConstantFoldBinaryInstruction doesn't do any real analysis - if there is a symbolic operand, it doesn't do the fold. It only folds when the two operands *are* undef. It has no idea if they came from the "same" variable or not. -Chris