Have InstCombine call SipmlifyCall when handling calls. Test case included.
authorMichael Ilseman <milseman@apple.com>
Thu, 7 Feb 2013 23:01:35 +0000 (23:01 +0000)
committerMichael Ilseman <milseman@apple.com>
Thu, 7 Feb 2013 23:01:35 +0000 (23:01 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@174675 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombineCalls.cpp
test/Transforms/InstCombine/intrinsics.ll

index 64cd1bd27891148e87f69e3d94721ab5d6e2dcdd..cb9ba44600ad397e90e9b8fddfe702c360d9aaa8 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "InstCombine.h"
 #include "llvm/ADT/Statistic.h"
+#include "llvm/Analysis/InstructionSimplify.h"
 #include "llvm/Analysis/MemoryBuiltins.h"
 #include "llvm/IR/DataLayout.h"
 #include "llvm/Support/CallSite.h"
@@ -210,6 +211,11 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
     return &CI;
   }
 
+  CallSite CS(&CI);
+  if (Value *V = SimplifyCall(CS.getCalledValue(), CS.arg_begin(), CS.arg_end(),
+                              TD))
+    return ReplaceInstUsesWith(CI, V);
+
   IntrinsicInst *II = dyn_cast<IntrinsicInst>(&CI);
   if (!II) return visitCallSite(&CI);
 
index f334b3b1e93533bc4d2f3446f69afa73de8cd664..6bfea72f41957b3b0ed94d3a528d7f907c06584d 100644 (file)
@@ -152,8 +152,8 @@ entry:
   ret void
 ; CHECK: @powi
 ; CHECK: %A = fdiv double 1.0{{.*}}, %V
-; CHECK: store volatile double %A, 
-; CHECK: store volatile double 1.0 
+; CHECK: store volatile double %A,
+; CHECK: store volatile double 1.0
 ; CHECK: store volatile double %V
 }
 
@@ -256,3 +256,15 @@ define i32 @cttz_select(i32 %Value) nounwind {
 ; CHECK: @cttz_select
 ; CHECK: select i1 %tobool, i32 %cttz, i32 32
 }
+
+; Test that SimplifyCall is getting invoked by InstCombine
+declare float @llvm.fabs.f32(float) nounwind readnone
+define float @simplify_idempotent(float %a) {
+; CHECK: @simplify_idempotent
+; CHECK: fabs
+; CHECK-NOT: fabs
+  %a0 = call float @llvm.fabs.f32(float %a)
+  %a1 = call float @llvm.fabs.f32(float %a0)
+
+  ret float %a1
+}
\ No newline at end of file