@@ -3374,76 +3374,96 @@ def visit_Compare(self, node):
3374
3374
self .visit (node .left )
3375
3375
left = self .popValue ()
3376
3376
self .visit (node .comparators [0 ])
3377
- comparator = self .popValue ()
3377
+ right = self .popValue ()
3378
3378
op = node .ops [0 ]
3379
3379
3380
- if isinstance (op , ast .Gt ):
3381
- if IntegerType .isinstance (left .type ):
3382
- if F64Type .isinstance (comparator .type ):
3383
- self .emitFatalError (
3384
- "invalid rhs for comparison (f64 type and not i64 type)." ,
3385
- node )
3380
+ left_type = left .type
3381
+ right_type = right .type
3382
+
3383
+ if IntegerType .isinstance (left_type ) and F64Type .isinstance (right_type ):
3384
+ left = arith .SIToFPOp (self .getFloatType (), left ).result
3385
+ elif F64Type .isinstance (left_type ) and IntegerType .isinstance (
3386
+ right_type ):
3387
+ right = arith .SIToFPOp (self .getFloatType (), right ).result
3388
+ elif IntegerType .isinstance (left_type ) and IntegerType .isinstance (
3389
+ right_type ):
3390
+ if IntegerType (left_type ).width < IntegerType (right_type ).width :
3391
+ zeroext = IntegerType (left_type ).width == 1
3392
+ left = cc .CastOp (right_type ,
3393
+ left ,
3394
+ sint = not zeroext ,
3395
+ zint = zeroext ).result
3396
+ elif IntegerType (left_type ).width > IntegerType (right_type ).width :
3397
+ zeroext = IntegerType (right_type ).width == 1
3398
+ right = cc .CastOp (left_type ,
3399
+ right ,
3400
+ sint = not zeroext ,
3401
+ zint = zeroext ).result
3386
3402
3387
- self .pushValue (
3388
- arith .CmpIOp (self .getIntegerAttr (iTy , 4 ), left ,
3389
- comparator ).result )
3390
- elif F64Type .isinstance (left .type ):
3391
- if IntegerType .isinstance (comparator .type ):
3392
- comparator = arith .SIToFPOp (self .getFloatType (),
3393
- comparator ).result
3403
+ if isinstance (op , ast .Gt ):
3404
+ if F64Type .isinstance (left .type ):
3394
3405
self .pushValue (
3395
3406
arith .CmpFOp (self .getIntegerAttr (iTy , 2 ), left ,
3396
- comparator ).result )
3407
+ right ).result )
3408
+ else :
3409
+ self .pushValue (
3410
+ arith .CmpIOp (self .getIntegerAttr (iTy , 4 ), left ,
3411
+ right ).result )
3397
3412
return
3398
3413
3399
3414
if isinstance (op , ast .GtE ):
3400
- self .pushValue (
3401
- arith .CmpIOp (self .getIntegerAttr (iTy , 5 ), left ,
3402
- comparator ).result )
3415
+ if F64Type .isinstance (left .type ):
3416
+ self .pushValue (
3417
+ arith .CmpFOp (self .getIntegerAttr (iTy , 3 ), left ,
3418
+ right ).result )
3419
+ else :
3420
+ self .pushValue (
3421
+ arith .CmpIOp (self .getIntegerAttr (iTy , 5 ), left ,
3422
+ right ).result )
3403
3423
return
3404
3424
3405
3425
if isinstance (op , ast .Lt ):
3406
- self .pushValue (
3407
- arith .CmpIOp (self .getIntegerAttr (iTy , 2 ), left ,
3408
- comparator ).result )
3426
+ if F64Type .isinstance (left .type ):
3427
+ self .pushValue (
3428
+ arith .CmpFOp (self .getIntegerAttr (iTy , 4 ), left ,
3429
+ right ).result )
3430
+ else :
3431
+ self .pushValue (
3432
+ arith .CmpIOp (self .getIntegerAttr (iTy , 2 ), left ,
3433
+ right ).result )
3409
3434
return
3410
3435
3411
3436
if isinstance (op , ast .LtE ):
3412
- self .pushValue (
3413
- arith .CmpIOp (self .getIntegerAttr (iTy , 7 ), left ,
3414
- comparator ).result )
3437
+ if F64Type .isinstance (left .type ):
3438
+ self .pushValue (
3439
+ arith .CmpFOp (self .getIntegerAttr (iTy , 5 ), left ,
3440
+ right ).result )
3441
+ else :
3442
+ self .pushValue (
3443
+ arith .CmpIOp (self .getIntegerAttr (iTy , 7 ), left ,
3444
+ right ).result )
3415
3445
return
3416
3446
3417
3447
if isinstance (op , ast .NotEq ):
3418
- if F64Type .isinstance (left .type ) and IntegerType .isinstance (
3419
- comparator .type ):
3420
- left = arith .FPToSIOp (comparator .type , left ).result
3421
- if IntegerType (left .type ).width < IntegerType (
3422
- comparator .type ).width :
3423
- zeroext = IntegerType (left .type ).width == 1
3424
- left = cc .CastOp (comparator .type ,
3425
- left ,
3426
- sint = not zeroext ,
3427
- zint = zeroext ).result
3428
- self .pushValue (
3429
- arith .CmpIOp (self .getIntegerAttr (iTy , 1 ), left ,
3430
- comparator ).result )
3448
+ if F64Type .isinstance (left .type ):
3449
+ self .pushValue (
3450
+ arith .CmpFOp (self .getIntegerAttr (iTy , 6 ), left ,
3451
+ right ).result )
3452
+ else :
3453
+ self .pushValue (
3454
+ arith .CmpIOp (self .getIntegerAttr (iTy , 1 ), left ,
3455
+ right ).result )
3431
3456
return
3432
3457
3433
3458
if isinstance (op , ast .Eq ):
3434
- if F64Type .isinstance (left .type ) and IntegerType .isinstance (
3435
- comparator .type ):
3436
- left = arith .FPToSIOp (comparator .type , left ).result
3437
- if IntegerType (left .type ).width < IntegerType (
3438
- comparator .type ).width :
3439
- zeroext = IntegerType (left .type ).width == 1
3440
- left = cc .CastOp (comparator .type ,
3441
- left ,
3442
- sint = not zeroext ,
3443
- zint = zeroext ).result
3444
- self .pushValue (
3445
- arith .CmpIOp (self .getIntegerAttr (iTy , 0 ), left ,
3446
- comparator ).result )
3459
+ if F64Type .isinstance (left .type ):
3460
+ self .pushValue (
3461
+ arith .CmpFOp (self .getIntegerAttr (iTy , 1 ), left ,
3462
+ right ).result )
3463
+ else :
3464
+ self .pushValue (
3465
+ arith .CmpIOp (self .getIntegerAttr (iTy , 0 ), left ,
3466
+ right ).result )
3447
3467
return
3448
3468
3449
3469
def visit_AugAssign (self , node ):
0 commit comments