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