@@ -2617,6 +2617,74 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
2617
2617
use IntPredicate :: * ;
2618
2618
assert_ty_eq ! ( self , lhs. ty, rhs. ty) ;
2619
2619
let b = SpirvType :: Bool . def ( self . span ( ) , self ) ;
2620
+
2621
+ if let Some ( const_lhs) = self . try_get_const_value ( lhs) {
2622
+ if let Some ( const_rhs) = self . try_get_const_value ( rhs) {
2623
+ let const_result = match self . lookup_type ( lhs. ty ) {
2624
+ SpirvType :: Integer ( _, _) => match ( const_lhs, const_rhs, op) {
2625
+ ( ConstValue :: Unsigned ( lhs) , ConstValue :: Unsigned ( rhs) , IntEQ ) => {
2626
+ Some ( lhs. eq ( & rhs) )
2627
+ }
2628
+ ( ConstValue :: Signed ( lhs) , ConstValue :: Signed ( rhs) , IntEQ ) => {
2629
+ Some ( lhs. eq ( & rhs) )
2630
+ }
2631
+ ( ConstValue :: Unsigned ( lhs) , ConstValue :: Unsigned ( rhs) , IntNE ) => {
2632
+ Some ( lhs. ne ( & rhs) )
2633
+ }
2634
+ ( ConstValue :: Signed ( lhs) , ConstValue :: Signed ( rhs) , IntNE ) => {
2635
+ Some ( lhs. ne ( & rhs) )
2636
+ }
2637
+ ( ConstValue :: Unsigned ( lhs) , ConstValue :: Unsigned ( rhs) , IntUGT ) => {
2638
+ Some ( lhs. gt ( & rhs) )
2639
+ }
2640
+ ( ConstValue :: Unsigned ( lhs) , ConstValue :: Unsigned ( rhs) , IntUGE ) => {
2641
+ Some ( lhs. ge ( & rhs) )
2642
+ }
2643
+ ( ConstValue :: Unsigned ( lhs) , ConstValue :: Unsigned ( rhs) , IntULT ) => {
2644
+ Some ( lhs. lt ( & rhs) )
2645
+ }
2646
+ ( ConstValue :: Unsigned ( lhs) , ConstValue :: Unsigned ( rhs) , IntULE ) => {
2647
+ Some ( lhs. le ( & rhs) )
2648
+ }
2649
+ ( ConstValue :: Signed ( lhs) , ConstValue :: Signed ( rhs) , IntUGT ) => {
2650
+ Some ( lhs. gt ( & rhs) )
2651
+ }
2652
+ ( ConstValue :: Signed ( lhs) , ConstValue :: Signed ( rhs) , IntUGE ) => {
2653
+ Some ( lhs. ge ( & rhs) )
2654
+ }
2655
+ ( ConstValue :: Signed ( lhs) , ConstValue :: Signed ( rhs) , IntULT ) => {
2656
+ Some ( lhs. lt ( & rhs) )
2657
+ }
2658
+ ( ConstValue :: Signed ( lhs) , ConstValue :: Signed ( rhs) , IntULE ) => {
2659
+ Some ( lhs. le ( & rhs) )
2660
+ }
2661
+ ( _, _, _) => None ,
2662
+ } ,
2663
+ SpirvType :: Bool => match ( const_lhs, const_rhs, op) {
2664
+ ( ConstValue :: Bool ( lhs) , ConstValue :: Bool ( rhs) , IntEQ ) => Some ( lhs. eq ( & rhs) ) ,
2665
+ ( ConstValue :: Bool ( lhs) , ConstValue :: Bool ( rhs) , IntNE ) => Some ( lhs. ne ( & rhs) ) ,
2666
+ ( ConstValue :: Bool ( lhs) , ConstValue :: Bool ( rhs) , IntUGT ) => {
2667
+ Some ( lhs. gt ( & rhs) )
2668
+ }
2669
+ ( ConstValue :: Bool ( lhs) , ConstValue :: Bool ( rhs) , IntUGE ) => {
2670
+ Some ( lhs. ge ( & rhs) )
2671
+ }
2672
+ ( ConstValue :: Bool ( lhs) , ConstValue :: Bool ( rhs) , IntULT ) => {
2673
+ Some ( lhs. lt ( & rhs) )
2674
+ }
2675
+ ( ConstValue :: Bool ( lhs) , ConstValue :: Bool ( rhs) , IntULE ) => {
2676
+ Some ( lhs. le ( & rhs) )
2677
+ }
2678
+ ( _, _, _) => None ,
2679
+ } ,
2680
+ _ => None ,
2681
+ } ;
2682
+ if let Some ( result) = const_result {
2683
+ return self . const_bool ( result) ;
2684
+ }
2685
+ }
2686
+ }
2687
+
2620
2688
match self . lookup_type ( lhs. ty ) {
2621
2689
SpirvType :: Integer ( _, _) => match op {
2622
2690
IntEQ => self . emit ( ) . i_equal ( b, None , lhs. def ( self ) , rhs. def ( self ) ) ,
0 commit comments