Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix codegen for comparisons to be able to handle refs #7065

Merged
merged 6 commits into from
Aug 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 44 additions & 20 deletions compiler/codegen/expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3819,16 +3819,22 @@ GenRet CallExpr::codegenPrimitive() {
break;

case PRIM_LESSOREQUAL: {
GenRet a = codegenValue(get(1));
GenRet b = codegenValue(get(2));
GenRet a = get(1);
GenRet b = get(2);

if (a.chplType && a.chplType->symbol->isRefOrWideRef()) a = codegenDeref(a);
if (b.chplType && b.chplType->symbol->isRefOrWideRef()) b = codegenDeref(b);

GenRet av = codegenValue(a);
GenRet bv = codegenValue(b);

if (gGenInfo->cfile) {
ret.c = "(" + a.c + " <= " + b.c + ")";
ret.c = "(" + av.c + " <= " + bv.c + ")";
} else {
#ifdef HAVE_LLVM
PromotedPair values = convertValuesToLarger(
a.val,
b.val,
av.val,
bv.val,
is_signed(get(1)->typeInfo()),
is_signed(get(2)->typeInfo()));

Expand All @@ -3848,16 +3854,22 @@ GenRet CallExpr::codegenPrimitive() {
}

case PRIM_GREATEROREQUAL: {
GenRet a = codegenValue(get(1));
GenRet b = codegenValue(get(2));
GenRet a = get(1);
GenRet b = get(2);

if (a.chplType && a.chplType->symbol->isRefOrWideRef()) a = codegenDeref(a);
if (b.chplType && b.chplType->symbol->isRefOrWideRef()) b = codegenDeref(b);

GenRet av = codegenValue(a);
GenRet bv = codegenValue(b);

if (gGenInfo->cfile) {
ret.c = "(" + a.c + " >= " + b.c + ")";
ret.c = "(" + av.c + " >= " + bv.c + ")";
} else {
#ifdef HAVE_LLVM
PromotedPair values = convertValuesToLarger(
a.val,
b.val,
av.val,
bv.val,
is_signed(get(1)->typeInfo()),
is_signed(get(2)->typeInfo()));

Expand All @@ -3877,16 +3889,22 @@ GenRet CallExpr::codegenPrimitive() {
}

case PRIM_LESS: {
GenRet a = codegenValue(get(1));
GenRet b = codegenValue(get(2));
GenRet a = get(1);
GenRet b = get(2);

if (a.chplType && a.chplType->symbol->isRefOrWideRef()) a = codegenDeref(a);
if (b.chplType && b.chplType->symbol->isRefOrWideRef()) b = codegenDeref(b);

GenRet av = codegenValue(a);
GenRet bv = codegenValue(b);

if (gGenInfo->cfile) {
ret.c = "(" + a.c + " < " + b.c + ")";
ret.c = "(" + av.c + " < " + bv.c + ")";
} else {
#ifdef HAVE_LLVM
PromotedPair values = convertValuesToLarger(
a.val,
b.val,
av.val,
bv.val,
is_signed(get(1)->typeInfo()),
is_signed(get(2)->typeInfo()));

Expand All @@ -3906,16 +3924,22 @@ GenRet CallExpr::codegenPrimitive() {
}

case PRIM_GREATER: {
GenRet a = codegenValue(get(1));
GenRet b = codegenValue(get(2));
GenRet a = get(1);
GenRet b = get(2);

if (a.chplType && a.chplType->symbol->isRefOrWideRef()) a = codegenDeref(a);
if (b.chplType && b.chplType->symbol->isRefOrWideRef()) b = codegenDeref(b);

GenRet av = codegenValue(a);
GenRet bv = codegenValue(b);

if (gGenInfo->cfile) {
ret.c = "(" + a.c + " > " + b.c + ")";
ret.c = "(" + av.c + " > " + bv.c + ")";
} else {
#ifdef HAVE_LLVM
PromotedPair values = convertValuesToLarger(
a.val,
b.val,
av.val,
bv.val,
is_signed(get(1)->typeInfo()),
is_signed(get(2)->typeInfo()));

Expand Down
11 changes: 11 additions & 0 deletions test/users/engin/refComparison.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
proc foo() {
var a = 10;
on Locales[0] {
writeln(a>10);
writeln(a>=10);
writeln(a<10);
writeln(a<=10);
}
}

foo();
4 changes: 4 additions & 0 deletions test/users/engin/refComparison.good
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
false
true
false
true