[llvm] b5137ff - [TableGen] Optimize APInt |= with setBit. NFC

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 18 23:26:06 PDT 2022


Author: Fangrui Song
Date: 2022-09-18T23:25:58-07:00
New Revision: b5137ffd8367404ff35631b170bc9a29e9ff5c04

URL: https://github.com/llvm/llvm-project/commit/b5137ffd8367404ff35631b170bc9a29e9ff5c04
DIFF: https://github.com/llvm/llvm-project/commit/b5137ffd8367404ff35631b170bc9a29e9ff5c04.diff

LOG: [TableGen] Optimize APInt |= with setBit. NFC

Added: 
    

Modified: 
    llvm/utils/TableGen/CodeEmitterGen.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/utils/TableGen/CodeEmitterGen.cpp b/llvm/utils/TableGen/CodeEmitterGen.cpp
index 1d00c3cfd069..004f94f18b76 100644
--- a/llvm/utils/TableGen/CodeEmitterGen.cpp
+++ b/llvm/utils/TableGen/CodeEmitterGen.cpp
@@ -370,8 +370,8 @@ void CodeEmitterGen::emitInstructionBaseValues(
     // Start by filling in fixed values.
     APInt Value(BitWidth, 0);
     for (unsigned i = 0, e = BI->getNumBits(); i != e; ++i) {
-      if (BitInit *B = dyn_cast<BitInit>(BI->getBit(e - i - 1)))
-        Value |= APInt(BitWidth, (uint64_t)B->getValue()) << (e - i - 1);
+      if (auto *B = dyn_cast<BitInit>(BI->getBit(i)); B && B->getValue())
+        Value.setBit(i);
     }
     o << "    ";
     emitInstBits(o, Value);


        


More information about the llvm-commits mailing list