@@ -741,16 +741,18 @@ class FindIntrinsics : public IRMutator {
741
741
bool is_saturated = op->value .as <Max>() || op->value .as <Min>();
742
742
Expr a = lossless_cast (op->type , shift->args [0 ]);
743
743
Expr b = lossless_cast (op->type .with_code (shift->args [1 ].type ().code ()), shift->args [1 ]);
744
- // Doing the shift in the narrower type might introduce UB where
745
- // there was no UB before, so we need to make sure b is bounded.
746
- auto b_bounds = constant_integer_bounds (b);
747
- const int max_shift = op->type .bits () - 1 ;
748
-
749
- if (a.defined () && b.defined () && b_bounds >= -max_shift && b_bounds <= max_shift) {
750
- if (!is_saturated ||
751
- (shift->is_intrinsic (Call::rounding_shift_right) && can_prove (b >= 0 )) ||
752
- (shift->is_intrinsic (Call::rounding_shift_left) && can_prove (b <= 0 ))) {
753
- return mutate (Call::make (op->type , shift->name , {a, b}, Call::PureIntrinsic));
744
+ if (b.defined ()) {
745
+ // Doing the shift in the narrower type might introduce UB where
746
+ // there was no UB before, so we need to make sure b is bounded.
747
+ auto b_bounds = constant_integer_bounds (b);
748
+ const int max_shift = op->type .bits () - 1 ;
749
+
750
+ if (a.defined () && b_bounds >= -max_shift && b_bounds <= max_shift) {
751
+ if (!is_saturated ||
752
+ (shift->is_intrinsic (Call::rounding_shift_right) && can_prove (b >= 0 )) ||
753
+ (shift->is_intrinsic (Call::rounding_shift_left) && can_prove (b <= 0 ))) {
754
+ return mutate (Call::make (op->type , shift->name , {a, b}, Call::PureIntrinsic));
755
+ }
754
756
}
755
757
}
756
758
}
0 commit comments