[cfe-users] data type implicit extension

Juan Fernando Eusse eusse at ice.rwth-aachen.de
Mon Nov 26 02:44:04 PST 2012


Good day,

I am working on a project related with generating hardware descriptions 
based on a C input application and found out that for the C language, 
the front-end extends the bit-width of the operands and operations in a 
given statement. So if I have for example:

short mulshort1 = 10,mulshort2 = 25,mulres = 0;
mulres = mulshort1 * mulshort2;

it will translate into:

  %mulshort1 = alloca i16, align 2
  %mulshort2 = alloca i16, align 2
  %mulres = alloca i16, align 2
  store i32 0, i32* %retval
  store i16 10, i16* %mulshort1, align 2, !dbg !20
  store i16 25, i16* %mulshort2, align 2, !dbg !21
  %0 = load i16* %mulshort1, align 2, !dbg !22
  %conv = sext i16 %0 to i32, !dbg !22 <-sign extension to 32-bits
  %1 = load i16* %mulshort2, align 2, !dbg !22
  %conv1 = sext i16 %1 to i32, !dbg !22 <-sign extension to 32-bits
  %mul = mul nsw i32 %conv, %conv1, !dbg !22 <-32-bit multiplication
  %conv2 = trunc i32 %mul to i16, !dbg !22 <-trunc into 16bit value
  store i16 %conv2, i16* %mulres, align 2, !dbg !22

Is there any way to avoid the type and operation extension? Thanks for 
your help!

-- 
Juan Fernando Eusse




More information about the cfe-users mailing list