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