[llvm] [InstCombine] recognize missed i128 split optimization (PR #129363)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 28 21:50:47 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Muhammad Bassiouni (bassiounix)
<details>
<summary>Changes</summary>
This pr fixes #<!-- -->126056, recognising a split i128 extension optimization.
Proof for working optimization:
```llvm
define i128 @<!-- -->src(i32 noundef %x) {
entry:
%coerce.sroa.0.0.extract.trunc = sext i32 %x to i64
%0 = ashr i32 %x, 31
%coerce.sroa.2.0.extract.trunc = sext i32 %0 to i64
%x.sroa.2.0.insert.ext.i = zext i64 %coerce.sroa.2.0.extract.trunc to i128
%x.sroa.2.0.insert.shift.i = shl nuw i128 %x.sroa.2.0.insert.ext.i, 64
%x.sroa.0.0.insert.ext.i = zext i64 %coerce.sroa.0.0.extract.trunc to i128
%x.sroa.0.0.insert.insert.i = or disjoint i128 %x.sroa.2.0.insert.shift.i, %x.sroa.0.0.insert.ext.i
ret i128 %x.sroa.0.0.insert.insert.i
}
define i128 @<!-- -->tgt(i32 noundef %x) {
%x.sroa.0.0.insert.insert.i = sext i32 %x to i128
ret i128 %x.sroa.0.0.insert.insert.i
}
```
---
Full diff: https://github.com/llvm/llvm-project/pull/129363.diff
1 Files Affected:
- (modified) llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp (+7)
``````````diff
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index 175c653f17f07..cff95338650f2 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -3119,6 +3119,13 @@ static Value *matchOrConcat(Instruction &Or, InstCombiner::BuilderTy &Builder) {
match(UpperSrc, m_BitReverse(m_Value(UpperBRev))))
return ConcatIntrinsicCalls(Intrinsic::bitreverse, UpperBRev, LowerBRev);
+ Value *X;
+ if (match(LowerSrc, m_SExt(m_Value(X))) &&
+ match(UpperSrc,
+ m_SExt(m_AShr(m_Specific(X), m_SpecificInt(HalfWidth / 2 - 1))))) {
+ return Builder.CreateSExt(X, Ty);
+ }
+
return nullptr;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/129363
More information about the llvm-commits
mailing list