Minor changes.
[oota-llvm.git] / test / select.ll
index 69f794f84a575a9de2a82ebc9c4e8ff378244312..6be90ff0bdf9fa60d82c0a2ca92e3372c7854b36 100644 (file)
@@ -1,3 +1,5 @@
+%AConst    = constant int 123
+
 implementation
 
 ; A SetCC whose result is used should produce instructions to
@@ -15,29 +17,65 @@ begin
 end
 
 ; A constant argument to a Phi produces a Cast instruction in the
-; corresponding predecessor basic block.  This has little to do with
-; selection but the code is a bit weird.
+; corresponding predecessor basic block.  This checks a few things:
+; -- phi arguments coming from the bottom of the same basic block
+;    (they should not be forward substituted in the machine code!)
+; -- code generation for casts of various types
+; -- use of immediate fields for integral constants of different sizes
+; -- branch on a constant condition
 ; 
 void "mergeConstants"(int * %x, int * %y)
 begin
-; <label>:0                                            ;         [#uses=1]
+; <label>:0
        br label %Top
-Top:                                                   ;         [#uses=4]
-       phi int [ 0, %0 ], [ 1, %Top ], [ 2, %Next ]    ; <int>:0 [#uses=0]
+Top:
+       phi int    [ 0,    %0 ], [ 1,    %Top ], [ 524288, %Next ]
+       phi float  [ 0.0,  %0 ], [ 1.0,  %Top ], [ 2.0,    %Next ]
+       phi double [ 0.5,  %0 ], [ 1.5,  %Top ], [ 2.5,    %Next ]
+       phi bool   [ true, %0 ], [ false,%Top ], [ true,   %Next ]
        br bool true, label %Top, label %Next
-Next:                                                  ;         [#uses=2]
+Next:
        br label %Top
 end
 
 
+
+; A constant argument to a cast used only once should be forward substituted
+; and loaded where needed, which happens is:
+; -- User of cast has no immediate field
+; -- User of cast has immediate field but constant is too large to fit
+;    or constant is not resolved until later (e.g., global address)
+; -- User of cast uses it as a call arg. or return value so it is an implicit
+;    use but has to be loaded into a virtual register so that the reg.
+;    allocator can allocate the appropriate phys. reg. for it
+;  
+int* "castconst"(float)
+begin
+; <label>:0
+       %castbig   = cast ulong 99999999 to int
+       %castsmall = cast ulong 1        to int
+       %usebig    = add int %castbig, %castsmall
+               
+       %castglob = cast int* %AConst to long*
+       %dummyl   = load long* %castglob
+       
+       %castnull = cast ulong 0 to int*
+       ret int* %castnull
+end
+
+
+
 ; Test branch-on-comparison-with-zero, in two ways:
 ; 1. can be folded
 ; 2. cannot be folded because result of comparison is used twice
 ;
 void "testbool"(int, int)   ; Def %0, %1
-       int 0          ; Def 2
-       int -4         ; Def 3
+       const int 0          ; Def 2
+       const int -4         ; Def 3
 begin
+; <label>:0
+       br label %Top
+Top:
        add int %0, %1    ; Def 4
        sub int %4, %3    ; Def 5
        setle int %5, %2  ; Def 0 - bool plane
@@ -48,7 +86,7 @@ loop:
        sub int %4, %3    ; Def 7
        setle int %7, %2  ; Def 1 - bool
        not bool %1               ; Def 2 - bool. first use of bool %1
-       br bool %1, label %loop, label %   ;  second use of bool %1
+       br bool %1, label %loop, label %Top   ;  second use of bool %1
 
 retlbl:
        ret void
@@ -59,11 +97,14 @@ end
 ;
 void "testfloatbool"(float %x, float %y)   ; Def %0, %1 - float
 begin
+; <label>:0
+       br label %Top
+Top:
        %p = add float %x, %y    ; Def 2 - float
        %z = sub float %x, %y    ; Def 3 - float
        %b = setle float %p, %z  ; Def 0 - bool
        %c = not bool %b         ; Def 1 - bool
-       br bool %b, label %0, label %goon
+       br bool %b, label %Top, label %goon
 goon:
        ret void
 end
@@ -71,10 +112,12 @@ end
 
 ; Test cases where an LLVM instruction requires no machine
 ; instructions (e.g., cast int* to long).  But there are 2 cases:
-; 1. If the result register has only a single use, the operand will be
-;    copy-propagated during instruction selection.
-; 2. If the result register has multiple uses, it cannot be copy 
-;    propagated during instruction selection.  It will generate a
+; 1. If the result register has only a single use and the use is in the
+;    same basic block, the operand will be copy-propagated during
+;    instruction selection.
+; 2. If the result register has multiple uses or is in a different
+;    basic block, it cannot (or will not) be copy propagated during
+;    instruction selection.  It will generate a
 ;    copy instruction (add-with-0), but this copy should get coalesced
 ;    away by the register allocator.
 ;