diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp index 787a38ffb7be6..60cf683d04a0c 100644 --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp @@ -111,18 +111,18 @@ static void generateInstSeqImpl(int64_t Val, const MCSubtargetInfo &STI, assert(IsRV64 && "Can't emit >32-bit imm for non-RV64 target"); // In the worst case, for a full 64-bit constant, a sequence of 8 instructions - // (i.e., LUI+ADDIW+SLLI+ADDI+SLLI+ADDI+SLLI+ADDI) has to be emitted. Note - // that the first two instructions (LUI+ADDIW) can contribute up to 32 bits + // (i.e., LUI+ADDI+SLLI+ADDI+SLLI+ADDI+SLLI+ADDI) has to be emitted. Note + // that the first two instructions (LUI+ADDI) can contribute up to 32 bits // while the following ADDI instructions contribute up to 12 bits each. // // On the first glance, implementing this seems to be possible by simply - // emitting the most significant 32 bits (LUI+ADDIW) followed by as many left - // shift (SLLI) and immediate additions (ADDI) as needed. However, due to the - // fact that ADDI performs a sign extended addition, doing it like that would - // only be possible when at most 11 bits of the ADDI instructions are used. - // Using all 12 bits of the ADDI instructions, like done by GAS, actually - // requires that the constant is processed starting with the least significant - // bit. + // emitting the most significant 32 bits (LUI+ADDI(W)) followed by as many + // left shift (SLLI) and immediate additions (ADDI) as needed. However, due to + // the fact that ADDI performs a sign extended addition, doing it like that + // would only be possible when at most 11 bits of the ADDI instructions are + // used. Using all 12 bits of the ADDI instructions, like done by GAS, + // actually requires that the constant is processed starting with the least + // significant bit. // // In the following, constants are processed from LSB to MSB but instruction // emission is performed from MSB to LSB by recursively calling @@ -145,7 +145,7 @@ static void generateInstSeqImpl(int64_t Val, const MCSubtargetInfo &STI, Val >>= ShiftAmount; // If the remaining bits don't fit in 12 bits, we might be able to reduce - // the // shift amount in order to use LUI which will zero the lower 12 + // the shift amount in order to use LUI which will zero the lower 12 // bits. if (ShiftAmount > 12 && !isInt<12>(Val)) { if (isInt<32>((uint64_t)Val << 12)) { @@ -344,8 +344,9 @@ InstSeq generateInstSeq(int64_t Val, const MCSubtargetInfo &STI) { // Perform optimization with BSETI in the Zbs extension. if (Res.size() > 2 && STI.hasFeature(RISCV::FeatureStdExtZbs)) { - // Create a simm32 value for LUI+ADDIW by forcing the upper 33 bits to zero. - // Xor that with original value to get which bits should be set by BSETI. + // Create a simm32 value for LUI+ADDI(W) by forcing the upper 33 bits to + // zero. Xor that with original value to get which bits should be set by + // BSETI. uint64_t Lo = Val & 0x7fffffff; uint64_t Hi = Val ^ Lo; assert(Hi != 0); @@ -372,8 +373,8 @@ InstSeq generateInstSeq(int64_t Val, const MCSubtargetInfo &STI) { // Perform optimization with BCLRI in the Zbs extension. if (Res.size() > 2 && STI.hasFeature(RISCV::FeatureStdExtZbs)) { - // Create a simm32 value for LUI+ADDIW by forcing the upper 33 bits to one. - // Xor that with original value to get which bits should be cleared by + // Create a simm32 value for LUI+ADDI(W) by forcing the upper 33 bits to + // one. Xor that with original value to get which bits should be cleared by // BCLRI. uint64_t Lo = Val | 0xffffffff80000000; uint64_t Hi = Val ^ Lo;