[llvm] [CVP] Implement type narrowing for LShr (PR #119577)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 11 16:16:52 PST 2024


================
@@ -0,0 +1,114 @@
+; RUN: opt < %s -passes="correlated-propagation,instcombine" -S | FileCheck %s
+
+; The tests below are the same as in lshr.ll
+; Here we test whether the CorrelatedValuePropagation pass 
+; composed with InstCombinePass produces the expected optimizations.
+
+; CHECK-LABEL: @trunc_test1
+; CHECK-NEXT: [[A1:%.*]] = lshr i32 [[A:%.*]], 16
+; CHECK-NEXT: [[CARG:%.*]] = trunc nuw i32 [[A1]] to i16
+; CHECK-NEXT: [[CSHIFT:%.*]] = trunc i32 [[B:%.*]] to i16
+; CHECK-NEXT: [[C1:%.*]] = lshr i16 [[CARG]], [[CSHIFT]]
+; CHECK-NEXT: ret i16 [[C1]]
+
+define i16 @trunc_test1(i32 %a, i32 %b) {
----------------
dtcxzyw wrote:

Can you demonstrate that this patch will improve the codegen? https://godbolt.org/z/hbP9qrsxv

BTW this transformation is incorrect: https://alive2.llvm.org/ce/z/j2w5Wa


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


More information about the llvm-commits mailing list