[PATCH] LLVM intrinsic for invariants

Chandler Carruth chandlerc at gmail.com
Thu Jul 17 11:16:04 PDT 2014


================
Comment at: docs/LangRef.rst:9304
@@ +9303,3 @@
+
+      declare void @llvm.invariant(i1 %cond)
+
----------------
I wonder if this would be more clear spelled "llvm.assume.invariant" or just "llvm.assume".

================
Comment at: docs/LangRef.rst:9321-9324
@@ +9320,6 @@
+
+The intrinsic allows the optimizer to assume that the provided condition is
+always true. No code is generated for this intrinsic, and instructions that
+contribute only to the provided condition are not used for code generation.
+If the condition is violated during execution, the behavior is undefined.
+
----------------
I think we should provide some minimal guidance for FE authors here that essentially indicates that using this intrinsic is not without cost, and essentially shouldn't be used to either document basic mathematical invariants the compiler could deduce otherwise, or if the invariant holds little or no value to the optimizer.

================
Comment at: lib/Transforms/Utils/Local.cpp:305
@@ +304,3 @@
+
+    // Invariants are dead if their condition is undef (and also if the
+    // condition is trivially true).
----------------
If the condition is undef, aren't they unreachable?

================
Comment at: test/Transforms/InstSimplify/invariant.ll:3-5
@@ +2,5 @@
+
+define void @test1() {
+        call void @llvm.invariant(i1 1)
+        ret void
+
----------------
Indent seems weird here. Use the more common 2-space indent?

http://reviews.llvm.org/D178






More information about the llvm-commits mailing list