Skip to content

Commit

Permalink
Add ext (#332)
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmoses authored Jun 24, 2023
1 parent 7515cc6 commit e288f7b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions tools/cgeist/Lib/clang-mlir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2575,7 +2575,7 @@ ValueCategory MLIRScanner::VisitAtomicExpr(clang::AtomicExpr *BO) {
ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) {
auto loc = getMLIRLocation(BO->getExprLoc());

auto fixInteger = [&](mlir::Value res) {
auto fixInteger = [&](mlir::Value res, bool forceUnsigned = false) {
auto prevTy = res.getType().cast<mlir::IntegerType>();
auto postTy = getMLIRType(BO->getType()).cast<mlir::IntegerType>();
bool signedType = true;
Expand All @@ -2585,6 +2585,8 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) {
if (bit->isSignedInteger())
signedType = true;
}
if (forceUnsigned)
signedType = false;
if (postTy != prevTy) {
if (signedType) {
res = builder.create<mlir::arith::ExtSIOp>(loc, postTy, res);
Expand Down Expand Up @@ -2838,7 +2840,7 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) {
} else {
res = builder.create<arith::CmpIOp>(loc, IPred, lhs_v, rhs_v);
}
return fixInteger(res);
return fixInteger(res, /*forceUnsigned*/ true);
}
case clang::BinaryOperator::Opcode::BO_Mul: {
if (isa<clang::ComplexType>(BO->getType())) {
Expand Down
6 changes: 3 additions & 3 deletions tools/cgeist/Test/Verification/signcmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ unsigned int cmp2() {
// CHECK-NEXT: scf.if %[[V0]] {
// CHECK-NEXT: call @run() : () -> ()
// CHECK-NEXT: }
// CHECK-NEXT: %[[V1:.+]] = arith.extsi %[[V0]] : i1 to i32
// CHECK-NEXT: %[[V1:.+]] = arith.extui %[[V0]] : i1 to i32
// CHECK-NEXT: return %[[V1]] : i32
// CHECK-NEXT: }
// CHECK: func @cmp2() -> i32
// CHECK-NEXT: %c-1_i32 = arith.constant -1 : i32
// CHECK-NEXT: %c1_i32 = arith.constant 1 : i32
// CHECK-NEXT: call @run() : () -> ()
// CHECK-NEXT: return %c-1_i32 : i32
// CHECK-NEXT: return %c1_i32 : i32
// CHECK-NEXT: }

0 comments on commit e288f7b

Please sign in to comment.