[llvm] [CanonicalizeFreezeInLoops] fix duplicate removal (PR #74716)

Wei Tao via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 24 23:10:08 PST 2023


================
@@ -99,6 +87,46 @@ class CanonicalizeFreezeInLoopsImpl {
 
 } // anonymous namespace
 
+namespace llvm {
+
+struct FrozenIndPHIInfo {
+  // A freeze instruction that uses an induction phi
+  FreezeInst *FI = nullptr;
+  // The induction phi, step instruction, the operand idx of StepInst which is
+  // a step value
+  PHINode *PHI;
+  BinaryOperator *StepInst;
+  unsigned StepValIdx = 0;
+
+  FrozenIndPHIInfo(PHINode *PHI, BinaryOperator *StepInst)
+      : PHI(PHI), StepInst(StepInst) {}
+
+  bool operator==(const FrozenIndPHIInfo &Other) { return FI == Other.FI; }
----------------
Friedrich20 wrote:

@nikic ,
I have tested this fix on both [llvmorg-15.0.7](https://github.com/llvm/llvm-project/releases/tag/llvmorg-15.0.7) and the latest main branch. Just as you said, this function is totally unused on llvm15. However, it is required by the main branch to overload this function to support `operator ==` between `type` and `const type`.
```
/home/taowei/repo/llvm-project/llvm/lib/Transforms/Utils/CanonicalizeFreezeInLoops.cpp:184:31:   required from here
/usr/include/c++/7/bits/predefined_ops.h:241:17: error: no match for ‘operator==’ (operand types are ‘llvm::FrozenIndPHIInfo’ and ‘const llvm::FrozenIndPHIInfo’)
  { return *__it == _M_value; }
           ~~~~~~^~~~~~~~~~~
```

https://github.com/llvm/llvm-project/pull/74716


More information about the llvm-commits mailing list