aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--qbe.c32
-rw-r--r--test/bitfield-assignment-sign-extend.qbe28
-rw-r--r--test/bitfield-compound-assign.qbe30
-rw-r--r--test/bitfield-integer-promotion.qbe17
-rw-r--r--test/bitfield-load-signed.qbe12
-rw-r--r--test/bitfield-load-unsigned.qbe12
-rw-r--r--test/builtin-alloca.qbe3
-rw-r--r--test/cast-bool-char.qbe9
-rw-r--r--test/common-real-int-sign.qbe8
-rw-r--r--test/common-real-unsigned-char.qbe12
-rw-r--r--test/compare-char.qbe10
-rw-r--r--test/float-to-uint32.qbe3
-rw-r--r--test/hello.qbe3
-rw-r--r--test/initializer-replace-local.qbe3
-rw-r--r--test/local-init.qbe23
-rw-r--r--test/sizeof-postfix.qbe3
-rw-r--r--test/struct-flexible-array.qbe18
-rw-r--r--test/struct-return-2.qbe10
-rw-r--r--test/subtract-pointer.qbe8
19 files changed, 104 insertions, 140 deletions
diff --git a/qbe.c b/qbe.c
index e5e6f15..12e2f37 100644
--- a/qbe.c
+++ b/qbe.c
@@ -423,10 +423,8 @@ ftou(struct func *f, int dst, int src, struct value *v)
struct block *join;
enum instkind op = src == 's' ? ISTOSI : IDTOSI;
- if (dst == 'w') {
- v = funcinst(f, op, 'l', v, NULL);
- return funcinst(f, ICOPY, 'w', v, NULL);
- }
+ if (dst == 'w')
+ return funcinst(f, op, 'l', v, NULL);
join = mkblock("ftou_join");
join->phi.blk[0] = mkblock("ftou_small");
@@ -488,15 +486,13 @@ convert(struct func *f, struct type *dst, struct type *src, struct value *l)
} else if (dst->prop & PROPINT) {
class = dst->size == 8 ? 'l' : 'w';
if (src->prop & PROPINT) {
- if (dst->size <= src->size) {
- op = ICOPY;
- } else {
- switch (src->size) {
- case 4: op = src->basic.issigned ? IEXTSW : IEXTUW; break;
- case 2: op = src->basic.issigned ? IEXTSH : IEXTUH; break;
- case 1: op = src->basic.issigned ? IEXTSB : IEXTUB; break;
- default: fatal("internal error; unknown int conversion");
- }
+ if (dst->size <= src->size)
+ return l;
+ switch (src->size) {
+ case 4: op = src->basic.issigned ? IEXTSW : IEXTUW; break;
+ case 2: op = src->basic.issigned ? IEXTSH : IEXTUH; break;
+ case 1: op = src->basic.issigned ? IEXTSB : IEXTUB; break;
+ default: fatal("internal error; unknown int conversion");
}
} else {
if (!dst->basic.issigned)
@@ -510,12 +506,10 @@ convert(struct func *f, struct type *dst, struct type *src, struct value *l)
return utof(f, class, src->size == 8 ? 'l' : 'w', l);
op = src->size == 8 ? ISLTOF : ISWTOF;
} else {
- if (src->size < dst->size)
- op = IEXTS;
- else if (src->size > dst->size)
- op = ITRUNCD;
- else
- op = ICOPY;
+ assert(src->prop & PROPFLOAT);
+ if (src->size == dst->size)
+ return l;
+ op = src->size < dst->size ? IEXTS : ITRUNCD;
}
}
diff --git a/test/bitfield-assignment-sign-extend.qbe b/test/bitfield-assignment-sign-extend.qbe
index c2af6b8..0a4d221 100644
--- a/test/bitfield-assignment-sign-extend.qbe
+++ b/test/bitfield-assignment-sign-extend.qbe
@@ -2,20 +2,18 @@ export
function w $main() {
@start.1
@body.2
- %.1 =l copy $s
- %.2 =l mul 0, 1
- %.3 =l add %.1, %.2
- %.4 =l copy %.3
- %.5 =w shl 15, 0
- %.6 =w shl %.5, 28
- %.7 =w sar %.6, 28
- %.8 =w and %.5, 15
- %.9 =w loadw %.4
- %.10 =w and %.9, 18446744073709551600
- %.11 =w or %.8, %.10
- storew %.11, %.4
- %.12 =w sub 0, 1
- %.13 =w cnew %.7, %.12
- ret %.13
+ %.1 =l mul 0, 1
+ %.2 =l add $s, %.1
+ %.3 =w shl 15, 0
+ %.4 =w shl %.3, 28
+ %.5 =w sar %.4, 28
+ %.6 =w and %.3, 15
+ %.7 =w loadw %.2
+ %.8 =w and %.7, 18446744073709551600
+ %.9 =w or %.6, %.8
+ storew %.9, %.2
+ %.10 =w sub 0, 1
+ %.11 =w cnew %.5, %.10
+ ret %.11
}
export data $s = align 4 { z 4 }
diff --git a/test/bitfield-compound-assign.qbe b/test/bitfield-compound-assign.qbe
index 6924502..4d49a6b 100644
--- a/test/bitfield-compound-assign.qbe
+++ b/test/bitfield-compound-assign.qbe
@@ -2,22 +2,20 @@ export
function $f() {
@start.1
@body.2
- %.1 =l copy $s
- %.2 =l mul 0, 1
- %.3 =l add %.1, %.2
- %.4 =l copy %.3
- %.5 =w loadw %.4
- %.6 =w shl %.5, 19
- %.7 =w sar %.6, 23
- %.8 =w add %.7, 3
- %.9 =w shl %.8, 4
- %.10 =w shl %.9, 19
- %.11 =w sar %.10, 23
- %.12 =w and %.9, 8176
- %.13 =w loadw %.4
- %.14 =w and %.13, 18446744073709543439
- %.15 =w or %.12, %.14
- storew %.15, %.4
+ %.1 =l mul 0, 1
+ %.2 =l add $s, %.1
+ %.3 =w loadw %.2
+ %.4 =w shl %.3, 19
+ %.5 =w sar %.4, 23
+ %.6 =w add %.5, 3
+ %.7 =w shl %.6, 4
+ %.8 =w shl %.7, 19
+ %.9 =w sar %.8, 23
+ %.10 =w and %.7, 8176
+ %.11 =w loadw %.2
+ %.12 =w and %.11, 18446744073709543439
+ %.13 =w or %.10, %.12
+ storew %.13, %.2
ret
}
export data $s = align 4 { z 4 }
diff --git a/test/bitfield-integer-promotion.qbe b/test/bitfield-integer-promotion.qbe
index e479e2f..993ca8d 100644
--- a/test/bitfield-integer-promotion.qbe
+++ b/test/bitfield-integer-promotion.qbe
@@ -3,15 +3,12 @@ function w $main() {
@start.1
@body.2
%.1 =w sub 0, 1
- %.2 =l copy $s
- %.3 =l mul 0, 1
- %.4 =l add %.2, %.3
- %.5 =l copy %.4
- %.6 =w loadw %.5
- %.7 =w shl %.6, 30
- %.8 =w shr %.7, 30
- %.9 =w copy %.8
- %.10 =w csgtw %.1, %.9
- ret %.10
+ %.2 =l mul 0, 1
+ %.3 =l add $s, %.2
+ %.4 =w loadw %.3
+ %.5 =w shl %.4, 30
+ %.6 =w shr %.5, 30
+ %.7 =w csgtw %.1, %.6
+ ret %.7
}
export data $s = align 4 { z 4 }
diff --git a/test/bitfield-load-signed.qbe b/test/bitfield-load-signed.qbe
index 87d1cf5..12b474f 100644
--- a/test/bitfield-load-signed.qbe
+++ b/test/bitfield-load-signed.qbe
@@ -2,13 +2,11 @@ export
function $f() {
@start.1
@body.2
- %.1 =l copy $s
- %.2 =l mul 0, 1
- %.3 =l add %.1, %.2
- %.4 =l copy %.3
- %.5 =w loadw %.4
- %.6 =w shl %.5, 13
- %.7 =w sar %.6, 17
+ %.1 =l mul 0, 1
+ %.2 =l add $s, %.1
+ %.3 =w loadw %.2
+ %.4 =w shl %.3, 13
+ %.5 =w sar %.4, 17
ret
}
export data $s = align 4 { z 4 }
diff --git a/test/bitfield-load-unsigned.qbe b/test/bitfield-load-unsigned.qbe
index 000ca11..decb72f 100644
--- a/test/bitfield-load-unsigned.qbe
+++ b/test/bitfield-load-unsigned.qbe
@@ -2,13 +2,11 @@ export
function $f() {
@start.1
@body.2
- %.1 =l copy $s
- %.2 =l mul 0, 1
- %.3 =l add %.1, %.2
- %.4 =l copy %.3
- %.5 =w loadw %.4
- %.6 =w shl %.5, 13
- %.7 =w shr %.6, 17
+ %.1 =l mul 0, 1
+ %.2 =l add $s, %.1
+ %.3 =w loadw %.2
+ %.4 =w shl %.3, 13
+ %.5 =w shr %.4, 17
ret
}
export data $s = align 4 { z 4 }
diff --git a/test/builtin-alloca.qbe b/test/builtin-alloca.qbe
index 877ed22..1eeef22 100644
--- a/test/builtin-alloca.qbe
+++ b/test/builtin-alloca.qbe
@@ -5,7 +5,6 @@ function $f() {
@body.2
%.2 =l extsw 32
%.3 =l alloc16 %.2
- %.4 =l copy %.3
- storel %.4, %.1
+ storel %.3, %.1
ret
}
diff --git a/test/cast-bool-char.qbe b/test/cast-bool-char.qbe
index 81d4eba..0e92c87 100644
--- a/test/cast-bool-char.qbe
+++ b/test/cast-bool-char.qbe
@@ -2,9 +2,8 @@ export
function w $main() {
@start.1
@body.2
- %.1 =w copy 256
- %.2 =w extub %.1
- %.3 =w cnew %.2, 0
- %.4 =w extub %.3
- ret %.4
+ %.1 =w extub 256
+ %.2 =w cnew %.1, 0
+ %.3 =w extub %.2
+ ret %.3
}
diff --git a/test/common-real-int-sign.qbe b/test/common-real-int-sign.qbe
index 09f4060..6de74a3 100644
--- a/test/common-real-int-sign.qbe
+++ b/test/common-real-int-sign.qbe
@@ -2,9 +2,7 @@ export
function w $main() {
@start.1
@body.2
- %.1 =w copy 0
- %.2 =w copy 0
- %.3 =w sub %.2, 1
- %.4 =w cugtw %.1, %.3
- ret %.4
+ %.1 =w sub 0, 1
+ %.2 =w cugtw 0, %.1
+ ret %.2
}
diff --git a/test/common-real-unsigned-char.qbe b/test/common-real-unsigned-char.qbe
index 4835e5a..574cde4 100644
--- a/test/common-real-unsigned-char.qbe
+++ b/test/common-real-unsigned-char.qbe
@@ -2,11 +2,9 @@ export
function w $main() {
@start.1
@body.2
- %.1 =w copy 1
- %.2 =w extub %.1
- %.3 =w copy 2
- %.4 =w extub %.3
- %.5 =w sub %.2, %.4
- %.6 =w csgtw %.5, 0
- ret %.6
+ %.1 =w extub 1
+ %.2 =w extub 2
+ %.3 =w sub %.1, %.2
+ %.4 =w csgtw %.3, 0
+ ret %.4
}
diff --git a/test/compare-char.qbe b/test/compare-char.qbe
index 33ccd4c..6cd4c7a 100644
--- a/test/compare-char.qbe
+++ b/test/compare-char.qbe
@@ -2,10 +2,8 @@ export
function w $main() {
@start.1
@body.2
- %.1 =w copy 0
- %.2 =w extub %.1
- %.3 =w copy 256
- %.4 =w extub %.3
- %.5 =w csltw %.2, %.4
- ret %.5
+ %.1 =w extub 0
+ %.2 =w extub 256
+ %.3 =w csltw %.1, %.2
+ ret %.3
}
diff --git a/test/float-to-uint32.qbe b/test/float-to-uint32.qbe
index a8463f3..2cfc65f 100644
--- a/test/float-to-uint32.qbe
+++ b/test/float-to-uint32.qbe
@@ -4,6 +4,5 @@ function w $f() {
@body.2
%.1 =s call $g()
%.2 =l stosi %.1
- %.3 =w copy %.2
- ret %.3
+ ret %.2
}
diff --git a/test/hello.qbe b/test/hello.qbe
index 1826315..9104b75 100644
--- a/test/hello.qbe
+++ b/test/hello.qbe
@@ -3,7 +3,6 @@ export
function w $main() {
@start.1
@body.2
- %.1 =l copy $.Lstring.2
- %.2 =w call $puts(l %.1)
+ %.1 =w call $puts(l $.Lstring.2)
ret 0
}
diff --git a/test/initializer-replace-local.qbe b/test/initializer-replace-local.qbe
index 316edb0..663dc39 100644
--- a/test/initializer-replace-local.qbe
+++ b/test/initializer-replace-local.qbe
@@ -16,7 +16,6 @@ function $f() {
%.7 =l add %.1, 5
storeb 0, %.7
%.8 =l add %.1, 1
- %.9 =w copy 97
- storeb %.9, %.8
+ storeb 97, %.8
ret
}
diff --git a/test/local-init.qbe b/test/local-init.qbe
index a8b919e..570d12d 100644
--- a/test/local-init.qbe
+++ b/test/local-init.qbe
@@ -3,19 +3,18 @@ function $f() {
@start.1
%.1 =l alloc8 32
@body.2
- %.2 =w copy 97
- storeb %.2, %.1
- %.3 =l add %.1, 1
- storeb 0, %.3
- %.4 =l add %.1, 2
- storeh 0, %.4
- %.5 =l add %.1, 4
- storew 0, %.5
- %.6 =l add %.1, 8
+ storeb 97, %.1
+ %.2 =l add %.1, 1
+ storeb 0, %.2
+ %.3 =l add %.1, 2
+ storeh 0, %.3
+ %.4 =l add %.1, 4
+ storew 0, %.4
+ %.5 =l add %.1, 8
+ storel 0, %.5
+ %.6 =l add %.1, 16
storel 0, %.6
- %.7 =l add %.1, 16
+ %.7 =l add %.1, 24
storel 0, %.7
- %.8 =l add %.1, 24
- storel 0, %.8
ret
}
diff --git a/test/sizeof-postfix.qbe b/test/sizeof-postfix.qbe
index d9eedd8..4b2636f 100644
--- a/test/sizeof-postfix.qbe
+++ b/test/sizeof-postfix.qbe
@@ -2,7 +2,6 @@ export
function w $f() {
@start.1
@body.2
- %.1 =w copy 4
- ret %.1
+ ret 4
}
export data $x = align 4 { z 4 }
diff --git a/test/struct-flexible-array.qbe b/test/struct-flexible-array.qbe
index 535c5d2..464bfa4 100644
--- a/test/struct-flexible-array.qbe
+++ b/test/struct-flexible-array.qbe
@@ -6,14 +6,12 @@ function w $f(l %.1) {
storel %.1, %.2
@body.2
%.3 =l loadl %.2
- %.4 =l copy %.3
- %.5 =l mul 4, 1
- %.6 =l add %.4, %.5
- %.7 =l copy %.6
- %.8 =l extsw 2
- %.9 =l mul %.8, 2
- %.10 =l add %.7, %.9
- %.11 =w loadsh %.10
- %.12 =w extsh %.11
- ret %.12
+ %.4 =l mul 4, 1
+ %.5 =l add %.3, %.4
+ %.6 =l extsw 2
+ %.7 =l mul %.6, 2
+ %.8 =l add %.5, %.7
+ %.9 =w loadsh %.8
+ %.10 =w extsh %.9
+ ret %.10
}
diff --git a/test/struct-return-2.qbe b/test/struct-return-2.qbe
index 1e8ad27..49cb817 100644
--- a/test/struct-return-2.qbe
+++ b/test/struct-return-2.qbe
@@ -4,10 +4,8 @@ function w $f() {
@start.1
@body.2
%.1 =:.1 call $g()
- %.2 =l copy %.1
- %.3 =l mul 4, 1
- %.4 =l add %.2, %.3
- %.5 =l copy %.4
- %.6 =w loadw %.5
- ret %.6
+ %.2 =l mul 4, 1
+ %.3 =l add %.1, %.2
+ %.4 =w loadw %.3
+ ret %.4
}
diff --git a/test/subtract-pointer.qbe b/test/subtract-pointer.qbe
index 0e7e9a3..6c4bdde 100644
--- a/test/subtract-pointer.qbe
+++ b/test/subtract-pointer.qbe
@@ -7,10 +7,8 @@ function $f(l %.1, l %.3) {
storel %.3, %.4
@body.2
%.5 =l loadl %.2
- %.6 =l copy %.5
- %.7 =l loadl %.4
- %.8 =l copy %.7
- %.9 =l sub %.6, %.8
- %.10 =l div %.9, 4
+ %.6 =l loadl %.4
+ %.7 =l sub %.5, %.6
+ %.8 =l div %.7, 4
ret
}