[PATCH] D79294: [InstSimplify] Remove known bits constant folding

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun May 3 09:33:27 PDT 2020


spatel accepted this revision.
spatel added a comment.
This revision is now accepted and ready to land.

LGTM - if we can remove redundant/expensive logic with few visible side-effects, that's a nice win.



================
Comment at: test/Transforms/GVN/PRE/volatile.ll:204
 ; CHECK-NEXT:    [[LOAD:%.*]] = load volatile i32, i32* [[V:%.*]], !range !0
-; CHECK-NEXT:    ret i32 0
+; CHECK-NEXT:    ret i32 [[LOAD]]
 ;
----------------
There's no dedicated fold for this in InstCombiner::visitLoadInst(). But we call computeKnownBits on the ret arg in instcombine anyway, so we get all basic patterns. That might be worth looking at as another candidate for removal for efficiency.

Ie, we may want to add a dedicated fold (add a simplifyLoad?) since it's cheap to do directly and a big win if it works (no idea if this happens in the real-world, but somebody added this GVN test case...)

A test that would subvert the current known-bits call from InstCombiner::visitReturnInst() based on current MaxDepth recursion:
```
define i32 @known0(i32* %V, i32 %y) {
  %load = load i32, i32* %V, !range !0
  %m1 = mul i32 %load, %y
  %m2 = mul i32 %m1, %y
  %m3 = mul i32 %m2, %y
  %m4 = mul i32 %m3, %y
  %m5 = mul i32 %m4, %y
  %m6 = mul i32 %m5, %y
  ret i32 %m6
}

!0 = !{ i32 0, i32 1 }

```


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79294/new/

https://reviews.llvm.org/D79294





More information about the llvm-commits mailing list