Skip to content

Commit e288f7b

Browse files
authored
Add ext (#332)
1 parent 7515cc6 commit e288f7b

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

tools/cgeist/Lib/clang-mlir.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2575,7 +2575,7 @@ ValueCategory MLIRScanner::VisitAtomicExpr(clang::AtomicExpr *BO) {
25752575
ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) {
25762576
auto loc = getMLIRLocation(BO->getExprLoc());
25772577

2578-
auto fixInteger = [&](mlir::Value res) {
2578+
auto fixInteger = [&](mlir::Value res, bool forceUnsigned = false) {
25792579
auto prevTy = res.getType().cast<mlir::IntegerType>();
25802580
auto postTy = getMLIRType(BO->getType()).cast<mlir::IntegerType>();
25812581
bool signedType = true;
@@ -2585,6 +2585,8 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) {
25852585
if (bit->isSignedInteger())
25862586
signedType = true;
25872587
}
2588+
if (forceUnsigned)
2589+
signedType = false;
25882590
if (postTy != prevTy) {
25892591
if (signedType) {
25902592
res = builder.create<mlir::arith::ExtSIOp>(loc, postTy, res);
@@ -2838,7 +2840,7 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) {
28382840
} else {
28392841
res = builder.create<arith::CmpIOp>(loc, IPred, lhs_v, rhs_v);
28402842
}
2841-
return fixInteger(res);
2843+
return fixInteger(res, /*forceUnsigned*/ true);
28422844
}
28432845
case clang::BinaryOperator::Opcode::BO_Mul: {
28442846
if (isa<clang::ComplexType>(BO->getType())) {

tools/cgeist/Test/Verification/signcmp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ unsigned int cmp2() {
1919
// CHECK-NEXT: scf.if %[[V0]] {
2020
// CHECK-NEXT: call @run() : () -> ()
2121
// CHECK-NEXT: }
22-
// CHECK-NEXT: %[[V1:.+]] = arith.extsi %[[V0]] : i1 to i32
22+
// CHECK-NEXT: %[[V1:.+]] = arith.extui %[[V0]] : i1 to i32
2323
// CHECK-NEXT: return %[[V1]] : i32
2424
// CHECK-NEXT: }
2525
// CHECK: func @cmp2() -> i32
26-
// CHECK-NEXT: %c-1_i32 = arith.constant -1 : i32
26+
// CHECK-NEXT: %c1_i32 = arith.constant 1 : i32
2727
// CHECK-NEXT: call @run() : () -> ()
28-
// CHECK-NEXT: return %c-1_i32 : i32
28+
// CHECK-NEXT: return %c1_i32 : i32
2929
// CHECK-NEXT: }

0 commit comments

Comments
 (0)