[LLVMdev] Troubling promotion of return value to Integer ...

Alireza.Moshtaghi at microchip.com Alireza.Moshtaghi at microchip.com
Tue May 20 14:16:12 PDT 2008


>Ok, I'm not sure what issue you mean.  Can you restate?

I'm referring to your statement (below) where you say "there needs to be
some attribute (or something) on foo". What I don't understand is I
don't know who would be setting this attribute? Whatever you do, if you
consider caller and callee are in different translation units, then all
that we can know in the caller is whether the return value has been
extended or not. But we don't know if it is sign extended or zero
extended.

	"
	define i32 @bar() {
  	; call
  	%tmp = call i32 @foo()
  	%x = trunc i32 %tmp to i8


  	; return
  	%tmp2 = sext i8 to i32
  	ret i32 %tmp2
	}
	The problem with this is that we now have a trunc+sext
instruction 	that cannot be eliminated.  The loss here is that while
foo returns an 	i32 value, we lost the fact that the top 25 bits all
have the same 	value (i.e. that it is a sign extended 8-bit value).
Because of this, 	we can't eliminate the trunc+sext pair in bar,
pessimizing code (and 	in a very common case!).  I am just saying that
we should have some 	attribute (or something) on foo that indicates
its result is actually 	sign extended, allowing the optimizer to zap the
trunc+sext in bar.
	"





More information about the llvm-dev mailing list