@@ -2467,6 +2467,74 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
2467
2467
use IntPredicate :: * ;
2468
2468
assert_ty_eq ! ( self , lhs. ty, rhs. ty) ;
2469
2469
let b = SpirvType :: Bool . def ( self . span ( ) , self ) ;
2470
+
2471
+ if let Some ( const_lhs) = self . try_get_const_value ( lhs) {
2472
+ if let Some ( const_rhs) = self . try_get_const_value ( rhs) {
2473
+ let const_result = match self . lookup_type ( lhs. ty ) {
2474
+ SpirvType :: Integer ( _, _) => match ( const_lhs, const_rhs, op) {
2475
+ ( ConstValue :: Unsigned ( lhs) , ConstValue :: Unsigned ( rhs) , IntEQ ) => {
2476
+ Some ( lhs. eq ( & rhs) )
2477
+ }
2478
+ ( ConstValue :: Signed ( lhs) , ConstValue :: Signed ( rhs) , IntEQ ) => {
2479
+ Some ( lhs. eq ( & rhs) )
2480
+ }
2481
+ ( ConstValue :: Unsigned ( lhs) , ConstValue :: Unsigned ( rhs) , IntNE ) => {
2482
+ Some ( lhs. ne ( & rhs) )
2483
+ }
2484
+ ( ConstValue :: Signed ( lhs) , ConstValue :: Signed ( rhs) , IntNE ) => {
2485
+ Some ( lhs. ne ( & rhs) )
2486
+ }
2487
+ ( ConstValue :: Unsigned ( lhs) , ConstValue :: Unsigned ( rhs) , IntUGT ) => {
2488
+ Some ( lhs. gt ( & rhs) )
2489
+ }
2490
+ ( ConstValue :: Unsigned ( lhs) , ConstValue :: Unsigned ( rhs) , IntUGE ) => {
2491
+ Some ( lhs. ge ( & rhs) )
2492
+ }
2493
+ ( ConstValue :: Unsigned ( lhs) , ConstValue :: Unsigned ( rhs) , IntULT ) => {
2494
+ Some ( lhs. lt ( & rhs) )
2495
+ }
2496
+ ( ConstValue :: Unsigned ( lhs) , ConstValue :: Unsigned ( rhs) , IntULE ) => {
2497
+ Some ( lhs. le ( & rhs) )
2498
+ }
2499
+ ( ConstValue :: Signed ( lhs) , ConstValue :: Signed ( rhs) , IntUGT ) => {
2500
+ Some ( lhs. gt ( & rhs) )
2501
+ }
2502
+ ( ConstValue :: Signed ( lhs) , ConstValue :: Signed ( rhs) , IntUGE ) => {
2503
+ Some ( lhs. ge ( & rhs) )
2504
+ }
2505
+ ( ConstValue :: Signed ( lhs) , ConstValue :: Signed ( rhs) , IntULT ) => {
2506
+ Some ( lhs. lt ( & rhs) )
2507
+ }
2508
+ ( ConstValue :: Signed ( lhs) , ConstValue :: Signed ( rhs) , IntULE ) => {
2509
+ Some ( lhs. le ( & rhs) )
2510
+ }
2511
+ ( _, _, _) => None ,
2512
+ } ,
2513
+ SpirvType :: Bool => match ( const_lhs, const_rhs, op) {
2514
+ ( ConstValue :: Bool ( lhs) , ConstValue :: Bool ( rhs) , IntEQ ) => Some ( lhs. eq ( & rhs) ) ,
2515
+ ( ConstValue :: Bool ( lhs) , ConstValue :: Bool ( rhs) , IntNE ) => Some ( lhs. ne ( & rhs) ) ,
2516
+ ( ConstValue :: Bool ( lhs) , ConstValue :: Bool ( rhs) , IntUGT ) => {
2517
+ Some ( lhs. gt ( & rhs) )
2518
+ }
2519
+ ( ConstValue :: Bool ( lhs) , ConstValue :: Bool ( rhs) , IntUGE ) => {
2520
+ Some ( lhs. ge ( & rhs) )
2521
+ }
2522
+ ( ConstValue :: Bool ( lhs) , ConstValue :: Bool ( rhs) , IntULT ) => {
2523
+ Some ( lhs. lt ( & rhs) )
2524
+ }
2525
+ ( ConstValue :: Bool ( lhs) , ConstValue :: Bool ( rhs) , IntULE ) => {
2526
+ Some ( lhs. le ( & rhs) )
2527
+ }
2528
+ ( _, _, _) => None ,
2529
+ } ,
2530
+ _ => None ,
2531
+ } ;
2532
+ if let Some ( result) = const_result {
2533
+ return self . const_bool ( result) ;
2534
+ }
2535
+ }
2536
+ }
2537
+
2470
2538
match self . lookup_type ( lhs. ty ) {
2471
2539
SpirvType :: Integer ( _, _) => match op {
2472
2540
IntEQ => self . emit ( ) . i_equal ( b, None , lhs. def ( self ) , rhs. def ( self ) ) ,
0 commit comments