[LLVMdev] [RFC] Extend LLVM IR to express "fast-math" at a per-instruction level

Chris Lattner clattner at apple.com
Thu Nov 15 13:27:38 PST 2012


On Nov 14, 2012, at 1:39 PM, Michael Ilseman <milseman at apple.com> wrote:
> 
>>> Chris, what problem could be solved by adding extra operands to binary ops? I'm trying to avoid those sorts of modifications, as the fast-math flags could make sense applied to a variety operations, e.g. comparisons and casts.
>> 
>> How, specifically, are you proposing that these bits be encoded?
>> 
> 
> I'm new to the bitcode so let me know if this doesn't make sense. I was going to look at the encoding for nuw (OBO_NO_UNSIGNED_WRAP) and follow how it is encoded/decoded in the bitcode. I would then specify some kind of fast-math enum and encode it in a similar fashion.

Right, this is what I was suggesting. NSW and friends are handle with this code:

      assert(isa<BinaryOperator>(I) && "Unknown instruction!");
      Code = bitc::FUNC_CODE_INST_BINOP;
      if (!PushValueAndType(I.getOperand(0), InstID, Vals, VE))
        AbbrevToUse = FUNCTION_INST_BINOP_ABBREV;
      pushValue(I.getOperand(1), InstID, Vals, VE);
      Vals.push_back(GetEncodedBinaryOpcode(I.getOpcode()));
      uint64_t Flags = GetOptimizationFlags(&I);
      if (Flags != 0) {
        ...
        Vals.push_back(Flags);
      }

Basically, the Flags operand is added to the end of the operand list (before the bitcode record is written) if present.  That's what I meant as an "extra operand", but I see how that was probably *really* confusing :)

-Chris



More information about the llvm-dev mailing list