[PATCH] D88937: [KnownBits] Add a sextOrTrunc method

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 7 23:21:14 PDT 2020


lebedev.ri added a comment.

Seems fine



================
Comment at: llvm/unittests/Support/KnownBitsTest.cpp:205
 }
 
+TEST(KnownBitsTest, SExtOrTrunc) {
----------------
I guess i was thinking of something like this:
```
TEST(KnownBitsTest, GetMinMaxVal) {
  const unsigned NarrowerSize = 4;
  const unsigned BaseSize = 6;
  const unsigned WiderSize = 8;
  ForeachKnownBits(BaseSize, [&](const KnownBits &KnownBase) {
    for (unsigned Size : {NarrowerSize, BaseSize, WiderSize}) {
      KnownBits Test;
      if(Size == BaseSize)
        Test = KnownBase
      else
        Test = Size < BaseSize ? KnownBase.trunc(Size) :  KnownBase.sext(Size);
      EXPECT_EQ(Test, KnownBase.sextOrTrunc(Size));
    }
  });
}
```
which seems pretty tautological i guess, so maybe we should go with your test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88937/new/

https://reviews.llvm.org/D88937



More information about the llvm-commits mailing list