[GlobalISel] Add G_FSHL and G_FSHR to computeKnownBits#191260
Conversation
|
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
|
@llvm/pr-subscribers-llvm-support @llvm/pr-subscribers-llvm-globalisel Author: Ayaan (def3r) ChangesPorted impl from Tests are based on Ref: #150515 Full diff: https://github.com/llvm/llvm-project/pull/191260.diff 2 Files Affected:
diff --git a/llvm/lib/CodeGen/GlobalISel/GISelValueTracking.cpp b/llvm/lib/CodeGen/GlobalISel/GISelValueTracking.cpp
index f0b455fbdc7d0..cb1a46abdd086 100644
--- a/llvm/lib/CodeGen/GlobalISel/GISelValueTracking.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/GISelValueTracking.cpp
@@ -560,6 +560,40 @@ void GISelValueTracking::computeKnownBitsImpl(Register R, KnownBits &Known,
Known.One = Known.One.rotr(Amt);
break;
}
+ case TargetOpcode::G_FSHL:
+ case TargetOpcode::G_FSHR: {
+ MachineInstr *AmtOpMI = MRI.getVRegDef(MI.getOperand(3).getReg());
+ auto MaybeAmtOp = isConstantOrConstantSplatVector(*AmtOpMI, MRI);
+ if (!MaybeAmtOp)
+ break;
+
+ unsigned Amt = MaybeAmtOp->urem(BitWidth);
+
+ // For fshl, 0-shift returns the 1st arg.
+ // For fshr, 0-shift returns the 2nd arg.
+ if (Amt == 0) {
+ computeKnownBitsImpl(
+ MI.getOperand(Opcode == TargetOpcode::G_FSHL ? 1 : 2).getReg(), Known,
+ DemandedElts, Depth + 1);
+ break;
+ }
+
+ // fshl: (X << (Z % BW)) | (Y >> (BW - (Z % BW)))
+ // fshr: (X << (BW - (Z % BW))) | (Y >> (Z % BW))
+ computeKnownBitsImpl(MI.getOperand(1).getReg(), Known, DemandedElts,
+ Depth + 1);
+ computeKnownBitsImpl(MI.getOperand(2).getReg(), Known2, DemandedElts,
+ Depth + 1);
+ if (Opcode == TargetOpcode::G_FSHL) {
+ Known <<= Amt;
+ Known2 >>= BitWidth - Amt;
+ } else {
+ Known <<= BitWidth - Amt;
+ Known2 >>= Amt;
+ }
+ Known = Known.unionWith(Known2);
+ break;
+ }
case TargetOpcode::G_INTTOPTR:
case TargetOpcode::G_PTRTOINT:
if (DstTy.isVector())
diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/knownbits-fshl-fshr.mir b/llvm/test/CodeGen/AArch64/GlobalISel/knownbits-fshl-fshr.mir
new file mode 100644
index 0000000000000..202a40831145e
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/knownbits-fshl-fshr.mir
@@ -0,0 +1,295 @@
+# NOTE: Assertions have been autogenerated by utils/update_givaluetracking_test_checks.py UTC_ARGS: --version 6
+# RUN: llc -mtriple aarch64 -passes="print<gisel-value-tracking>" %s -o - 2>&1 | FileCheck %s
+
+---
+name: Cst
+body: |
+ bb.1:
+ ; CHECK-LABEL: name: @Cst
+ ; CHECK-NEXT: %0:_ KnownBits:11100000 SignBits:3
+ ; CHECK-NEXT: %1:_ KnownBits:00001111 SignBits:4
+ ; CHECK-NEXT: %2:_ KnownBits:00000010 SignBits:6
+ ; CHECK-NEXT: %3:_ KnownBits:10000000 SignBits:1
+ %0:_(s8) = G_CONSTANT i8 224
+ %1:_(s8) = G_CONSTANT i8 15
+ %2:_(s8) = G_CONSTANT i8 2
+ %3:_(s8) = G_FSHL %0, %1, %2
+...
+---
+name: CstBig
+body: |
+ bb.1:
+ ; CHECK-LABEL: name: @CstBig
+ ; CHECK-NEXT: %0:_ KnownBits:11111001 SignBits:5
+ ; CHECK-NEXT: %1:_ KnownBits:11100000 SignBits:3
+ ; CHECK-NEXT: %2:_ KnownBits:00000110 SignBits:5
+ ; CHECK-NEXT: %3:_ KnownBits:01111000 SignBits:1
+ %0:_(s8) = G_CONSTANT i8 249
+ %1:_(s8) = G_CONSTANT i8 224
+ %2:_(s8) = G_CONSTANT i8 6
+ %3:_(s8) = G_FSHL %0, %1, %2
+...
+---
+name: CstSext
+body: |
+ bb.1:
+ ; CHECK-LABEL: name: @CstSext
+ ; CHECK-NEXT: %0:_ KnownBits:10000001 SignBits:1
+ ; CHECK-NEXT: %1:_ KnownBits:00000100 SignBits:5
+ ; CHECK-NEXT: %2:_ KnownBits:11111000 SignBits:5
+ ; CHECK-NEXT: %3:_ KnownBits:11100000 SignBits:3
+ ; CHECK-NEXT: %4:_ KnownBits:00000011 SignBits:6
+ ; CHECK-NEXT: %5:_ KnownBits:11000111 SignBits:2
+ %0:_(s8) = G_CONSTANT i8 129
+ %1:_(s8) = G_CONSTANT i8 4
+ %2:_(s8) = G_ASHR %0, %1
+ %3:_(s8) = G_CONSTANT i8 224
+ %4:_(s8) = G_CONSTANT i8 3
+ %5:_(s8) = G_FSHL %2, %3, %4
+...
+---
+name: CstSextBig
+body: |
+ bb.1:
+ ; CHECK-LABEL: name: @CstSextBig
+ ; CHECK-NEXT: %0:_ KnownBits:10000001 SignBits:1
+ ; CHECK-NEXT: %1:_ KnownBits:00000100 SignBits:5
+ ; CHECK-NEXT: %2:_ KnownBits:11111000 SignBits:5
+ ; CHECK-NEXT: %3:_ KnownBits:11100000 SignBits:3
+ ; CHECK-NEXT: %4:_ KnownBits:00000110 SignBits:5
+ ; CHECK-NEXT: %5:_ KnownBits:00111000 SignBits:2
+ %0:_(s8) = G_CONSTANT i8 129
+ %1:_(s8) = G_CONSTANT i8 4
+ %2:_(s8) = G_ASHR %0, %1
+ %3:_(s8) = G_CONSTANT i8 224
+ %4:_(s8) = G_CONSTANT i8 6
+ %5:_(s8) = G_FSHL %2, %3, %4
+...
+---
+name: ScalarVar
+body: |
+ bb.1:
+ ; CHECK-LABEL: name: @ScalarVar
+ ; CHECK-NEXT: %0:_ KnownBits:???????? SignBits:1
+ ; CHECK-NEXT: %1:_ KnownBits:???????? SignBits:1
+ ; CHECK-NEXT: %2:_ KnownBits:???????? SignBits:1
+ %0:_(s8) = COPY $b0
+ %1:_(s8) = COPY $b1
+ %2:_(s8) = G_FSHL %0, %0, %1
+...
+---
+name: ScalarCst
+body: |
+ bb.1:
+ ; CHECK-LABEL: name: @ScalarCst
+ ; CHECK-NEXT: %0:_ KnownBits:???????? SignBits:1
+ ; CHECK-NEXT: %1:_ KnownBits:???????? SignBits:1
+ ; CHECK-NEXT: %2:_ KnownBits:00000011 SignBits:6
+ ; CHECK-NEXT: %3:_ KnownBits:???????? SignBits:1
+ %0:_(s8) = COPY $b0
+ %1:_(s8) = COPY $b1
+ %2:_(s8) = G_CONSTANT i8 3
+ %3:_(s8) = G_FSHL %0, %1, %2
+...
+---
+name: VectorSimple
+body: |
+ bb.1:
+ ; CHECK-LABEL: name: @VectorSimple
+ ; CHECK-NEXT: %0:_ KnownBits:0000000000010011 SignBits:11
+ ; CHECK-NEXT: %1:_ KnownBits:1111111100000000 SignBits:8
+ ; CHECK-NEXT: %2:_ KnownBits:0000000000000011 SignBits:14
+ ; CHECK-NEXT: %3:_ KnownBits:0000000000010011 SignBits:11
+ ; CHECK-NEXT: %4:_ KnownBits:1111111100000000 SignBits:8
+ ; CHECK-NEXT: %5:_ KnownBits:0000000000000011 SignBits:14
+ ; CHECK-NEXT: %6:_ KnownBits:0000000010011111 SignBits:8
+ %0:_(s16) = G_CONSTANT i16 19
+ %1:_(s16) = G_CONSTANT i16 65280
+ %2:_(s16) = G_CONSTANT i16 3
+ %3:_(<4 x s16>) = G_BUILD_VECTOR %0, %0, %0, %0
+ %4:_(<4 x s16>) = G_BUILD_VECTOR %1, %1, %1, %1
+ %5:_(<4 x s16>) = G_BUILD_VECTOR %2, %2, %2, %2
+ %6:_(<4 x s16>) = G_FSHL %3, %4, %5
+...
+---
+name: VectorCst
+body: |
+ bb.1:
+ ; CHECK-LABEL: name: @VectorCst
+ ; CHECK-NEXT: %0:_ KnownBits:???????????????? SignBits:1
+ ; CHECK-NEXT: %1:_ KnownBits:???????????????? SignBits:1
+ ; CHECK-NEXT: %2:_ KnownBits:0000000000000011 SignBits:14
+ ; CHECK-NEXT: %3:_ KnownBits:0000000000000011 SignBits:14
+ ; CHECK-NEXT: %4:_ KnownBits:???????????????? SignBits:1
+ %0:_(<4 x s16>) = COPY $d0
+ %1:_(<4 x s16>) = COPY $d1
+ %2:_(s16) = G_CONSTANT i16 3
+ %3:_(<4 x s16>) = G_BUILD_VECTOR %2, %2, %2, %2
+ %4:_(<4 x s16>) = G_FSHL %0, %1, %3
+...
+---
+name: VectorCst36
+body: |
+ bb.1:
+ ; CHECK-LABEL: name: @VectorCst36
+ ; CHECK-NEXT: %0:_ KnownBits:0000000000000011 SignBits:14
+ ; CHECK-NEXT: %1:_ KnownBits:0000000000000110 SignBits:13
+ ; CHECK-NEXT: %2:_ KnownBits:0000000000000?1? SignBits:13
+ ; CHECK-NEXT: %3:_ KnownBits:0000000000000?1? SignBits:13
+ ; CHECK-NEXT: %4:_ KnownBits:???????????????? SignBits:1
+ %0:_(s16) = G_CONSTANT i16 3
+ %1:_(s16) = G_CONSTANT i16 6
+ %2:_(<4 x s16>) = G_BUILD_VECTOR %0, %1, %1, %0
+ %3:_(<4 x s16>) = G_BUILD_VECTOR %0, %1, %1, %0
+ %4:_(<4 x s16>) = G_FSHL %2, %2, %3
+...
+---
+name: VectorCst3unknown
+body: |
+ bb.1:
+ ; CHECK-LABEL: name: @VectorCst3unknown
+ ; CHECK-NEXT: %0:_ KnownBits:???????????????? SignBits:1
+ ; CHECK-NEXT: %1:_ KnownBits:???????????????? SignBits:1
+ ; CHECK-NEXT: %2:_ KnownBits:???????????????? SignBits:1
+ ; CHECK-NEXT: %3:_ KnownBits:0000000000000011 SignBits:14
+ ; CHECK-NEXT: %4:_ KnownBits:???????????????? SignBits:1
+ ; CHECK-NEXT: %5:_ KnownBits:???????????????? SignBits:1
+ %0:_(<4 x s16>) = COPY $d0
+ %1:_(<4 x s16>) = COPY $d1
+ %2:_(s16) = COPY $h0
+ %3:_(s16) = G_CONSTANT i16 3
+ %4:_(<4 x s16>) = G_BUILD_VECTOR %2, %3, %3, %2
+ %5:_(<4 x s16>) = G_FSHL %0, %1, %4
+...
+---
+name: VectorSext
+body: |
+ bb.1:
+ ; CHECK-LABEL: name: @VectorSext
+ ; CHECK-NEXT: %0:_ KnownBits:11101110 SignBits:3
+ ; CHECK-NEXT: %1:_ KnownBits:00001111 SignBits:4
+ ; CHECK-NEXT: %2:_ KnownBits:1111111111101110 SignBits:11
+ ; CHECK-NEXT: %3:_ KnownBits:0000000000001111 SignBits:12
+ ; CHECK-NEXT: %4:_ KnownBits:1111111111101110 SignBits:11
+ ; CHECK-NEXT: %5:_ KnownBits:0000000000001111 SignBits:12
+ ; CHECK-NEXT: %6:_ KnownBits:0000000000000011 SignBits:14
+ ; CHECK-NEXT: %7:_ KnownBits:0000000000000110 SignBits:13
+ ; CHECK-NEXT: %8:_ KnownBits:0000000000000?1? SignBits:13
+ ; CHECK-NEXT: %9:_ KnownBits:???????????????? SignBits:1
+ %0:_(s8) = G_CONSTANT i8 238
+ %1:_(s8) = G_CONSTANT i8 15
+ %2:_(s16) = G_SEXT %0(s8)
+ %3:_(s16) = G_SEXT %1(s8)
+ %4:_(<4 x s16>) = G_BUILD_VECTOR %2, %2, %2, %2
+ %5:_(<4 x s16>) = G_BUILD_VECTOR %3, %3, %3, %3
+ %6:_(s16) = G_CONSTANT i16 3
+ %7:_(s16) = G_CONSTANT i16 6
+ %8:_(<4 x s16>) = G_BUILD_VECTOR %6, %7, %7, %6
+ %9:_(<4 x s16>) = G_FSHL %4, %5, %8
+...
+---
+name: FSHLless
+body: |
+ bb.1:
+ ; CHECK-LABEL: name: @FSHLless
+ ; CHECK-NEXT: %0:_ KnownBits:???????? SignBits:1
+ ; CHECK-NEXT: %1:_ KnownBits:???????? SignBits:1
+ ; CHECK-NEXT: %2:_ KnownBits:???????????????? SignBits:9
+ ; CHECK-NEXT: %3:_ KnownBits:???????????????? SignBits:9
+ ; CHECK-NEXT: %4:_ KnownBits:0000000000000011 SignBits:14
+ ; CHECK-NEXT: %5:_ KnownBits:???????????????? SignBits:1
+ %0:_(s8) = COPY $b0
+ %1:_(s8) = COPY $b1
+ %2:_(s16) = G_SEXT %0(s8)
+ %3:_(s16) = G_SEXT %1(s8)
+ %4:_(s16) = G_CONSTANT i16 3
+ %5:_(s16) = G_FSHL %2, %3, %4
+...
+---
+name: FSHLeq
+body: |
+ bb.1:
+ ; CHECK-LABEL: name: @FSHLeq
+ ; CHECK-NEXT: %0:_ KnownBits:???????? SignBits:1
+ ; CHECK-NEXT: %1:_ KnownBits:???????? SignBits:1
+ ; CHECK-NEXT: %2:_ KnownBits:???????????????? SignBits:9
+ ; CHECK-NEXT: %3:_ KnownBits:???????????????? SignBits:9
+ ; CHECK-NEXT: %4:_ KnownBits:0000000000001000 SignBits:12
+ ; CHECK-NEXT: %5:_ KnownBits:???????????????? SignBits:1
+ %0:_(s8) = COPY $b0
+ %1:_(s8) = COPY $b1
+ %2:_(s16) = G_SEXT %0(s8)
+ %3:_(s16) = G_SEXT %1(s8)
+ %4:_(s16) = G_CONSTANT i16 8
+ %5:_(s16) = G_FSHL %2, %3, %4
+...
+---
+name: FSHLmore
+body: |
+ bb.1:
+ ; CHECK-LABEL: name: @FSHLmore
+ ; CHECK-NEXT: %0:_ KnownBits:???????? SignBits:1
+ ; CHECK-NEXT: %1:_ KnownBits:???????? SignBits:1
+ ; CHECK-NEXT: %2:_ KnownBits:???????????????? SignBits:9
+ ; CHECK-NEXT: %3:_ KnownBits:???????????????? SignBits:9
+ ; CHECK-NEXT: %4:_ KnownBits:0000000000001101 SignBits:12
+ ; CHECK-NEXT: %5:_ KnownBits:???????????????? SignBits:1
+ %0:_(s8) = COPY $b0
+ %1:_(s8) = COPY $b1
+ %2:_(s16) = G_SEXT %0(s8)
+ %3:_(s16) = G_SEXT %1(s8)
+ %4:_(s16) = G_CONSTANT i16 13
+ %5:_(s16) = G_FSHL %2, %3, %4
+...
+---
+name: SignBitsThroughZext
+body: |
+ bb.1:
+ ; CHECK-LABEL: name: @SignBitsThroughZext
+ ; CHECK-NEXT: %0:_ KnownBits:???????? SignBits:1
+ ; CHECK-NEXT: %1:_ KnownBits:???????? SignBits:1
+ ; CHECK-NEXT: %2:_ KnownBits:0000000000000011 SignBits:14
+ ; CHECK-NEXT: %3:_ KnownBits:???????? SignBits:4
+ ; CHECK-NEXT: %4:_ KnownBits:???????? SignBits:4
+ ; CHECK-NEXT: %5:_ KnownBits:00000000???????? SignBits:8
+ ; CHECK-NEXT: %6:_ KnownBits:00000000???????? SignBits:8
+ ; CHECK-NEXT: %7:_ KnownBits:0000000000001000 SignBits:12
+ ; CHECK-NEXT: %8:_ KnownBits:????????00000000 SignBits:1
+ %0:_(s8) = COPY $b0
+ %1:_(s8) = COPY $b1
+ %2:_(s16) = G_CONSTANT i16 3
+ %3:_(s8) = G_ASHR %0, %2
+ %4:_(s8) = G_ASHR %1, %2
+ %5:_(s16) = G_ZEXT %3
+ %6:_(s16) = G_ZEXT %4
+ %7:_(s16) = G_CONSTANT i16 8
+ %8:_(s16) = G_FSHL %5, %6, %7
+...
+---
+name: FSHLZeroAmt
+body: |
+ bb.1:
+ ; CHECK-LABEL: name: @FSHLZeroAmt
+ ; CHECK-NEXT: %0:_ KnownBits:11100010 SignBits:3
+ ; CHECK-NEXT: %1:_ KnownBits:00001111 SignBits:4
+ ; CHECK-NEXT: %2:_ KnownBits:00000000 SignBits:8
+ ; CHECK-NEXT: %3:_ KnownBits:11100010 SignBits:3
+ %0:_(s8) = G_CONSTANT i8 226
+ %1:_(s8) = G_CONSTANT i8 15
+ %2:_(s8) = G_CONSTANT i8 0
+ %3:_(s8) = G_FSHL %0, %1, %2
+...
+---
+name: FSHRZeroAmt
+body: |
+ bb.1:
+ ; CHECK-LABEL: name: @FSHRZeroAmt
+ ; CHECK-NEXT: %0:_ KnownBits:11100010 SignBits:3
+ ; CHECK-NEXT: %1:_ KnownBits:00001111 SignBits:4
+ ; CHECK-NEXT: %2:_ KnownBits:00000000 SignBits:8
+ ; CHECK-NEXT: %3:_ KnownBits:00001111 SignBits:4
+ %0:_(s8) = G_CONSTANT i8 226
+ %1:_(s8) = G_CONSTANT i8 15
+ %2:_(s8) = G_CONSTANT i8 0
+ %3:_(s8) = G_FSHR %0, %1, %2
+...
|
|
|
||
| KnownBits KnownBits::fshl(KnownBits LHS, KnownBits RHS, unsigned Amt) { | ||
| // fshl: (X << (Z % BW)) | (Y >> (BW - (Z % BW))) | ||
| if (Amt == 0) |
There was a problem hiding this comment.
These are general purpose utility functions so you need to do the Amt %= BitWidth here. Also please add some unit testing in unittests/Support/KnownBitsTest.cpp.
| @@ -673,6 +673,25 @@ TEST(KnownBitsTest, UnaryExhaustive) { | |||
| [](const APInt &N) { return N * N; }, /*CheckOptimality=*/false); | |||
| } | |||
|
|
|||
| TEST(KnownBitsTest, FunnelShift) { | |||
There was a problem hiding this comment.
Exhaustive testing would be even better. But I guess this is OK to start with.
|
ping |
| Known.setAllConflict(); | ||
|
|
||
| for (unsigned ShiftAmt = MinAmt; ShiftAmt <= MaxAmt; ++ShiftAmt) { | ||
| if ((ShiftAmtZeroMask & ShiftAmt) != 0 || |
There was a problem hiding this comment.
| if ((ShiftAmtZeroMask & ShiftAmt) != 0 || | |
| if (ShiftAmtZeroMask.intersects(ShiftAmt) || |
|
|
||
| for (unsigned ShiftAmt = MinAmt; ShiftAmt <= MaxAmt; ++ShiftAmt) { | ||
| if ((ShiftAmtZeroMask & ShiftAmt) != 0 || | ||
| (ShiftAmtOneMask | ShiftAmt) != ShiftAmt) |
There was a problem hiding this comment.
| (ShiftAmtOneMask | ShiftAmt) != ShiftAmt) | |
| (!ShiftAmtOneMask.isSubsetOf(ShiftAmt)) |
Not sure I got this exactly right, but something like this
There was a problem hiding this comment.
The masks are unsigned, and this is consistent with KnownBits::shl and KnownBits::lshr
llvm-project/llvm/lib/Support/KnownBits.cpp
Lines 470 to 483 in 980ddce
Should I instead use APInt for it?
There was a problem hiding this comment.
ShiftAmt can generally be a unsigned for shifts (types don't get that big, out of range shifts produce poison for shifts), but that isn't always true for funnel shifts. APInts will protect against converting i128 or other types larger than 64bits, and the shift amount is taken modulo the bitwidth.
| @@ -603,6 +603,60 @@ KnownBits KnownBits::ashr(const KnownBits &LHS, const KnownBits &RHS, | |||
| return Known; | |||
| } | |||
|
|
|||
| KnownBits KnownBits::fshl(const KnownBits &LHS, const KnownBits &RHS, | |||
There was a problem hiding this comment.
I'm assuming this was moved code from the IR copy, so any cleanups here would maybe be better done separately. However, I don't see the removal of the IR copy?
There was a problem hiding this comment.
I did not port this impl from anywhere (I'm not aware if there exists an impl to be ported for KnownBits). After adding exhaustive unit test for funnel shift, multiple tests failed. So I looked for impl similar to fshl. This is based on how KnownBits::shl and KnownBits::lshr are handled.
There was a problem hiding this comment.
There is a SDAG version in
And a ValueTracking/IR version in
llvm-project/llvm/lib/Analysis/ValueTracking.cpp
Line 2079 in 6c5b4a7
Could they use this new logic? It might be simpler to keep just the constant shift amount version as a first addition.
There was a problem hiding this comment.
llvm-project/llvm/lib/Analysis/ValueTracking.cpp
Line 2079 in 10f8205
We should only have one implementation here, not develop one for each of the 3 IRs
There was a problem hiding this comment.
I have updated both to use KnownBits::fshl and fshr, and kept only const shift amount impl in KnownBits.
🐧 Linux x64 Test Results
Failed Tests(click on a test name to see its output) LLVMLLVM.CodeGen/AMDGPU/GlobalISel/fshl.llLLVM.CodeGen/AMDGPU/GlobalISel/fshr.llIf these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the |
🪟 Windows x64 Test Results
Failed Tests(click on a test name to see its output) LLVMLLVM.CodeGen/AMDGPU/GlobalISel/fshl.llLLVM.CodeGen/AMDGPU/GlobalISel/fshr.llIf these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the |
|
|
||
| for (unsigned ShiftAmt = MinAmt; ShiftAmt <= MaxAmt; ++ShiftAmt) { | ||
| if ((ShiftAmtZeroMask & ShiftAmt) != 0 || | ||
| (ShiftAmtOneMask | ShiftAmt) != ShiftAmt) |
There was a problem hiding this comment.
ShiftAmt can generally be a unsigned for shifts (types don't get that big, out of range shifts produce poison for shifts), but that isn't always true for funnel shifts. APInts will protect against converting i128 or other types larger than 64bits, and the shift amount is taken modulo the bitwidth.
| return KnownBits(APIntOps::fshl(LHS.Zero, RHS.Zero, ShAmt), | ||
| APIntOps::fshl(LHS.One, RHS.One, ShAmt)); | ||
| } | ||
| unsigned BitWidth = LHS.getBitWidth(); |
There was a problem hiding this comment.
Is this code is current inaccessible, outside of the unit test? As the Amt is always a constant.
There was a problem hiding this comment.
Yup, I added it for unit tests, and GISel passes a const shift Amt
| @@ -603,6 +603,60 @@ KnownBits KnownBits::ashr(const KnownBits &LHS, const KnownBits &RHS, | |||
| return Known; | |||
| } | |||
|
|
|||
| KnownBits KnownBits::fshl(const KnownBits &LHS, const KnownBits &RHS, | |||
There was a problem hiding this comment.
There is a SDAG version in
And a ValueTracking/IR version in
llvm-project/llvm/lib/Analysis/ValueTracking.cpp
Line 2079 in 6c5b4a7
Could they use this new logic? It might be simpler to keep just the constant shift amount version as a first addition.
There was a problem hiding this comment.
Nit: move this outside the ShAmt loop?
There was a problem hiding this comment.
Shouldn't have lost this comment?
There was a problem hiding this comment.
Since computation was moved, I thought it made sense to remove the comment as well. Restored it now.
There was a problem hiding this comment.
It might work out simpler to just make this be const APInt &Amt to start with
|
@def3r Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
Ported impl from `SelectionDAG::computeKnownBits`. Tests are based on `AArch64/GlobalISel/knownbits-shl.mir` Ref: llvm#150515
Ported impl from `SelectionDAG::computeKnownBits`. Tests are based on `AArch64/GlobalISel/knownbits-shl.mir` Ref: llvm#150515
Ported impl from
SelectionDAG::computeKnownBits.Tests are based on
AArch64/GlobalISel/knownbits-shl.mirRef: #150515