[llvm] d45a135 - [InstCombine] Remove redundant align 1 assumptions. (#160695)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 25 10:00:21 PDT 2025


Author: Florian Hahn
Date: 2025-09-25T18:00:18+01:00
New Revision: d45a1359183a2e3f3f5b58a426a5f4899c893778

URL: https://github.com/llvm/llvm-project/commit/d45a1359183a2e3f3f5b58a426a5f4899c893778
DIFF: https://github.com/llvm/llvm-project/commit/d45a1359183a2e3f3f5b58a426a5f4899c893778.diff

LOG: [InstCombine] Remove redundant align 1 assumptions. (#160695)

It seems like we have a bunch of align 1 assumptions in practice and
unless I am missing something they should not add any value.

See https://github.com/dtcxzyw/llvm-opt-benchmark/pull/2861/files

PR: https://github.com/llvm/llvm-project/pull/160695

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
    llvm/test/Transforms/InstCombine/assume-align.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 6ad493772d170..04f787aae11aa 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -3412,6 +3412,10 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
             !isPowerOf2_64(RK.ArgValue) || !isa<ConstantInt>(RK.IRArgValue))
           continue;
 
+        // Remove align 1 bundles; they don't add any useful information.
+        if (RK.ArgValue == 1)
+          return CallBase::removeOperandBundle(II, OBU.getTagID());
+
         // Don't try to remove align assumptions for pointers derived from
         // arguments. We might lose information if the function gets inline and
         // the align argument attribute disappears.

diff  --git a/llvm/test/Transforms/InstCombine/assume-align.ll b/llvm/test/Transforms/InstCombine/assume-align.ll
index f6373d85ddb9c..4185b10eeca95 100644
--- a/llvm/test/Transforms/InstCombine/assume-align.ll
+++ b/llvm/test/Transforms/InstCombine/assume-align.ll
@@ -249,8 +249,7 @@ define ptr @redundant_assume_align_8_via_asume(ptr %p) {
 
 define ptr @assume_align_1(ptr %p) {
 ; CHECK-LABEL: @assume_align_1(
-; CHECK-NEXT:    call void @llvm.assume(i1 true) [ "align"(ptr [[P:%.*]], i32 1) ]
-; CHECK-NEXT:    call void @foo(ptr [[P]])
+; CHECK-NEXT:    call void @foo(ptr [[P:%.*]])
 ; CHECK-NEXT:    ret ptr [[P]]
 ;
   call void @llvm.assume(i1 true) [ "align"(ptr %p, i32 1) ]


        


More information about the llvm-commits mailing list