Fix Bug: Assembler/2003-05-12-MinIntProblem.llx
[oota-llvm.git] / test / LLC / select.ll
index f8454598d04503c25af097611fbb6c028fa6df6e..c3f53b5523a38e9bbede2529bb2c3dd554d289e0 100644 (file)
@@ -1,5 +1,7 @@
 %AConst    = constant int 123
 
+%Domain = type { sbyte*, int, int*, int, int, int*, %Domain* }
+
 implementation
 
 ; Test setting values of different constants in registers.
@@ -30,7 +32,7 @@ void "unusedBool"(int * %x, int * %y)
 begin
 ; <label>:0                            ;               [#uses=0]
        seteq int * %x, %y              ; <bool>:0      [#uses=1]
-       not bool %0                     ; <bool>:1      [#uses=0]
+       xor bool %0, true               ; <bool>:1      [#uses=0]
        setne int * %x, %y              ; <bool>:2      [#uses=0]
        ret void
 end
@@ -100,7 +102,7 @@ loop:
        %F = add int %A, %B
        %G = sub int %D, -4
        %D = setle int %G, 0
-       %E = not bool %D
+       %E = xor bool %D, true
        br bool %E, label %loop, label %Top
 
 retlbl:
@@ -108,6 +110,30 @@ retlbl:
 end
 
 
+;; Test use of a boolean result in cast operations.
+;; Requires converting a condition code result into a 0/1 value in a reg.
+;; 
+implementation
+
+int %castbool(int %A, int %B) {
+bb0:                                           ; [#uses=0]
+    %cond213 = setlt int %A, %B                        ; <bool> [#uses=1]
+    %cast110 = cast bool %cond213 to ubyte      ; <ubyte> [#uses=1]
+    %cast109 = cast ubyte %cast110 to int       ; <int> [#uses=1]
+    ret int %cast109
+}
+
+
+;; Test use of a boolean result in arithmetic and logical operations.
+;; Requires converting a condition code result into a 0/1 value in a reg.
+;; 
+bool %boolexpr(bool %b, int %N) {
+    %b2 = setge int %N, 0
+    %b3 = and bool %b, %b2
+    ret bool %b3
+}
+
+
 ; Test branch on floating point comparison
 ;
 void "testfloatbool"(float %x, float %y)   ; Def %0, %1 - float
@@ -118,7 +144,7 @@ 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
+       %c = xor bool %b, true   ; Def 1 - bool
        br bool %b, label %Top, label %goon
 goon:
        ret void
@@ -141,11 +167,41 @@ begin
 
 bb2:           ;;<label>
        %reg114 = shl int %N, ubyte 2           ;;
-       %cast115 = cast int %reg114 to int*     ;; reg114 will be propagated
-       %reg116 = add int* %A, %cast115         ;;
-       %reg118 = load int* %reg116             ;;
+       %cast115 = cast int %reg114 to long     ;; reg114 will be propagated
+       %cast116 = cast int* %A to long         ;; %A will be propagated 
+       %reg116  = add long %cast116, %cast115  ;;
+       %castPtr = cast long %reg116 to int*    ;; %A will be propagated 
+       %reg118 = load int* %castPtr            ;;
        %cast117 = cast int %reg118 to long     ;; reg118 will be copied 'cos
        %reg159 = add long 1234567, %cast117    ;;  cast117 has 2 uses, here
        %reg160 = add long 7654321, %cast117    ;;  and here.
        ret int 0
 end
+
+
+; Test case for unary NOT operation constructed from XOR.
+; 
+void "checkNot"(bool %b, int %i)
+begin
+       %notB = xor bool %b, true
+       %notI = xor int %i, -1
+       %F    = setge int %notI, 100
+       %J    = add int %i, %i
+       %andNotB = and bool %F, %notB           ;; should get folded with notB
+       %andNotI = and int %J, %notI            ;; should get folded with notI
+
+       %notB2 = xor bool true, %b              ;; should become XNOR
+       %notI2 = xor int -1, %i                 ;; should become XNOR
+
+       ret void
+end
+
+
+; Test case for folding getelementptr into a load/store
+;
+int "checkFoldGEP"(%Domain* %D, long %idx)
+begin
+        %reg841 = getelementptr %Domain* %D, long 0, ubyte 1
+        %reg820 = load int* %reg841
+        ret int %reg820
+end