%AConst = constant int 123
+%Domain = type { sbyte*, int, int*, int, int, int*, %Domain* }
+
implementation
; Test setting values of different constants in registers.
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
; 1. can be folded
; 2. cannot be folded because result of comparison is used twice
;
-void "testbool"(int, int) ; Def %0, %1
- const int 0 ; Def 2
- const int -4 ; Def 3
-begin
-; <label>:0
+void "testbool"(int %A, int %B) {
br label %Top
Top:
- add int %0, %1 ; Def 4
- sub int %4, %3 ; Def 5
- setle int %5, %2 ; Def 0 - bool plane
- br bool %0, label %retlbl, label %loop
+ %D = add int %A, %B
+ %E = sub int %D, -4
+ %C = setle int %E, 0
+ br bool %C, label %retlbl, label %loop
loop:
- add int %0, %1 ; Def 6
- 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 %Top ; second use of bool %1
+ %F = add int %A, %B
+ %G = sub int %D, -4
+ %D = setle int %G, 0
+ %E = xor bool %D, true
+ br bool %E, label %loop, label %Top
retlbl:
ret void
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
%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
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