[llvm-commits] Fold() function on TargetFolder class - removal of redundant constantexpr

Jin Gu Kang jaykang10 at imrc.kist.re.kr
Tue Feb 22 21:34:32 PST 2011


Hi Chris

I tested the following code using llvm-gcc-4.2.

struct test{
  char c:3;
  char d:4;
  char e:5;
  int a;
  double b;
};
struct kist {
  char a;
  int b;
  struct test temp;
  short c;
  int d;
};
struct kist kang = {1, 2, {1, 2, 3, 5, 6}, 3, 4};
int main(void) {
  kang.temp.e = 1;
  return 0;
}

The converted result is as in the following:

%0 = type { i8, i32, %1, i16, i32 }
%1 = type { i8, i8, i32, double }
%struct.kist = type { i8, i32, %struct.test, i16, i32 }
%struct.test = type { i32, i32, double }
@kang = unnamed_addr global %0 { i8 1, i32 2, %1 { i8 17, i8 3, i32 5, double 6.000000e+00 }, i16 3, i32 4 }
define i32 @main() nounwind {
entry:
  %retval = alloca i32
  %0 = alloca i32
  %"alloca point" = bitcast i32 0 to i32
  %1 = load i32* bitcast (i8* getelementptr inbounds (%0* @kang, i32 0, i32 2, i32 0) to i32*), align 8
  %2 = and i32 %1, -7937
  %3 = or i32 %2, 256
  store i32 %3, i32* bitcast (i8* getelementptr inbounds (%0* @kang, i32 0, i32 2, i32 0) to i32*), align 8
  store i32 0, i32* %0, align 4
  %4 = load i32* %0, align 4
  store i32 %4, i32* %retval, align 4
  br label %return
return:                                           ; preds = %entry
  %retval1 = load i32* %retval
  ret i32 %retval1
}

I thought some of issues about converted code.

First, I thought index of getelementptr is confused.
%1 = load i32* bitcast (i8* getelementptr inbounds (%0* @kang, i32 0, i32 2, i32 0) to i32*)
On above statement, there is not bitcast which decribes kang's sub struct type(%1) is mapped to struct.test.

The reason why bitcast disappears that SymbolicallyEvaluateGEP() function under CreateStructGEP()
function changes bitcast ConstantExpr to bitcast ConstantExpr's operand(0) using stripPointerCasts()
and makes new GEP using the operand(0).

I would like to know what do you think about keeping bitcast ConstantExpr about above code? 

Second, I thought redundant information is generated while processing CreateStructGEP().
  Constant *CreateInBoundsGetElementPtr(Constant *C, Value* const *IdxList,
                                        unsigned NumIdx) const {
    return Fold(ConstantExpr::getInBoundsGetElementPtr(C, IdxList, NumIdx));
  }
As I said on previous e-mail, I thought if fold() function's argument is different with fold() function's return value,
fold() function's argument which was newly created  is redundant. This redundant ConstantExpr
increases Use count of its operand and Increased Use Count may have effect on functions which use Use inforamation
like replaceAllUsesWith(). so I would like to remove this redundant ConstantExprs. :)

These were my thoughts. :)

Thanks,
Jin-Gu Kang
________________________________________
From: Chris Lattner [clattner at apple.com]
Sent: Wednesday, February 23, 2011 6:02 AM
To: Jin Gu Kang
Cc: Duncan Sands; llvm-commits at cs.uiuc.edu
Subject: Re: [llvm-commits] Fold() function on TargetFolder class - removal of redundant constantexpr

On Feb 22, 2011, at 5:47 AM, Jin Gu Kang wrote:

> replaceAllUsesWith() is an example. :)
>
> I don't know all of passes which use inforamtion of Use.
> so I would like to know whether this issue is trivial or not.
>
> I think view of you and other llvm-commiters are right.

Hi Jin,

Instead of focusing on the patch, lets look at it another way: what problem are you experiencing and trying to solve?

-Chris



More information about the llvm-commits mailing list