[PATCH] Invariant intrinsic canonicalization
hfinkel at anl.gov
hfinkel at anl.gov
Mon Jul 14 10:43:43 PDT 2014
No change, but rebased against the latest version of http://reviews.llvm.org/D4490 (because this patch adds to the end of the same regression test).
http://reviews.llvm.org/D4491
Files:
lib/Transforms/InstCombine/InstCombineCalls.cpp
test/Transforms/InstCombine/invariants.ll
Index: lib/Transforms/InstCombine/InstCombineCalls.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -997,6 +997,17 @@
return EraseInstFromFunction(CI);
break;
}
+ case Intrinsic::invariant: {
+ // Canonicalize invariant(a && b) -> invariant(a); invariant(b);
+ Value *IIOperand = II->getArgOperand(0), *A, *B;
+ if (match(IIOperand, m_And(m_Value(A), m_Value(B)))) {
+ Builder->CreateCall(II->getCalledValue(), A, II->getName());
+ Builder->CreateCall(II->getCalledValue(), B, II->getName());
+ return EraseInstFromFunction(*II);
+ }
+
+ break;
+ }
}
return visitCallSite(II);
Index: test/Transforms/InstCombine/invariants.ll
===================================================================
--- test/Transforms/InstCombine/invariants.ll
+++ test/Transforms/InstCombine/invariants.ll
@@ -140,7 +140,22 @@
; CHECK-LABEL: @icmp2
; CHECK: call void @llvm.invariant
; CHECK: ret i32 0
+}
+
+; Function Attrs: nounwind uwtable
+define i32 @can1(i1 %a, i1 %b, i1 %c) {
+entry:
+ %and1 = and i1 %a, %b
+ %and = and i1 %and1, %c
+ tail call void @llvm.invariant(i1 %and)
+
+; CHECK-LABEL: @can1
+; CHECK: call void @llvm.invariant(i1 %a)
+; CHECK: call void @llvm.invariant(i1 %b)
+; CHECK: call void @llvm.invariant(i1 %c)
+; CHECK: ret i32
+ ret i32 5
}
attributes #0 = { nounwind uwtable }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4491.11397.patch
Type: text/x-patch
Size: 1486 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140714/77b678ff/attachment.bin>
More information about the llvm-commits
mailing list