[llvm] [KnownBits] Add fast path for udiv by pow2 and overloads for shift ops by constant (PR #189779)
Max Graey via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 2 09:39:34 PDT 2026
MaxGraey wrote:
It looks [like this change](https://github.com/llvm/llvm-project/pull/189779/changes#diff-e6db17dae29e7ff730beec131ac8340805eea3252166d2fe57600ff0a251249cR790):
```diff
- Known = KnownBits::shl(Known,
- KnownBits::makeConstant(APInt(BitWidth, ShiftAmt)),
+ Known = KnownBits::shl(Known, ShiftAmt,
/* NUW */ IOp->hasNoUnsignedWrap(),
/* NSW */ IOp->hasNoSignedWrap());
```
lead to regression for constant folding in [InstCombine/select-obo-peo-ops.ll](https://github.com/llvm/llvm-project/blob/main/llvm/test/Transforms/InstCombine/select-obo-peo-ops.ll#L140):
```diff
define i32 @test_shl_nuw_nsw__nsw_is_safe(i32 %x) {
+; CHECK-LABEL: @test_shl_nuw_nsw__nsw_is_safe(
+; CHECK-NEXT: [[TMP1:%.*]] = or i32 [[X:%.*]], -83886080
+; CHECK-NEXT: [[TMP2:%.*]] = shl nsw i32 [[TMP1]], 2
+; CHECK-NEXT: [[TMP3:%.*]] = mul i32 [[TMP2]], [[TMP1]]
+; CHECK-NEXT: [[TMP4:%.*]] = mul i32 [[TMP3]], [[TMP2]]
-; CHECK-NEXT: ret i32 [[TMP4]]
;
%1 = or i32 %x, -83886080
%2 = icmp eq i32 %1, -83886079
```
```diff
define i32 @test_shl_nuw__nsw_is_safe(i32 %x) {
+; CHECK-LABEL: @test_shl_nuw__nsw_is_safe(
+; CHECK-NEXT: [[TMP1:%.*]] = or i32 [[X:%.*]], -83886080
+; CHECK-NEXT: [[TMP2:%.*]] = shl nsw i32 [[TMP1]], 2
+; CHECK-NEXT: [[TMP3:%.*]] = mul i32 [[TMP2]], [[TMP1]]
+; CHECK-NEXT: [[TMP4:%.*]] = mul i32 [[TMP3]], [[TMP2]]
-; CHECK-NEXT: ret i32 [[TMP4]]
;
%1 = or i32 %x, -83886080
%2 = icmp eq i32 %1, -83886079
```
https://github.com/llvm/llvm-project/pull/189779
More information about the llvm-commits
mailing list