[llvm] [InstCombine] Resolve TODO: Remove one-time check if other logic operand (Y) is constant (PR #77973)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 20 09:41:07 PST 2024


================
@@ -240,6 +240,35 @@ define i32 @lshr_or_extra_use(i32 %x, i32 %y, ptr %p) {
   ret i32 %sh1
 }
 
+define i32 @lshr_or_extra_use_multiuse(i32 %x, ptr %p) {
+; CHECK-LABEL: @lshr_or_extra_use_multiuse(
+; CHECK-NEXT:    [[SH0:%.*]] = lshr i32 [[X:%.*]], 5
+; CHECK-NEXT:    store i32 [[SH0]], ptr [[P:%.*]], align 4
+; CHECK-NEXT:    [[SH1:%.*]] = lshr i32 [[X]], 12
+; CHECK-NEXT:    ret i32 [[SH1]]
+;
+  %sh0 = lshr i32 %x, 5
+  %r = or i32 %sh0, 42
----------------
nikic wrote:

It looks like the or gets optimized away entirely with this constant. You'll have to increase it so that the lshr by 7 does not make it zero.

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


More information about the llvm-commits mailing list