|
| 1 | +===== Human ===== |
| 2 | + |
| 3 | +Your task is to read a code change from a commit and (1) determine the target lines for a directed compiler fuzzer to aim at, and (2) categorize the code change. |
| 4 | + |
| 5 | +First, you determine the target lines. |
| 6 | +The source code is from the LLVM project and implements mid-end optimizations in C++, including InstCombine, VectorCombine, GVN, SLPVectorizer, and others. |
| 7 | +The directed compiler fuzzer, Optimuzz, generates input programs that satisfy the optimization conditions in the source code to reach the target line and trigger the optimization. |
| 8 | +The target line is the line at which the optimization happens after the optimization condition checks and the code transformation is applied. |
| 9 | +For example, LLVM InstCombine pass returns a newly created instruction when the optimization is applied, |
| 10 | +and the return statement is usually located at the target line. |
| 11 | + |
| 12 | +The code change is typically one of the following three types: |
| 13 | +(A) A new optimization is added to the compiler. |
| 14 | +```c++ |
| 15 | +1 Instruction *foldX() { |
| 16 | +2 if (A) |
| 17 | +3 return Inst(); |
| 18 | +4 if (C) |
| 19 | +5 ... |
| 20 | +6 } |
| 21 | +``` |
| 22 | +In the example, a new optimization is added with the optimization condition `A`. |
| 23 | +In this case, the target line is 3, where the new instruction `Inst()` is created and returned. |
| 24 | +This is because we want to generate input programs that test the optimization `Inst()`. |
| 25 | +(B) Optimization condition is weakened. |
| 26 | +```c++ |
| 27 | +1 Instruction *foldX() { |
| 28 | +2 if (A) |
| 29 | +3 + if (B) |
| 30 | +4 return nullptr; |
| 31 | +5 if (C) |
| 32 | +6 return Opt1(); |
| 33 | +7 return nullptr; |
| 34 | +8 } |
| 35 | +``` |
| 36 | +In the example, the optimization condition `B` is added, |
| 37 | +then the optimization condition of `Opt1` is weakened since both `A` and `B` are required to be true to prevent the optimization. |
| 38 | +In this case, the target line is 6, where the optimization `Opt1` is applied. |
| 39 | +(C) Optimization condition is strengthened. |
| 40 | +```c++ |
| 41 | +1 Instruction *foldX() { |
| 42 | +2 if (A) |
| 43 | +3 + if (B) |
| 44 | +4 return Opt1(); |
| 45 | +5 if (C) |
| 46 | +6 return Opt2(); |
| 47 | +7 return nullptr; |
| 48 | +8 } |
| 49 | +``` |
| 50 | +In the example, the optimization condition `B` is added to the optimization `Opt1`. |
| 51 | +In this case, the target lines are 4 and 6, where the optimization `Opt1` is applied and the optimization `Opt2` is applied. |
| 52 | +Since the optimization condition of `Opt2` is weakend, we also target the line of `Opt2`. |
| 53 | + |
| 54 | +Second, you categorize the code change. |
| 55 | +A code change is typically one of the following three types: |
| 56 | + |
| 57 | +1. A new optimization is added to the compiler. Then you should answer `new`. The code change usually follows the pattern of (A) above. |
| 58 | +2. An optimization condition is weakened. Then you should answer `weakened`. The code change usually follows the pattern of (B) above. |
| 59 | +3. An optimization condition is strengthened. Then you should answer `strengthened`. The code change usually follows the pattern of (C) above. |
| 60 | + |
| 61 | +The commit message is: |
| 62 | +[InstCombine] Preserve the sign bit of NaN in `SimplifyDemandedUseFPClass` (#137287) |
| 63 | + |
| 64 | +Alive2: https://alive2.llvm.org/ce/z/uiUzEf |
| 65 | + |
| 66 | +Closes https://github.com/llvm/llvm-project/issues/137196. |
| 67 | + |
| 68 | +Note: To avoid regression in |
| 69 | +`ret_nofpclass_nopositives_copysign_nnan_flag`, the second commit takes |
| 70 | +FMF into account. |
| 71 | + |
| 72 | +The code change is as follows: |
| 73 | + |
| 74 | +File: llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp |
| 75 | +Status: modified |
| 76 | +Patch: |
| 77 | +``` |
| 78 | +--- | @@ -1959,9 +1959,11 @@ static Constant *getFPClassConstant(Type *Ty, FPClassTest Mask) { |
| 79 | +1959 | } |
| 80 | +1960 | } |
| 81 | +1961 | |
| 82 | +--- | -Value *InstCombinerImpl::SimplifyDemandedUseFPClass( |
| 83 | +--- | - Value *V, const FPClassTest DemandedMask, KnownFPClass &Known, |
| 84 | +--- | - unsigned Depth, Instruction *CxtI) { |
| 85 | +1962 | +Value *InstCombinerImpl::SimplifyDemandedUseFPClass(Value *V, |
| 86 | +1963 | + FPClassTest DemandedMask, |
| 87 | +1964 | + KnownFPClass &Known, |
| 88 | +1965 | + unsigned Depth, |
| 89 | +1966 | + Instruction *CxtI) { |
| 90 | +1967 | assert(Depth <= MaxAnalysisRecursionDepth && "Limit Search Depth"); |
| 91 | +1968 | Type *VTy = V->getType(); |
| 92 | +1969 | |
| 93 | +--- | @@ -1985,7 +1987,12 @@ Value *InstCombinerImpl::SimplifyDemandedUseFPClass( |
| 94 | +1987 | if (!I->hasOneUse()) |
| 95 | +1988 | return nullptr; |
| 96 | +1989 | |
| 97 | +--- | - // TODO: Should account for nofpclass/FastMathFlags on current instruction |
| 98 | +1990 | + if (auto *FPOp = dyn_cast<FPMathOperator>(I)) { |
| 99 | +1991 | + if (FPOp->hasNoNaNs()) |
| 100 | +1992 | + DemandedMask &= ~fcNan; |
| 101 | +1993 | + if (FPOp->hasNoInfs()) |
| 102 | +1994 | + DemandedMask &= ~fcInf; |
| 103 | +1995 | + } |
| 104 | +1996 | switch (I->getOpcode()) { |
| 105 | +1997 | case Instruction::FNeg: { |
| 106 | +1998 | if (SimplifyDemandedFPClass(I, 0, llvm::fneg(DemandedMask), Known, |
| 107 | +--- | @@ -2013,13 +2020,13 @@ Value *InstCombinerImpl::SimplifyDemandedUseFPClass( |
| 108 | +2020 | if (SimplifyDemandedFPClass(I, 0, DemandedMaskAnySign, Known, Depth + 1)) |
| 109 | +2021 | return I; |
| 110 | +2022 | |
| 111 | +--- | - if ((DemandedMask & fcPositive) == fcNone) { |
| 112 | +2023 | + if ((DemandedMask & fcNegative) == DemandedMask) { |
| 113 | +2024 | // Roundabout way of replacing with fneg(fabs) |
| 114 | +2025 | I->setOperand(1, ConstantFP::get(VTy, -1.0)); |
| 115 | +2026 | return I; |
| 116 | +2027 | } |
| 117 | +2028 | |
| 118 | +--- | - if ((DemandedMask & fcNegative) == fcNone) { |
| 119 | +2029 | + if ((DemandedMask & fcPositive) == DemandedMask) { |
| 120 | +2030 | // Roundabout way of replacing with fabs |
| 121 | +2031 | I->setOperand(1, ConstantFP::getZero(VTy)); |
| 122 | +2032 | return I; |
| 123 | + |
| 124 | +``` |
| 125 | +Now you should answer the following question: |
| 126 | + |
| 127 | +(1) Which target line should Optimuzz aim at? Provide your best suggestion of the target line. |
| 128 | +(2) What is the type of the code change? You can answer one of the following four types: `new`, `bug fix`, `weakened`, `removed`. |
| 129 | + |
| 130 | +You answer should follow the JSON format: |
| 131 | +```json |
| 132 | +{ |
| 133 | + "target_file": "<target_file>", |
| 134 | + "target_line": <target_line>, |
| 135 | + "type": "<type>" |
| 136 | +} |
| 137 | +``` |
| 138 | + |
| 139 | +===== AI ===== |
| 140 | +```json |
| 141 | +{ |
| 142 | + "target_file": "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp", |
| 143 | + "target_line": 2026, |
| 144 | + "type": "strengthened" |
| 145 | +} |
| 146 | +``` |
0 commit comments